Beispiel #1
0
 /**
  * Add Use Manage Stock Condition to collection
  *
  * @param null|int $storeId
  * @return $this
  */
 public function useManageStockFilter($storeId = null)
 {
     $this->joinInventoryItem();
     $manageStockExpr = $this->getConnection()->getCheckSql($this->_getInventoryItemField('use_config_manage_stock') . ' = 1', (int) $this->stockConfiguration->getManageStock($storeId), $this->_getInventoryItemField('manage_stock'));
     $this->getSelect()->where($manageStockExpr . ' = ?', 1);
     return $this;
 }
Beispiel #2
0
 /**
  * Retrieve can Manage Stock
  *
  * @return int
  */
 public function getManageStock()
 {
     if ($this->getUseConfigManageStock()) {
         return $this->stockConfiguration->getManageStock($this->getStoreId());
     }
     return (int) $this->getData(static::MANAGE_STOCK);
 }
 /**
  * Filter stock data
  *
  * @param array $stockData
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function filter(array $stockData)
 {
     if (!isset($stockData['use_config_manage_stock'])) {
         $stockData['use_config_manage_stock'] = 0;
     }
     if ($stockData['use_config_manage_stock'] == 1 && !isset($stockData['manage_stock'])) {
         $stockData['manage_stock'] = $this->stockConfiguration->getManageStock();
     }
     if (isset($stockData['qty']) && (double) $stockData['qty'] > self::MAX_QTY_VALUE) {
         $stockData['qty'] = self::MAX_QTY_VALUE;
     }
     if (isset($stockData['min_qty']) && (int) $stockData['min_qty'] < 0) {
         $stockData['min_qty'] = 0;
     }
     if (!isset($stockData['is_decimal_divided']) || $stockData['is_qty_decimal'] == 0) {
         $stockData['is_decimal_divided'] = 0;
     }
     return $stockData;
 }
 /**
  * Fill simple product data during generation
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Catalog\Model\Product $parentProduct
  * @param array $postData
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @return void
  */
 protected function fillSimpleProductData(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $parentProduct, $postData)
 {
     $product->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID)->setTypeId($postData['weight'] ? ProductType::TYPE_SIMPLE : ProductType::TYPE_VIRTUAL)->setAttributeSetId($parentProduct->getNewVariationsAttributeSetId());
     foreach ($product->getTypeInstance()->getEditableAttributes($product) as $attribute) {
         if ($attribute->getIsUnique() || $attribute->getAttributeCode() == 'url_key' || $attribute->getFrontend()->getInputType() == 'gallery' || $attribute->getFrontend()->getInputType() == 'media_image' || !$attribute->getIsVisible()) {
             continue;
         }
         $product->setData($attribute->getAttributeCode(), $parentProduct->getData($attribute->getAttributeCode()));
     }
     $postData['stock_data'] = $parentProduct->getStockData();
     $postData['stock_data']['manage_stock'] = $postData['quantity_and_stock_status']['qty'] === '' ? 0 : 1;
     if (!isset($postData['stock_data']['is_in_stock'])) {
         $stockStatus = $parentProduct->getQuantityAndStockStatus();
         $postData['stock_data']['is_in_stock'] = $stockStatus['is_in_stock'];
     }
     $configDefaultValue = $this->stockConfiguration->getManageStock($product->getStoreId());
     $postData['stock_data']['use_config_manage_stock'] = $postData['stock_data']['manage_stock'] == $configDefaultValue ? 1 : 0;
     $postData = $this->processMediaGallery($product, $postData);
     $postData['status'] = isset($postData['status']) ? $postData['status'] : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
     $product->addData($postData)->setWebsiteIds($parentProduct->getWebsiteIds())->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
 }