/** * Usuwa produkt z koszyka * * @param Product $product * @return Basket * @throws ProductNotFoundException */ public function remove(Product $product) { $basket = $this->session->get('basket', []); if (array_key_exists($product->getId(), $basket)) { unset($basket[$product->getId()]); } else { throw new ProductNotFoundException("Wybranego produktu nie miałeś w koszyku!"); } $this->session->set('basket', $basket); return $this; }
/** * Usuwa produkt z koszyka * * @param Product $product * @return \AppBundle\Utils\Basket * @throws ProductNotFoundException */ public function remove(Product $product) { $basket = $this->session->get('basket', []); if (!array_key_exists($product->getId(), $basket)) { throw new ProductNotFoundException("Produkt nie znajduje się w koszyku."); } unset($basket[$product->getId()]); // aktualizujemy koszyk $this->session->set('basket', $basket); return $this; }
/** * Usuwanie produktu z koszyka * @param Product $product * @return \AppBundle\Utils\Basket * @throws ProductNotFoundException */ public function remove(Product $product) { $basket = $this->session->get('basket', []); if (!array_key_exists($product->getId(), $basket)) { throw new ProductNotFoundException('Produkt nie został znaleziony w koszyku'); } unset($basket[$product->getId()]); //Aktualizujemy stan koszyka w sesji $this->session->set('basket', $basket); return $this; }
/** * Deletes a Product entity. * * @Route("/delete/{id}", name="product_delete") * @Method("GET") * @param Request $request * @param Product $product * @return index page */ public function deleteAction(Request $request, Product $product) { if ($request->get('pass') !== 'angólar') { $this->addFlash('danger', 'Nie masz uprawnień do wykonania tej operacji'); } else { $em = $this->getDoctrine()->getManager()->getRepository('AppBundle:Product'); $em->createQueryBuilder('p')->delete()->where('p.id = :product')->setParameter('product', $product->getId())->getQuery()->execute(); $this->addFlash('success', 'Pomyslnie usunąłeś produkt'); } return $this->redirectToRoute('database_index'); }
/** * 向购物车添加指定项目 */ public function addProduct(Product $product, $quantity = 1) { if ($product->isUnavailable()) { throw new \InvalidArgumentException('Product unavailable'); } $mapping = $this->getMapping(); // if( $this->hasProduct($product) ) { // $quantity += $mapping[$product->getId()]; // } $mapping[$product->getId()] = $quantity; $this->session->set(self::CART, $mapping); }
/** * Creates a form to delete a Product entity. * * @param Product $product The Product entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Product $product) { return $this->createFormBuilder()->setAction($this->generateUrl('product_delete', array('id' => $product->getId())))->setMethod('DELETE')->getForm(); }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }
/** * Increase the count of a product * * @param Product $product * @param int $nb * * @return $this */ protected function increaseNbProduct(Product $product, $nb = 1) { if (false === array_key_exists($product->getId(), $this->nbPerProducts)) { $this->nbPerProducts[$product->getId()] = 0; } $this->nbPerProducts[$product->getId()] += $nb; return $this; }
/** * @param Product $product * @param Request $request * @return array $cart */ public function removeFromCart(Product $product, Request $request) { $cart = json_decode($request->cookies->get('cart'), true); $productId = $product->getId(); if (is_array($cart) ? array_key_exists($productId, $cart) : false) { unset($cart[$productId]); } return $cart; }