コード例 #1
0
 public function test_cart_update_existing_item()
 {
     $items = array(array('id' => 456, 'name' => 'Sample Item 1', 'price' => 67.98999999999999, 'quantity' => 3, 'attributes' => array()), array('id' => 568, 'name' => 'Sample Item 2', 'price' => 69.25, 'quantity' => 1, 'attributes' => array()));
     $this->cart->add($items);
     $itemIdToEvaluate = 456;
     $item = $this->cart->get($itemIdToEvaluate);
     $this->assertEquals('Sample Item 1', $item['name'], 'Item name should be "Sample Item 1"');
     $this->assertEquals(67.98999999999999, $item['price'], 'Item price should be "67.99"');
     $this->assertEquals(3, $item['quantity'], 'Item quantity should be 3');
     // when cart's item quantity is updated, the subtotal should be updated as well
     $this->cart->update(456, array('name' => 'Renamed', 'quantity' => 2, 'price' => 105));
     $item = $this->cart->get($itemIdToEvaluate);
     $this->assertEquals('Renamed', $item['name'], 'Item name should be "Renamed"');
     $this->assertEquals(105, $item['price'], 'Item price should be 105');
     $this->assertEquals(2, $item['quantity'], 'Item quantity should be 2');
 }
コード例 #2
0
 public function test_clear_item_conditions()
 {
     $itemCondition1 = new CartCondition(array('name' => 'SALE 5%', 'type' => 'sale', 'target' => 'item', 'value' => '-5%'));
     $itemCondition2 = new CartCondition(array('name' => 'Item Gift Pack 25.00', 'type' => 'promo', 'target' => 'item', 'value' => '-25'));
     $item = array('id' => 456, 'name' => 'Sample Item 1', 'price' => 100, 'quantity' => 1, 'attributes' => array(), 'conditions' => [$itemCondition1, $itemCondition2]);
     $this->cart->add($item);
     // let's very first the item has 2 conditions in it
     $this->assertCount(2, $this->cart->get(456)['conditions'], 'Item should have two conditions');
     // now let's remove all condition on that item
     $this->cart->clearItemConditions(456);
     // now we should have only 0 condition left on that item
     $this->assertCount(0, $this->cart->get(456)['conditions'], 'Item should have no conditions now');
 }
コード例 #3
0
 public function test_item_quantity_update_by_reduced_should_not_reduce_if_quantity_will_result_to_zero()
 {
     $items = array(array('id' => 456, 'name' => 'Sample Item 1', 'price' => 67.98999999999999, 'quantity' => 3, 'attributes' => array()), array('id' => 568, 'name' => 'Sample Item 2', 'price' => 69.25, 'quantity' => 1, 'attributes' => array()));
     $this->cart->add($items);
     // get the item to be evaluated
     $item = $this->cart->get(456);
     // prove first we have quantity of 3
     $this->assertEquals(3, $item['quantity'], 'Item quantity of with item ID of 456 should be reduced to 3');
     // when cart's item quantity is updated, and reduced to more than the current quantity
     // this should not work
     $this->cart->update(456, array('quantity' => -3));
     $this->assertEquals(3, $item['quantity'], 'Item quantity of with item ID of 456 should now be reduced to 2');
 }
コード例 #4
0
 public function test_remove_item_condition_by_condition_name_scenario_two()
 {
     // NOTE: in this scenario, we will add the conditions not in array format
     $itemCondition = new CartCondition(array('name' => 'SALE 5%', 'type' => 'sale', 'target' => 'item', 'value' => '-5%'));
     $item = array('id' => 456, 'name' => 'Sample Item 1', 'price' => 100, 'quantity' => 1, 'attributes' => array(), 'conditions' => $itemCondition);
     $this->cart->add($item);
     // let's very first the item has 2 conditions in it
     $this->assertNotEmpty($this->cart->get(456)['conditions'], 'Item should have one condition in it.');
     // now let's remove a condition on that item using the condition name
     $this->cart->removeItemCondition(456, 'SALE 5%');
     // now we should have only 1 condition left on that item
     $this->assertEmpty($this->cart->get(456)['conditions'], 'Item should have no condition now');
 }
コード例 #5
0
ファイル: _ide_helper.php プロジェクト: nhatkhoa/GroupBuy
 /**
  * get an item on a cart by item ID
  *
  * @param $itemId
  * @return mixed 
  * @static 
  */
 public static function get($itemId)
 {
     return \Darryldecode\Cart\Cart::get($itemId);
 }
コード例 #6
0
 public function test_item_get_sum_price_using_array_style()
 {
     $this->cart->add(455, 'Sample Item', 100.99, 2, array());
     $item = $this->cart->get(455);
     $this->assertEquals(201.98, $item->getPriceSum(), 'Item summed price should be 201.98');
 }