public function test_total_with_multiple_conditions_added_scenario_four()
 {
     $this->fillCart();
     $this->assertEquals(187.49, $this->cart->getSubTotal(), 'Cart should have sub total of 187.49');
     // add condition
     $condition1 = new CartCondition(array('name' => 'COUPON LESS 12.5%', 'type' => 'tax', 'target' => 'total', 'value' => '-12.5%'));
     $condition2 = new CartCondition(array('name' => 'Express Shipping $15', 'type' => 'shipping', 'target' => 'total', 'value' => '+15'));
     $this->cart->condition($condition1);
     $this->cart->condition($condition2);
     // no changes in subtotal as the condition's target added was for total
     $this->assertEquals(187.49, $this->cart->getSubTotal(), 'Cart should have sub total of 187.49');
     // total should be changed
     $this->assertEquals(179.05375, $this->cart->getTotal(), 'Cart should have a total of 179.05375');
 }
 public function test_add_cart_condition_with_condition_attributes()
 {
     $cartCondition1 = new CartCondition(array('name' => 'SALE 5%', 'type' => 'sale', 'target' => 'subtotal', 'value' => '-5%', 'attributes' => array('description' => 'october fest promo sale', 'sale_start_date' => '2015-01-20', 'sale_end_date' => '2015-01-30')));
     $item = array('id' => 456, 'name' => 'Sample Item 1', 'price' => 100, 'quantity' => 1, 'attributes' => array());
     $this->cart->add($item);
     $this->cart->condition([$cartCondition1]);
     // prove first we have now the condition on the cart
     $contition = $this->cart->getCondition("SALE 5%");
     $this->assertEquals('SALE 5%', $contition->getName());
     // when get attribute is called and there is no attributes added,
     // it should return an empty array
     $conditionAttributes = $contition->getAttributes();
     $this->assertInternalType('array', $conditionAttributes);
     $this->assertArrayHasKey('description', $conditionAttributes);
     $this->assertArrayHasKey('sale_start_date', $conditionAttributes);
     $this->assertArrayHasKey('sale_end_date', $conditionAttributes);
     $this->assertEquals('october fest promo sale', $conditionAttributes['description']);
     $this->assertEquals('2015-01-20', $conditionAttributes['sale_start_date']);
     $this->assertEquals('2015-01-30', $conditionAttributes['sale_end_date']);
 }
Beispiel #3
0
 /**
  * add a condition on the cart
  *
  * @param \Darryldecode\Cart\CartCondition|array $condition
  * @return $this 
  * @throws InvalidConditionException
  * @static 
  */
 public static function condition($condition)
 {
     return \Darryldecode\Cart\Cart::condition($condition);
 }