public function test_remove_cart_condition_by_condition_name() { $itemCondition1 = new CartCondition(array('name' => 'SALE 5%', 'type' => 'sale', 'target' => 'subtotal', 'value' => '-5%')); $itemCondition2 = new CartCondition(array('name' => 'Item Gift Pack 25.00', 'type' => 'promo', 'target' => 'subtotal', 'value' => '-25')); $item = array('id' => 456, 'name' => 'Sample Item 1', 'price' => 100, 'quantity' => 1, 'attributes' => array()); $this->cart->add($item); $this->cart->condition([$itemCondition1, $itemCondition2]); // let's prove first we have now two conditions in the cart $this->assertEquals(2, $this->cart->getConditions()->count(), 'Cart should have two conditions'); // now let's remove a specific condition by condition name $this->cart->removeCartCondition('SALE 5%'); // cart should have now only 1 condition $this->assertEquals(1, $this->cart->getConditions()->count(), 'Cart should have one condition'); $this->assertEquals('Item Gift Pack 25.00', $this->cart->getConditions()->first()->getName()); }
/** * removes a condition on a cart by condition name, * this can only remove conditions that are added on cart bases not conditions that are added on an item/product. * * If you wish to remove a condition that has been added for a specific item/product, you may * use the removeItemCondition(itemId, conditionName) method instead. * * @param $conditionName * @return void * @static */ public static function removeCartCondition($conditionName) { \Darryldecode\Cart\Cart::removeCartCondition($conditionName); }