mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Merge pull request #56 from Sartoric/fix-cartitem-pricetax
Fix cartitem priceTax bug
This commit is contained in:
@@ -279,7 +279,6 @@ class CartItem implements Arrayable, Jsonable
|
||||
$this->id = $item->getBuyableIdentifier($this->options);
|
||||
$this->name = $item->getBuyableDescription($this->options);
|
||||
$this->price = $item->getBuyablePrice($this->options);
|
||||
$this->priceTax = $this->price + $this->tax;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,7 +295,6 @@ class CartItem implements Arrayable, Jsonable
|
||||
$this->name = Arr::get($attributes, 'name', $this->name);
|
||||
$this->price = Arr::get($attributes, 'price', $this->price);
|
||||
$this->weight = Arr::get($attributes, 'weight', $this->weight);
|
||||
$this->priceTax = $this->price + $this->tax;
|
||||
$this->options = new CartItemOptions(Arr::get($attributes, 'options', $this->options));
|
||||
|
||||
$this->rowId = $this->generateRowId($this->id, $this->options->all());
|
||||
|
||||
@@ -959,6 +959,52 @@ class CartTest extends TestCase
|
||||
$this->assertEquals(11.90, $cartItem->total(2));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_calculate_all_values_after_updating_from_array()
|
||||
{
|
||||
$cart = $this->getCartDiscount(50);
|
||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
|
||||
|
||||
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', ['qty'=>2]);
|
||||
|
||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||
|
||||
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
||||
|
||||
$this->assertEquals(10.00, $cartItem->price(2));
|
||||
$this->assertEquals(5.00, $cartItem->discount(2));
|
||||
$this->assertEquals(10.00, $cartItem->discountTotal(2));
|
||||
$this->assertEquals(5.00, $cartItem->priceTarget(2));
|
||||
$this->assertEquals(10.00, $cartItem->subtotal(2));
|
||||
$this->assertEquals(0.95, $cartItem->tax(2));
|
||||
$this->assertEquals(1.90, $cartItem->taxTotal(2));
|
||||
$this->assertEquals(5.95, $cartItem->priceTax(2));
|
||||
$this->assertEquals(11.90, $cartItem->total(2));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_calculate_all_values_after_updating_from_buyable()
|
||||
{
|
||||
$cart = $this->getCartDiscount(50);
|
||||
$cart->add(new BuyableProduct(1, 'First item', 5.00), 2);
|
||||
|
||||
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', new BuyableProduct(1, 'First item', 10.00));
|
||||
|
||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||
|
||||
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
||||
|
||||
$this->assertEquals(10.00, $cartItem->price(2));
|
||||
$this->assertEquals(5.00, $cartItem->discount(2));
|
||||
$this->assertEquals(10.00, $cartItem->discountTotal(2));
|
||||
$this->assertEquals(5.00, $cartItem->priceTarget(2));
|
||||
$this->assertEquals(10.00, $cartItem->subtotal(2));
|
||||
$this->assertEquals(0.95, $cartItem->tax(2));
|
||||
$this->assertEquals(1.90, $cartItem->taxTotal(2));
|
||||
$this->assertEquals(5.95, $cartItem->priceTax(2));
|
||||
$this->assertEquals(11.90, $cartItem->total(2));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_will_destroy_the_cart_when_the_user_logs_out_and_the_config_setting_was_set_to_true()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user