public function test_sub_total_when_item_quantity_is_updated() { $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); $this->assertEquals(273.22, $this->cart->getSubTotal(), 'Cart should have sub total of 273.22'); // when cart's item quantity is updated, the subtotal should be updated as well $this->cart->update(456, array('quantity' => 2)); $this->assertEquals(205.23, $this->cart->getSubTotal(), 'Cart should have sub total of 205.23'); }
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'); }
/** * update a cart * * @param $id * @param $data the $data will be an associative array, you don't need to pass all the data, only the key value * of the item you want to update on it * @static */ public static function update($id, $data) { return \Darryldecode\Cart\Cart::update($id, $data); }