示例#1
0
 /**
  * Simple helper function for calculating item-price
  *
  * @param ItemInterface $item
  * @param ProductPrice $productPriceEntity
  *
  * @return float
  */
 private function calcTotalPriceForItem($item, $productPriceEntity)
 {
     $expectedPrice = $item->getQuantity() * $productPriceEntity->getPrice();
     $expectedPrice -= $expectedPrice / 100 * $item->getDiscount();
     return $expectedPrice;
 }
示例#2
0
 /**
  * Set addon data to item.
  *
  * @param ItemInterface $lastProcessedProductItem
  * @param ItemInterface $item
  * @param ProductInterface $parentItemProduct Items product parent product.
  *
  * @throws \Exception
  *
  * @return Addon
  */
 protected function setAddonData(ItemInterface $lastProcessedProductItem, ItemInterface $item, ProductInterface $parentItemProduct = null)
 {
     $item->setParent($lastProcessedProductItem);
     $parentProduct = $lastProcessedProductItem->getProduct();
     $addonProduct = $item->getProduct();
     /** @var Addon $addon */
     $addon = $this->addonRepository->findOneBy(['product' => $parentProduct, 'addon' => $addonProduct]);
     // Check if parent product has an addon relation.
     if (!$addon && $parentItemProduct) {
         $addon = $this->addonRepository->findOneBy(['product' => $parentProduct, 'addon' => $parentItemProduct]);
     }
     if (!$addon) {
         throw new \Exception('Addon id ' . $addonProduct->getId() . ' for product id ' . $parentProduct->getId() . ' not found.');
     }
     $item->setAddon($addon);
     return $addon;
 }
示例#3
0
 /**
  * Checks if product of an item is in active state.
  *
  * @param ItemInterface $item
  *
  * @throws ProductNotValidException
  * @throws ProductNotFoundException
  *
  * @return bool
  */
 protected function validateIfItemProductActive(ItemInterface $item)
 {
     $product = $item->getProduct();
     if (!$product) {
         throw new ProductNotFoundException('item ' . $item->getId());
     }
     if (!$product->isValidShopProduct($this->defaultCurrency)) {
         throw new ProductNotValidException($product->getId());
     }
     return true;
 }