Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: extends WellCommerce\Bundle\CoreBundle\Entity\TranslatableInterface, extends WellCommerce\Bundle\CoreBundle\Entity\TimestampableInterface, extends WellCommerce\Bundle\CoreBundle\Entity\BlameableInterface, extends WellCommerce\Bundle\MultiStoreBundle\Entity\ShopCollectionAwareInterface, extends WellCommerce\Bundle\ProducerBundle\Entity\ProducerAwareInterface, extends WellCommerce\Bundle\UnitBundle\Entity\UnitAwareInterface, extends WellCommerce\Bundle\AvailabilityBundle\Entity\AvailabilityAwareInterface
 /**
  * {@inheritdoc}
  */
 public function getAttributes(ProductInterface $product) : array
 {
     $attributes = [];
     $product->getVariants()->map(function (VariantInterface $variant) use(&$attributes) {
         $this->extractAttributesData($variant, $attributes);
     });
     return $attributes;
 }
 private function addBreadcrumbs(ProductInterface $product)
 {
     $category = $product->getCategories()->last();
     $paths = $this->get('category.repository')->getCategoryPath($category);
     /** @var CategoryInterface $path */
     foreach ($paths as $path) {
         $this->getBreadcrumbProvider()->add(new Breadcrumb(['label' => $path->translate()->getName(), 'url' => $this->getRouterHelper()->generateUrl($path->translate()->getRoute()->getId())]));
     }
     $this->getBreadcrumbProvider()->add(new Breadcrumb(['label' => $product->translate()->getName()]));
 }
 /**
  * {@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();
 }
 public function getFieldsCollection() : Collection
 {
     $accessor = PropertyAccess::createPropertyAccessor();
     $fields = new ArrayCollection();
     $translations = $this->product->getTranslations();
     foreach ($translations as $locale => $translation) {
         $fields->add(new SearchField('name_' . $locale, $accessor->getValue($translation, 'name')));
         $fields->add(new SearchField('description_' . $locale, $accessor->getValue($translation, 'description')));
         $fields->add(new SearchField('short_description' . $locale, $accessor->getValue($translation, 'shortDescription')));
     }
     $fields->add(new SearchField('sku', $this->product->getSku()));
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 public function calculateProduct(ShippingMethodInterface $shippingMethod, ProductInterface $product)
 {
     $baseCurrency = $product->getSellPrice()->getCurrency();
     $targetCurrency = $shippingMethod->getCurrency()->getCode();
     $totalGrossAmount = $this->currencyHelper->convert($product->getSellPrice()->getFinalGrossAmount(), $baseCurrency, $targetCurrency);
     $ranges = $shippingMethod->getCosts();
     $supportedRanges = $ranges->filter(function (ShippingMethodCostInterface $cost) use($totalGrossAmount) {
         return $cost->getRangeFrom() <= $totalGrossAmount && $cost->getRangeTo() >= $totalGrossAmount;
     });
     if ($supportedRanges->count()) {
         return $supportedRanges->first();
     }
     return null;
 }
Esempio n. 6
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]);
 }
Esempio n. 7
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' => []]);
 }
 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);
 }
 public function indexAction(ProductInterface $product) : Response
 {
     $this->getBreadcrumbProvider()->add(new Breadcrumb(['label' => $product->translate()->getName()]));
     $this->getProductStorage()->setCurrentProduct($product);
     return $this->displayTemplate('index', ['product' => $product]);
 }
 protected function syncProductStock(ProductInterface $product)
 {
     $trackStock = $product->getTrackStock();
     if (true === $trackStock) {
         $product->setEnabled($product->getStock() > 0);
     }
 }
 public function getCurrency() : string
 {
     return $this->product->getSellPrice()->getCurrency();
 }
Esempio n. 12
0
 public function indexAction(ProductInterface $product)
 {
     $this->addBreadCrumbItem(new BreadcrumbItem(['name' => $product->translate()->getName()]));
     $this->manager->getProductContext()->setCurrentProduct($product);
     return $this->displayTemplate('index', ['product' => $product]);
 }
 protected function syncProductStock(ProductInterface $product)
 {
     $trackStock = $product->getTrackStock();
     $stock = $product->getStock();
     $grossPrice = $product->getSellPrice()->getFinalGrossAmount();
     $isStockAvailable = true === $trackStock ? $stock > 0 : 1;
     $isPriceNonZero = $grossPrice > 0;
     if (false === $isStockAvailable && false === $isPriceNonZero) {
         $product->setEnabled(false);
     }
 }
 public function getIdentifier() : int
 {
     return $this->product->getId();
 }