當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::getStockData方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\Product::getStockData方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getStockData方法的具體用法?PHP Product::getStockData怎麽用?PHP Product::getStockData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getStockData方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: beforeSave

 /**
  * Prepare inventory data from custom attribute
  *
  * @param Product $object
  * @return void
  */
 public function beforeSave($object)
 {
     $stockData = $object->getData($this->getAttribute()->getAttributeCode());
     if (isset($stockData['qty']) && $stockData['qty'] === '') {
         $stockData['qty'] = null;
     }
     if ($object->getStockData() !== null || $stockData !== null) {
         $object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData));
     }
     $object->unsetData($this->getAttribute()->getAttributeCode());
     parent::beforeSave($object);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:18,代碼來源:Stock.php

示例2: saveStockItemData

 /**
  * Prepare stock item data for save
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function saveStockItemData($product)
 {
     $stockItemData = $product->getStockData();
     $stockItemData['product_id'] = $product->getId();
     if (!isset($stockItemData['website_id'])) {
         $stockItemData['website_id'] = $this->stockConfiguration->getDefaultScopeId();
     }
     $stockItemData['stock_id'] = $this->stockRegistry->getStock($stockItemData['website_id'])->getStockId();
     foreach ($this->paramListToCheck as $dataKey => $configPath) {
         if (null !== $product->getData($configPath['item']) && null === $product->getData($configPath['config'])) {
             $stockItemData[$dataKey] = false;
         }
     }
     $originalQty = $product->getData('stock_data/original_inventory_qty');
     if (strlen($originalQty) > 0) {
         $stockItemData['qty_correction'] = (isset($stockItemData['qty']) ? $stockItemData['qty'] : 0) - $originalQty;
     }
     // todo resolve issue with builder and identity field name
     $stockItem = $this->stockRegistry->getStockItem($stockItemData['product_id'], $stockItemData['website_id']);
     $stockItem->addData($stockItemData);
     $this->stockItemRepository->save($stockItem);
     return $this;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:29,代碼來源:SaveInventoryDataObserver.php

示例3: _fillSimpleProductData

 /**
  * 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)
  */
 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'] ? \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE : \Magento\Catalog\Model\Product\Type::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;
     if (!empty($postData['image'])) {
         $postData['small_image'] = $postData['thumbnail'] = $postData['image'];
         $postData['media_gallery']['images'][] = ['position' => 1, 'file' => $postData['image'], 'disabled' => 0, 'label' => ''];
     }
     $product->addData($postData)->setWebsiteIds($parentProduct->getWebsiteIds())->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
 }
開發者ID:niranjanssiet,項目名稱:magento2,代碼行數:32,代碼來源:Configurable.php

示例4: saveStockItemData

 /**
  * Prepare stock item data for save
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function saveStockItemData($product)
 {
     $stockItemData = $product->getStockData();
     $stockItemData['product_id'] = $product->getId();
     /**
      * @todo Should be refactored together with \Magento\CatalogInventory\Model\Stock\Item::getStockId
      */
     $stockItemData['stock_id'] = \Magento\CatalogInventory\Model\Stock\Item::DEFAULT_STOCK_ID;
     foreach ($this->paramListToCheck as $dataKey => $configPath) {
         if (null !== $product->getData($configPath['item']) && null === $product->getData($configPath['config'])) {
             $stockItemData[$dataKey] = false;
         }
     }
     $originalQty = $product->getData('stock_data/original_inventory_qty');
     if (strlen($originalQty) > 0) {
         $stockItemData['qty_correction'] = $stockItemData['qty'] - $originalQty;
     }
     $stockItemDo = $this->stockItemService->getStockItem($product->getId());
     $this->stockItemService->saveStockItem($this->stockItemBuilder->mergeDataObjectWithArray($stockItemDo, $stockItemData));
     return $this;
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:27,代碼來源:Observer.php

示例5: fillSimpleProductData

 /**
  * 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()->getSetAttributes($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()));
     }
     $keysFilter = ['item_id', 'product_id', 'stock_id', 'type_id', 'website_id'];
     $postData['stock_data'] = array_diff_key((array) $parentProduct->getStockData(), array_flip($keysFilter));
     if (!isset($postData['stock_data']['is_in_stock'])) {
         $stockStatus = $parentProduct->getQuantityAndStockStatus();
         $postData['stock_data']['is_in_stock'] = $stockStatus['is_in_stock'];
     }
     $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);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:30,代碼來源:VariationHandler.php


注:本文中的Magento\Catalog\Model\Product::getStockData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。