getVariants() public method

public getVariants ( ) : Doctrine\Common\Collections\Collection
return Doctrine\Common\Collections\Collection
コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getAttributes(ProductInterface $product) : array
 {
     $attributes = [];
     $product->getVariants()->map(function (VariantInterface $variant) use(&$attributes) {
         $this->extractAttributesData($variant, $attributes);
     });
     return $attributes;
 }
コード例 #2
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' => []]);
 }