当前位置: 首页>>代码示例>>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;未经允许,请勿转载。