Example #1
0
$products[5] = ['id' => '5', 'name' => 'Test item five', 'price' => '756.00'];
// initialize request
$request = Request::createFromGlobals();
// handle incoming request
if ($request->isMethod('post')) {
    // get the action form the post var
    $action = $request->request->get('action');
    switch ($action) {
        case 'add':
            // add item eg. from product listing
            $id = $request->get('id');
            if (isset($products[$id])) {
                // create the Item
                $item = new Item($products[$id]);
                // we dont supply a quantity in form below so it defaults to "1"
                $item->setQuantity($request->get('quantity', 1));
                // add the Item to the Cart
                $cart->addItem($item);
            }
            break;
        case 'remove':
            // remove item from Cart
            $cart->removeItem($request->get('id'));
            break;
        case 'quantity':
            // update quantity on Item in Cart
            // get Item from Cart
            $item = $cart->getItem($request->get('id'));
            if ($item) {
                // set new quantity
                $item->setQuantity($request->get('quantity'));
Example #2
0
 /**
  * @param $quantity
  * @param $price
  * @param $expected
  * @dataProvider getTotalProvider
  */
 public function testGetTotal($quantity, $price, $expected)
 {
     $item = new Item();
     $item->setQuantity($quantity);
     $item->setPrice($price);
     $this->assertEquals($expected, $item->getTotal());
 }