コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function addProduct(ProductInterface $product, $indexName = ProductIndexerInterface::DEFAULT_INDEX_NAME)
 {
     $index = $this->searchIndexManager->getIndex(ProductIndexerInterface::DEFAULT_INDEX_NAME);
     $document = new Document();
     $document->addField(Field::unIndexed('identifier', $product->getId()));
     $document->addField(Field::text('name', $product->translate('en')->getName()));
     $document->addField(Field::text('shortDescription', $product->translate()->getShortDescription()));
     $document->addField(Field::text('description', $product->translate()->getDescription()));
     $index->addDocument($document);
     $index->commit();
 }
コード例 #2
0
 /**
  * Adds item to cart or redirects to quick-view
  *
  * @param ProductInterface               $product
  * @param ProductAttributeInterface|null $attribute
  * @param int                            $quantity
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function addAction(ProductInterface $product, ProductAttributeInterface $attribute = null, $quantity = 1)
 {
     if ($product->getAttributes()->count() && !$product->getAttributes()->contains($attribute)) {
         return $this->redirectToRoute('front.product.view', ['id' => $product->getId()]);
     }
     try {
         $this->manager->addProductToCart($product, $attribute, $quantity);
     } catch (AddCartItemException $exception) {
         return $this->jsonResponse(['error' => $exception->getMessage()]);
     }
     $category = $product->getCategories()->first();
     $recommendations = $this->manager->getProductProvider()->getProductRecommendationsForCategory($category);
     $basketModalContent = $this->renderView('WellCommerceCartBundle:Front/Cart:add.html.twig', ['product' => $product, 'recommendations' => $recommendations]);
     $cartPreviewContent = $this->renderView('WellCommerceCartBundle:Front/Common:preview.html.twig');
     return $this->jsonResponse(['basketModalContent' => $basketModalContent, 'cartPreviewContent' => $cartPreviewContent]);
 }
コード例 #3
0
 public function addAction(ProductInterface $product, VariantInterface $variant = null, int $quantity = 1) : Response
 {
     $variants = $product->getVariants();
     if ($variants->count() && false === $variants->contains($variant)) {
         return $this->redirectToRoute('front.product.view', ['id' => $product->getId()]);
     }
     try {
         $this->manager->addProductToCart($product, $variant, $quantity);
     } catch (AddCartItemException $exception) {
         return $this->jsonResponse(['error' => $exception->getMessage(), 'previousError' => $exception->getPrevious()->getMessage()]);
     }
     $category = $product->getCategories()->first();
     $recommendations = $this->get('product.helper')->getProductRecommendationsForCategory($category);
     $basketModalContent = $this->renderView('WellCommerceCartBundle:Front/Cart:add.html.twig', ['product' => $product, 'recommendations' => $recommendations]);
     $cartPreviewContent = $this->renderView('WellCommerceCartBundle:Front/Common:preview.html.twig');
     return $this->jsonResponse(['basketModalContent' => $basketModalContent, 'cartPreviewContent' => $cartPreviewContent, 'templateData' => []]);
 }
コード例 #4
0
 public function __construct(ProductInterface $product, ProductAttributeInterface $attribute = null, $quantity, \Exception $previous)
 {
     $message = sprintf('Cannot add item with id: "%s", attribute: "%s" and quantity: "%s" to cart', $product->getId(), null === $attribute ? 0 : $attribute->getId(), $quantity);
     parent::__construct($message, $previous->getCode(), $previous);
 }
コード例 #5
0
 public function getIdentifier() : int
 {
     return $this->product->getId();
 }