Commit 0a07d02c authored by Thomas Bilk's avatar Thomas Bilk

more comments more tests

parent 118b775a
......@@ -641,8 +641,11 @@ class Cart implements Jsonable, \JsonSerializable, Arrayable{
})->map(function (Condition $c) use (&$subtotal_with_conditions) {
$cond_value = $c->applyCondition($subtotal_with_conditions);
$cond_data = $c->all();
/* when a negative condition results in a negative total
* only the remainder of the condition is used */
if (($diff = $subtotal_with_conditions + $cond_value) < 0) {
$subtotal_with_conditions = 0;
/* only the remainder is used for the condition value */
$cond_data['value'] = (string)($cond_value - $diff);
} else {
$subtotal_with_conditions += $cond_value;
......
......@@ -1153,10 +1153,19 @@ class CartConditionTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(2, $conditions->count());
$this->assertEquals($this->cart->subTotal(), abs($conditions->sum('value')));
$this->assertEquals(0, $this->cart->total());
$this->cart->update(456, ['quantity' => '+1']);
$conditions = $this->cart->priceConditions();
$this->assertEquals(8000, abs($conditions->sum('value')));
$this->assertEquals(2000, $this->cart->total());
$this->cart->removeConditionsByType('coupon');
$conditions = $this->cart->priceConditions();
$this->assertEquals(0, $conditions->count());
$this->assertEquals(0, abs($conditions->sum('value')));
$this->assertEquals(10000, $this->cart->total());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment