当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductInterface::getExtensionAttributes方法代码示例

本文整理汇总了PHP中Magento\Catalog\Api\Data\ProductInterface::getExtensionAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getExtensionAttributes方法的具体用法?PHP ProductInterface::getExtensionAttributes怎么用?PHP ProductInterface::getExtensionAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Api\Data\ProductInterface的用法示例。


在下文中一共展示了ProductInterface::getExtensionAttributes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveConfigurableProductOptions

 /**
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param \Magento\ConfigurableProduct\Api\Data\OptionInterface[] $options
  * @return $this
  */
 protected function saveConfigurableProductOptions(\Magento\Catalog\Api\Data\ProductInterface $product, array $options)
 {
     $existingOptionIds = [];
     if ($product->getExtensionAttributes() !== null) {
         $extensionAttributes = $product->getExtensionAttributes();
         if ($extensionAttributes->getConfigurableProductOptions() !== null) {
             $existingOptions = $extensionAttributes->getConfigurableProductOptions();
             foreach ($existingOptions as $option) {
                 $existingOptionIds[] = $option->getId();
             }
         }
     }
     $updatedOptionIds = [];
     foreach ($options as $option) {
         if ($option->getId()) {
             $updatedOptionIds[] = $option->getId();
         }
         $this->optionRepository->save($product->getSku(), $option);
     }
     $optionIdsToDelete = array_diff($existingOptionIds, $updatedOptionIds);
     foreach ($optionIdsToDelete as $optionId) {
         $this->optionRepository->deleteById($product->getSku(), $optionId);
     }
     return $this;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:30,代码来源:AroundProductRepositorySave.php

示例2: execute

 /**
  * @param string $entityType
  * @param ProductInterface $entity
  * @return ProductInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     if ($entity->getTypeId() !== Configurable::TYPE_CODE) {
         return $entity;
     }
     $extensionAttributes = $entity->getExtensionAttributes();
     $extensionAttributes->setConfigurableProductLinks($this->getLinkedProducts($entity));
     $extensionAttributes->setConfigurableProductOptions($this->optionLoader->load($entity));
     $entity->setExtensionAttributes($extensionAttributes);
     return $entity;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:ReadHandler.php

示例3: getStockItemToBeUpdated

 /**
  * Return the stock item that needs to be updated.
  * If the stock item does not need to be updated, return null.
  *
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @return \Magento\CatalogInventory\Api\Data\StockItemInterface|null
  */
 protected function getStockItemToBeUpdated($product)
 {
     // from the API, all the data we care about will exist as extension attributes of the original product
     $extendedAttributes = $product->getExtensionAttributes();
     if ($extendedAttributes !== null) {
         $stockItem = $extendedAttributes->getStockItem();
         if ($stockItem != null) {
             return $stockItem;
         }
     }
     // we have no new stock item information to update, however we need to ensure that the product does have some
     // stock item information present.  On a newly created product, it will not have any stock item info.
     $stockItem = $this->stockRegistry->getStockItem($product->getId());
     if ($stockItem->getItemId() != null) {
         // we already have stock item info, so we return null since nothing more needs to be updated
         return null;
     }
     return $stockItem;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:26,代码来源:AroundProductRepositorySave.php

示例4: execute

 /**
  * @param ProductInterface $entity
  * @param array $arguments
  * @return ProductInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     if ($entity->getTypeId() !== Configurable::TYPE_CODE) {
         return $entity;
     }
     $extensionAttributes = $entity->getExtensionAttributes();
     if ($extensionAttributes === null) {
         return $entity;
     }
     if ($extensionAttributes->getConfigurableProductOptions() !== null) {
         $this->deleteConfigurableProductAttributes($entity);
     }
     $configurableOptions = (array) $extensionAttributes->getConfigurableProductOptions();
     if (!empty($configurableOptions)) {
         $this->saveConfigurableProductAttributes($entity, $configurableOptions);
     }
     $configurableLinks = (array) $extensionAttributes->getConfigurableProductLinks();
     $this->resourceModel->saveProducts($entity, $configurableLinks);
     return $entity;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:SaveHandler.php

示例5: afterInitialize

 /**
  * Initialize data for configurable product
  *
  * @param Helper $subject
  * @param ProductInterface $product
  * @return ProductInterface
  * @throws \InvalidArgumentException
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterInitialize(Helper $subject, ProductInterface $product)
 {
     $attributes = $this->request->getParam('attributes');
     $productData = $this->request->getPost('product', []);
     if ($product->getTypeId() !== ConfigurableProduct::TYPE_CODE || empty($attributes)) {
         return $product;
     }
     $setId = $this->request->getPost('new-variations-attribute-set-id');
     if ($setId) {
         $product->setAttributeSetId($setId);
     }
     $extensionAttributes = $product->getExtensionAttributes();
     $product->setNewVariationsAttributeSetId($setId);
     $configurableOptions = [];
     if (!empty($productData['configurable_attributes_data'])) {
         $configurableOptions = $this->optionsFactory->create((array) $productData['configurable_attributes_data']);
     }
     $extensionAttributes->setConfigurableProductOptions($configurableOptions);
     $this->setLinkedProducts($product, $extensionAttributes);
     $product->setCanSaveConfigurableAttributes((bool) $this->request->getPost('affect_configurable_product_attributes'));
     $product->setExtensionAttributes($extensionAttributes);
     return $product;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:33,代码来源:Configurable.php

示例6: getStockItemFromProduct

 /**
  * @param ProductInterface $product
  * @return StockItemInterface
  * @throws LocalizedException
  */
 private function getStockItemFromProduct(ProductInterface $product)
 {
     $stockItem = null;
     $extendedAttributes = $product->getExtensionAttributes();
     if ($extendedAttributes !== null) {
         $stockItem = $extendedAttributes->getStockItem();
         if ($stockItem) {
             $this->validateStockItem($product, $stockItem);
         }
     }
     return $stockItem;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:AroundProductRepositorySave.php

示例7: saveSamples

 /**
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param \Magento\Downloadable\Api\Data\SampleInterface[] $samples
  * @return $this
  */
 protected function saveSamples(\Magento\Catalog\Api\Data\ProductInterface $product, array $samples)
 {
     $existingSampleIds = [];
     $extensionAttributes = $product->getExtensionAttributes();
     if ($extensionAttributes !== null) {
         $existingSamples = $extensionAttributes->getDownloadableProductSamples();
         if ($existingSamples !== null) {
             foreach ($existingSamples as $existingSample) {
                 $existingSampleIds[] = $existingSample->getId();
             }
         }
     }
     $updatedSampleIds = [];
     foreach ($samples as $sample) {
         $sampleId = $sample->getId();
         if ($sampleId) {
             $updatedSampleIds[] = $sampleId;
         }
         $this->sampleRepository->save($product->getSku(), $sample);
     }
     $sampleIdsToDelete = array_diff($existingSampleIds, $updatedSampleIds);
     foreach ($sampleIdsToDelete as $sampleId) {
         $this->sampleRepository->delete($sampleId);
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:31,代码来源:AroundProductRepositorySave.php


注:本文中的Magento\Catalog\Api\Data\ProductInterface::getExtensionAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。