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


PHP ProductInterface::getProductOptions方法代码示例

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


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

示例1: save

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
 {
     if ($saveOptions) {
         $productOptions = $product->getProductOptions();
     }
     $isDeleteOptions = $product->getIsDeleteOptions();
     $tierPrices = $product->getData('tier_price');
     $productId = $this->resourceModel->getIdBySku($product->getSku());
     $ignoreLinksFlag = $product->getData('ignore_links_flag');
     $productDataArray = $this->extensibleDataObjectConverter->toNestedArray($product, [], 'Magento\\Catalog\\Api\\Data\\ProductInterface');
     $productLinks = null;
     if (!$ignoreLinksFlag && $ignoreLinksFlag !== null) {
         $productLinks = $product->getProductLinks();
     }
     $product = $this->initializeProductData($productDataArray, empty($productId));
     if (isset($productDataArray['options'])) {
         if (!empty($productDataArray['options']) || $isDeleteOptions) {
             $this->processOptions($product, $productDataArray['options']);
             $product->setCanSaveCustomOptions(true);
         }
     }
     $this->processLinks($product, $productLinks);
     if (isset($productDataArray['media_gallery_entries'])) {
         $this->processMediaGallery($product, $productDataArray['media_gallery_entries']);
     }
     $validationResult = $this->resourceModel->validate($product);
     if (true !== $validationResult) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Invalid product data: %1', implode(',', $validationResult)));
     }
     try {
         if ($saveOptions) {
             $product->setProductOptions($productOptions);
             $product->setCanSaveCustomOptions(true);
         }
         if ($tierPrices !== null) {
             $product->setData('tier_price', $tierPrices);
         }
         $this->resourceModel->save($product);
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $product->getData($exception->getAttributeCode()), $exception);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
     }
     unset($this->instances[$product->getSku()]);
     unset($this->instancesById[$product->getId()]);
     return $this->get($product->getSku());
 }
开发者ID:nblair,项目名称:magescotch,代码行数:52,代码来源:ProductRepository.php

示例2: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
 {
     if ($saveOptions) {
         $productOptions = $product->getProductOptions();
     }
     $groupPrices = $product->getData('group_price');
     $tierPrices = $product->getData('tier_price');
     $productId = $this->resourceModel->getIdBySku($product->getSku());
     $productDataArray = $this->extensibleDataObjectConverter->toNestedArray($product, [], 'Magento\\Catalog\\Api\\Data\\ProductInterface');
     $product = $this->initializeProductData($productDataArray, empty($productId));
     $validationResult = $this->resourceModel->validate($product);
     if (true !== $validationResult) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Invalid product data: %1', implode(',', $validationResult)));
     }
     try {
         if ($saveOptions) {
             $product->setProductOptions($productOptions);
             $product->setCanSaveCustomOptions(true);
         }
         $product->setData('group_price', $groupPrices);
         $product->setData('tier_price', $tierPrices);
         $this->resourceModel->save($product);
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $product->getData($exception->getAttributeCode()), $exception);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
     }
     unset($this->instances[$product->getSku()]);
     unset($this->instancesById[$product->getId()]);
     return $product;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:34,代码来源:ProductRepository.php


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