-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
$cart->conditions(null) includes items, but $cart->conditions(‘type’) does not.
TestCase:
public function test_item_level_conditions_are_returned()
{
$product = FactoryMuffin::create('Acme\Models\Product', ['title'=>'A New Product']);
$coupon = $this->createCondition('Test Coupon', 'coupon', '5', 'subtotal');
$discount = $this->createCondition('Test Discount', 'discount', '10%', 'subtotal');
$this->cart->add($this->createItemFromProduct($product, 1, 10, [$coupon, $discount]));
$this->assertEquals(2, count($this->cart->conditions()));
//The following assertion fails with: Failed asserting that 0 matches expected 1.
$this->assertEquals(1, count($this->cart->conditions('coupon')));
}This test passes after updating the $cart->conditions() method to the following:
public function conditions($type = null, $includeItems = true)
{
$conditions = [];
if ( ! $type) {
if ($includeItems) {
foreach ($this->items as $item) {
$conditions = array_merge($conditions, $item->conditions());
}
}
return array_merge($conditions, $this->conditions);
}
if ($includeItems) {
foreach ($this->items as $item) {
$conditions = array_merge($conditions, $item->conditions($type));
}
}
foreach ($this->conditions as $condition) {
if ($condition->get('type') === $type) {
$conditions[] = $condition;
}
}
return $conditions;
}