/** * {@inheritdoc} */ public function calculatePrice(CartInterface $cart) { $price = 0; $finalPrice = 0; foreach ($cart->getItems() as $item) { $price = bcadd($price, $item->getPrice(), 2); $finalPrice = bcadd($finalPrice, $item->getFinalPrice(), 2); } $cart->setPrice($price); $cart->setFinalPrice($finalPrice); return $cart; }
/** * Add the item into the Cart * * @param CartInterface $cart * @param ItemInterface $item * * @return Boolean */ public function addItem(CartInterface $cart, ItemInterface $item) { $return = $cart->addItem($item); return $return; }
/** * Create the Response. * * @param CartInterface $cart * @param int $statusCode * @param string $getCartRoute * * @return \FOS\RestBundle\View\View */ protected function createResponse(CartInterface $cart, $statusCode = 204, $getCartRoute = 'api_1_get_cart') { $headers = array(); $response = new Response(); $response->setStatusCode($statusCode); // set the `Location` header only when creating new resources if (201 === $statusCode) { $headers = array('Location' => $this->container->get('router')->generate($getCartRoute, array('cart_id' => $cart->getId(), '_format' => $this->container->get('request')->get('_format')), true)); } return $this->view($cart, $statusCode, $headers); }
/** * Remove all cart items of the given cart and apply a transition * from current state to TRANSITION_DELETE. * * @param CartInterface $cart * * @return CartInterface * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException */ public function deleteAllItems(CartInterface $cart) { foreach ($cart->getItems() as $item) { $this->doDeleteItem($cart, $item); } return $cart; }