Browse Source

Product getPrice method returns cash_price attribute if credit_price is 0 or null

pull/4/head
Nafies Luthfi 9 years ago
parent
commit
bdad3cfde7
  1. 3
      app/Product.php
  2. 2
      resources/views/cart/partials/product-search-box.blade.php
  3. 2
      resources/views/cart/partials/product-search-result-box.blade.php
  4. 10
      tests/Unit/Integration/ProductTest.php

3
app/Product.php

@ -10,8 +10,7 @@ class Product extends Model
public function getPrice($type = 'cash') public function getPrice($type = 'cash')
{ {
// TODO: if there is no credit_price then return cash_price
if ($type == 'credit') {
if ($type == 'credit' && $this->credit_price) {
return $this->credit_price; return $this->credit_price;
} }

2
resources/views/cart/partials/product-search-box.blade.php

@ -4,7 +4,7 @@
<label for="query">{{ trans('cart.product_search') }}</label> <label for="query">{{ trans('cart.product_search') }}</label>
<input type="text" id="query" name="query" value="{{ request('query') }}"> <input type="text" id="query" name="query" value="{{ request('query') }}">
<input type="submit" value="{{ trans('cart.product_search') }}" class="btn btn-sm"> <input type="submit" value="{{ trans('cart.product_search') }}" class="btn btn-sm">
<a href="{{ route('cart.show', $draft->draftKey) }}" class="btn btn-sm">Refresh</a>
{{ link_to_route('cart.show', 'Bersihkan Pencarian', [$draft->draftKey], ['class' => 'btn btn-sm']) }}
</form> </form>
</div> </div>
@includeWhen ($queriedProducts, 'cart.partials.product-search-result-box') @includeWhen ($queriedProducts, 'cart.partials.product-search-result-box')

2
resources/views/cart/partials/product-search-result-box.blade.php

@ -13,7 +13,7 @@
<tr> <tr>
<td>{{ $product->name }}</td> <td>{{ $product->name }}</td>
<td>{{ $product->unit->name }}</td> <td>{{ $product->unit->name }}</td>
<td>{{ formatRp($draft->type == 'cash' ? $product->cash_price : $product->credit_price) }}</td>
<td>{{ formatRp($product->getPrice($draft->type)) }}</td>
<td> <td>
<form action="{{ route('cart.add-draft-item', [$draft->draftKey, $product->id]) }}" method="post" style="display:inline"> <form action="{{ route('cart.add-draft-item', [$draft->draftKey, $product->id]) }}" method="post" style="display:inline">
{{ csrf_field() }} {{ csrf_field() }}

10
tests/Unit/Integration/ProductTest.php

@ -31,4 +31,14 @@ class ProductTest extends TestCase
$this->assertEquals($product->credit_price, $product->getPrice('credit')); $this->assertEquals($product->credit_price, $product->getPrice('credit'));
$this->assertEquals(3000, $product->getPrice('credit')); $this->assertEquals(3000, $product->getPrice('credit'));
} }
/** @test */
public function product_get_price_returns_cash_price_if_credit_price_is_0_or_null()
{
$product = new Product(['cash_price' => 2000, 'credit_price' => 0]);
$this->assertEquals(2000, $product->getPrice('credit'));
$product = new Product(['cash_price' => 2000, 'credit_price' => null]);
$this->assertEquals(2000, $product->getPrice('credit'));
}
} }
Loading…
Cancel
Save