/**
  * Initialize stock item
  *
  * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
  * @param \Magento\Quote\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\DataObject
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function initialize(\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem, \Magento\Quote\Model\Quote\Item $quoteItem, $qty)
 {
     /**
      * When we work with subitem
      */
     if ($quoteItem->getParentItem()) {
         $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
         /**
          * we are using 0 because original qty was processed
          */
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), 0);
     } else {
         $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
         $rowQty = $qty;
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseQty);
     }
     $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
     if ($productTypeCustomOption !== null) {
         // Check if product related to current item is a part of product that represents product set
         if ($this->typeConfig->isProductSet($productTypeCustomOption->getValue())) {
             $stockItem->setIsChildItem(true);
         }
     }
     $stockItem->setProductName($quoteItem->getProduct()->getName());
     $result = $this->stockState->checkQuoteItemQty($quoteItem->getProduct()->getId(), $rowQty, $qtyForCheck, $qty, $quoteItem->getProduct()->getStore()->getWebsiteId());
     if ($stockItem->hasIsChildItem()) {
         $stockItem->unsIsChildItem();
     }
     if ($result->getItemIsQtyDecimal() !== null) {
         $quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
         if ($quoteItem->getParentItem()) {
             $quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
         }
     }
     /**
      * Just base (parent) item qty can be changed
      * qty of child products are declared just during add process
      * exception for updating also managed by product type
      */
     if ($result->getHasQtyOptionUpdate() && (!$quoteItem->getParentItem() || $quoteItem->getParentItem()->getProduct()->getTypeInstance()->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct()))) {
         $quoteItem->setData('qty', $result->getOrigQty());
     }
     if ($result->getItemUseOldQty() !== null) {
         $quoteItem->setUseOldQty($result->getItemUseOldQty());
     }
     if ($result->getMessage() !== null) {
         $quoteItem->setMessage($result->getMessage());
     }
     if ($result->getItemBackorders() !== null) {
         $quoteItem->setBackorders($result->getItemBackorders());
     }
     return $result;
 }
 /**
  * Automaticaly assign backend model to weee attributes
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $backendModel = \Magento\Weee\Model\Attribute\Backend\Weee\Tax::getBackendModelName();
     /** @var $object \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
     $object = $observer->getEvent()->getAttribute();
     if ($object->getFrontendInput() == 'weee') {
         $object->setBackendModel($backendModel);
         if (!$object->getApplyTo()) {
             $applyTo = [];
             foreach ($this->productType->getOptions() as $option) {
                 if ($this->productTypeConfig->isProductSet($option['value'])) {
                     continue;
                 }
                 $applyTo[] = $option['value'];
             }
             $object->setApplyTo($applyTo);
         }
     }
     return $this;
 }
Example #3
0
 /**
  * Check is product available depending on final price or type set(configurable)
  *
  * @param bool $isInCatalog
  * @return bool
  */
 public function isPriceOrSetAvailable($isInCatalog)
 {
     if ($isInCatalog) {
         // Show PayPal shortcut on a product view page only if product has nonzero price
         /** @var $currentProduct \Magento\Catalog\Model\Product */
         $currentProduct = $this->_registry->registry('current_product');
         if (!is_null($currentProduct)) {
             $productPrice = (double) $currentProduct->getFinalPrice();
             if (empty($productPrice) && !$this->_productTypeConfig->isProductSet($currentProduct->getTypeId())) {
                 return false;
             }
         }
     }
     return true;
 }
Example #4
0
 /**
  * Returns whether Qty field is valid for this item
  *
  * @return bool
  */
 public function canHaveQty()
 {
     $product = $this->getProduct();
     return !$this->productTypeConfig->isProductSet($product->getTypeId());
 }
Example #5
0
 /**
  * Check whether quantity field should be rendered
  *
  * @return bool
  */
 public function shouldRenderQuantity()
 {
     return !$this->productTypeConfig->isProductSet($this->getProduct()->getTypeId());
 }
Example #6
0
 /**
  * Returns whether this qty field must be inactive
  *
  * @param \Magento\Framework\DataObject $row
  * @return bool
  */
 protected function _isInactive($row)
 {
     return $this->typeConfig->isProductSet($row->getTypeId());
 }