Пример #1
0
 public function reindexProducts()
 {
     $products = $this->productRepository->findAll();
     $this->searchIndexManager->eraseIndex(ProductIndexerInterface::DEFAULT_INDEX_NAME);
     foreach ($products as $product) {
         $this->addProduct($product);
     }
     $index = $this->searchIndexManager->getIndex(ProductIndexerInterface::DEFAULT_INDEX_NAME);
     $index->optimize();
 }
Пример #2
0
 /**
  * Creates an instance of order product
  *
  * @param array          $productValues
  * @param OrderInterface $order
  *
  * @return \WellCommerce\AppBundle\Entity\OrderProductInterface
  */
 protected function createOrderProduct(array $productValues, OrderInterface $order)
 {
     $productId = (int) $productValues['product_id'];
     $product = $this->productRepository->find($productId);
     if (!$product instanceof ProductInterface) {
         throw new \InvalidArgumentException(sprintf('Cannot add product to order. ID "%s" does not exists.', $productId));
     }
     $orderProduct = $this->factory->create();
     $orderProduct->setBuyPrice($product->getBuyPrice());
     $orderProduct->setOrder($order);
     $orderProduct->setProduct($product);
     $orderProduct->setProductAttribute(null);
     $orderProduct->setQuantity($productValues['quantity']);
     $orderProduct->setWeight($productValues['weight']);
     $sellPrice = new Price();
     $grossAmount = $productValues['gross_amount'];
     $taxRate = $product->getSellPriceTax()->getValue();
     $netAmount = TaxHelper::calculateNetPrice($grossAmount, $taxRate);
     $sellPrice->setTaxRate($taxRate);
     $sellPrice->setTaxAmount($grossAmount - $netAmount);
     $sellPrice->setNetAmount($netAmount);
     $sellPrice->setGrossAmount($grossAmount);
     $sellPrice->setCurrency($order->getCurrency());
     $orderProduct->setSellPrice($sellPrice);
     return $orderProduct;
 }