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


PHP Product::getExtensionAttributes方法代码示例

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


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

示例1: assertEqualsSpecificAttributes

 /**
  * @param \Magento\Catalog\Model\Product $expectedProduct
  * @param \Magento\Catalog\Model\Product $actualProduct
  */
 protected function assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
 {
     $expectedBundleProductOptions = $expectedProduct->getExtensionAttributes()->getBundleProductOptions();
     $actualBundleProductOptions = $actualProduct->getExtensionAttributes()->getBundleProductOptions();
     $this->assertEquals(count($expectedBundleProductOptions), count($actualBundleProductOptions));
     $expectedBundleProductOptionsToCompare = [];
     foreach ($expectedBundleProductOptions as $expectedBundleProductOption) {
         $expectedBundleProductOptionsToCompare[$expectedBundleProductOption->getTitle()]['type'] = $expectedBundleProductOption->getType();
         foreach ($expectedBundleProductOption->getProductLinks() as $productLink) {
             $expectedBundleProductOptionsToCompare[$expectedBundleProductOption->getTitle()]['product_links'][] = $productLink->getSku();
         }
     }
     $actualBundleProductOptionsToCompare = [];
     foreach ($actualBundleProductOptions as $actualBundleProductOption) {
         $actualBundleProductOptionsToCompare[$actualBundleProductOption->getTitle()]['type'] = $actualBundleProductOption->getType();
         foreach ($actualBundleProductOption->getProductLinks() as $productLink) {
             $actualBundleProductOptionsToCompare[$actualBundleProductOption->getTitle()]['product_links'][] = $productLink->getSku();
         }
     }
     $this->assertEquals(count($expectedBundleProductOptions), count($actualBundleProductOptions));
     foreach ($expectedBundleProductOptionsToCompare as $key => $expectedBundleProductOption) {
         $this->assertEquals($expectedBundleProductOption['type'], $actualBundleProductOptionsToCompare[$key]['type']);
         $expectedProductLinks = $expectedBundleProductOption['product_links'];
         $actualProductLinks = $actualBundleProductOptionsToCompare[$key]['product_links'];
         sort($expectedProductLinks);
         sort($actualProductLinks);
         $this->assertEquals($expectedProductLinks, $actualProductLinks);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:33,代码来源:BundleTest.php

示例2: getTargetLink

 /**
  * Retrieve product link by its ID (or first link if ID is not specified)
  *
  * @param Product $product
  * @param int|null $linkId
  * @return Link|null
  */
 protected function getTargetLink(Product $product, $linkId = null)
 {
     $links = $product->getExtensionAttributes()->getDownloadableProductLinks();
     if ($linkId !== null) {
         return isset($links[$linkId]) ? $links[$linkId] : null;
     }
     // return first link
     return reset($links);
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:16,代码来源:LinkRepositoryTest.php

示例3: afterLoad

 /**
  * Add stock item information to the product's extension attributes
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function afterLoad(\Magento\Catalog\Model\Product $product)
 {
     $productExtension = $product->getExtensionAttributes();
     if ($productExtension === null) {
         $productExtension = $this->productExtensionFactory->create();
     }
     // stockItem := \Magento\CatalogInventory\Api\Data\StockItemInterface
     $productExtension->setStockItem($this->stockRegistry->getStockItem($product->getId()));
     $product->setExtensionAttributes($productExtension);
     return $product;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:AfterProductLoad.php

示例4: build

 /**
  * Duplicating bundle options and selections
  *
  * @param Product $product
  * @param Product $duplicate
  * @return void
  */
 public function build(Product $product, Product $duplicate)
 {
     if ($product->getTypeId() != Type::TYPE_BUNDLE) {
         //do nothing if not bundle
         return;
     }
     $bundleOptions = $product->getExtensionAttributes()->getBundleProductOptions();
     $duplicatedBundleOptions = [];
     foreach ($bundleOptions as $key => $bundleOption) {
         $duplicatedBundleOptions[$key] = clone $bundleOption;
     }
     $duplicate->getExtensionAttributes()->setBundleProductOptions($duplicatedBundleOptions);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:20,代码来源:Bundle.php

示例5: afterLoad

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function afterLoad(\Magento\Catalog\Model\Product $product)
 {
     if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
         return $product;
     }
     $productExtension = $product->getExtensionAttributes();
     if ($productExtension === null) {
         $productExtension = $this->productExtensionFactory->create();
     }
     $productExtension->setConfigurableProductOptions($this->getOptions($product));
     $productExtension->setConfigurableProductLinks($this->getLinkedProducts($product));
     $product->setExtensionAttributes($productExtension);
     return $product;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:18,代码来源:AfterProductLoad.php

示例6: assertEqualsSpecificAttributes

 /**
  * @param \Magento\Catalog\Model\Product $expectedProduct
  * @param \Magento\Catalog\Model\Product $actualProduct
  */
 protected function assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
 {
     $expectedProductLinks = $expectedProduct->getExtensionAttributes()->getDownloadableProductLinks();
     $expectedProductSamples = $expectedProduct->getExtensionAttributes()->getDownloadableProductSamples();
     $actualProductLinks = $actualProduct->getExtensionAttributes()->getDownloadableProductLinks();
     $actualProductSamples = $actualProduct->getExtensionAttributes()->getDownloadableProductSamples();
     $this->assertEquals(count($expectedProductLinks), count($actualProductLinks));
     $this->assertEquals(count($expectedProductSamples), count($actualProductSamples));
     $expectedLinksArray = [];
     foreach ($expectedProductLinks as $link) {
         $expectedLinksArray[] = $link->getData();
     }
     foreach ($actualProductLinks as $actualLink) {
         $this->assertContains($expectedLinksArray, $actualLink->getData());
     }
     $expectedSamplesArray = [];
     foreach ($expectedProductSamples as $sample) {
         $expectedSamplesArray[] = $sample->getData();
     }
     foreach ($actualProductSamples as $actualSample) {
         $this->assertContains($expectedSamplesArray, $actualSample->getData());
     }
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:27,代码来源:DownloadableTest.php

示例7: getTargetLink

 /**
  * Retrieve product link by its ID (or first link if ID is not specified)
  *
  * @param Product $product
  * @param int|null $linkId
  * @return Link|null
  */
 protected function getTargetLink(Product $product, $linkId = null)
 {
     $links = $product->getExtensionAttributes()->getDownloadableProductLinks();
     if ($linkId !== null) {
         if (!empty($links)) {
             foreach ($links as $link) {
                 if ($link->getId() == $linkId) {
                     return $link;
                 }
             }
         }
         return null;
     }
     // return first link
     return reset($links);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:23,代码来源:LinkRepositoryTest.php

示例8: getTargetSample

 /**
  * Retrieve product sample by its ID (or first sample if ID is not specified)
  *
  * @param Product $product
  * @param int|null $sampleId
  * @return Sample|null
  */
 protected function getTargetSample(Product $product, $sampleId = null)
 {
     $samples = $product->getExtensionAttributes()->getDownloadableProductSamples();
     if ($sampleId) {
         /* @var $sample \Magento\Downloadable\Model\Sample */
         if ($samples) {
             foreach ($samples as $sample) {
                 if ($sample->getId() == $sampleId) {
                     return $sample;
                 }
             }
         }
         return null;
     }
     // return first sample
     return $samples[0];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:24,代码来源:SampleRepositoryTest.php

示例9: afterLoad

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function afterLoad(\Magento\Catalog\Model\Product $product)
 {
     if ($product->getTypeId() != \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         return $product;
     }
     $productExtension = $product->getExtensionAttributes() ?: $this->productExtensionFactory->create();
     $links = $this->linkRepository->getLinksByProduct($product);
     if ($links !== null) {
         $productExtension->setDownloadableProductLinks($links);
     }
     $samples = $this->sampleRepository->getSamplesByProduct($product);
     if ($samples !== null) {
         $productExtension->setDownloadableProductSamples($samples);
     }
     $product->setExtensionAttributes($productExtension);
     return $product;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:AfterProductLoad.php

示例10: afterInitialize

 /**
  * Prepare product to save
  *
  * @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject
  * @param \Magento\Catalog\Model\Product $product
  *
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function afterInitialize(\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject, \Magento\Catalog\Model\Product $product)
 {
     if ($downloadable = $this->request->getPost('downloadable')) {
         $product->setDownloadableData($downloadable);
         $extension = $product->getExtensionAttributes();
         if (isset($downloadable['link']) && is_array($downloadable['link'])) {
             $links = [];
             foreach ($downloadable['link'] as $linkData) {
                 if (!$linkData || isset($linkData['is_delete']) && $linkData['is_delete']) {
                     continue;
                 } else {
                     $links[] = $this->getLinkBuilder()->setData($linkData)->build($this->getLinkFactory()->create());
                 }
             }
             $extension->setDownloadableProductLinks($links);
         }
         if (isset($downloadable['sample']) && is_array($downloadable['sample'])) {
             $samples = [];
             foreach ($downloadable['sample'] as $sampleData) {
                 if (!$sampleData || isset($sampleData['is_delete']) && (bool) $sampleData['is_delete']) {
                     continue;
                 } else {
                     $samples[] = $this->getSampleBuilder()->setData($sampleData)->build($this->getSampleFactory()->create());
                 }
             }
             $extension->setDownloadableProductSamples($samples);
         }
         $product->setExtensionAttributes($extension);
         if ($product->getLinksPurchasedSeparately()) {
             $product->setTypeHasRequiredOptions(true)->setRequiredOptions(true);
         } else {
             $product->setTypeHasRequiredOptions(false)->setRequiredOptions(false);
         }
     }
     return $product;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:47,代码来源:Downloadable.php

示例11: processBundleOptionsData

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function processBundleOptionsData(\Magento\Catalog\Model\Product $product)
 {
     $bundleOptionsData = $product->getBundleOptionsData();
     if (!$bundleOptionsData) {
         return;
     }
     $options = [];
     foreach ($bundleOptionsData as $key => $optionData) {
         if ((bool) $optionData['delete']) {
             continue;
         }
         $option = $this->optionFactory->create(['data' => $optionData]);
         $option->setSku($product->getSku());
         $option->setOptionId(null);
         $links = [];
         $bundleLinks = $product->getBundleSelectionsData();
         if (empty($bundleLinks[$key])) {
             continue;
         }
         foreach ($bundleLinks[$key] as $linkData) {
             if ((bool) $linkData['delete']) {
                 continue;
             }
             $link = $this->linkFactory->create(['data' => $linkData]);
             if ((int) $product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
                 if (array_key_exists('selection_price_value', $linkData)) {
                     $link->setPrice($linkData['selection_price_value']);
                 }
                 if (array_key_exists('selection_price_type', $linkData)) {
                     $link->setPriceType($linkData['selection_price_type']);
                 }
             }
             $linkProduct = $this->productRepository->getById($linkData['product_id']);
             $link->setSku($linkProduct->getSku());
             $link->setQty($linkData['selection_qty']);
             if (array_key_exists('selection_can_change_qty', $linkData)) {
                 $link->setCanChangeQuantity($linkData['selection_can_change_qty']);
             }
             $links[] = $link;
         }
         $option->setProductLinks($links);
         $options[] = $option;
     }
     $extension = $product->getExtensionAttributes();
     $extension->setBundleProductOptions($options);
     $product->setExtensionAttributes($extension);
     return;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:53,代码来源:Bundle.php

示例12: getExtensionAttributes

 /**
  * {@inheritdoc}
  */
 public function getExtensionAttributes()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getExtensionAttributes');
     if (!$pluginInfo) {
         return parent::getExtensionAttributes();
     } else {
         return $this->___callPlugins('getExtensionAttributes', func_get_args(), $pluginInfo);
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:Interceptor.php

示例13: afterInitialize

 /**
  * Prepare product to save
  *
  * @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject
  * @param \Magento\Catalog\Model\Product $product
  *
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function afterInitialize(\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject, \Magento\Catalog\Model\Product $product)
 {
     if ($downloadable = $this->request->getPost('downloadable')) {
         $product->setDownloadableData($downloadable);
         $extension = $product->getExtensionAttributes();
         if (isset($downloadable['link']) && is_array($downloadable['link'])) {
             $links = [];
             foreach ($downloadable['link'] as $linkData) {
                 if (!$linkData || isset($linkData['is_delete']) && (bool) $linkData['is_delete']) {
                     continue;
                 } else {
                     unset($linkData['link_id']);
                     // TODO: need to implement setLinkFileContent()
                     $link = $this->linkFactory->create(['data' => $linkData]);
                     if (isset($linkData['type'])) {
                         $link->setLinkType($linkData['type']);
                     }
                     if (isset($linkData['file'])) {
                         $link->setLinkFile($linkData['file']);
                     }
                     if (isset($linkData['file_content'])) {
                         $link->setLinkFileContent($linkData['file_content']);
                     }
                     $link->setId(null);
                     if (isset($linkData['sample']['type'])) {
                         $link->setSampleType($linkData['sample']['type']);
                     }
                     if (isset($linkData['sample']['file'])) {
                         $link->setSampleFile($linkData['sample']['file']);
                     }
                     if (isset($linkData['sample']['url'])) {
                         $link->setSampleUrl($linkData['sample']['url']);
                     }
                     if (isset($linkData['sample']['file_content'])) {
                         $link->setSampleFileContent($linkData['file_content']);
                     }
                     $link->setStoreId($product->getStoreId());
                     $link->setWebsiteId($product->getStore()->getWebsiteId());
                     $link->setProductWebsiteIds($product->getWebsiteIds());
                     if (!$link->getSortOrder()) {
                         $link->setSortOrder(1);
                     }
                     if (null === $link->getPrice()) {
                         $link->setPrice(0);
                     }
                     if ($link->getIsUnlimited()) {
                         $link->setNumberOfDownloads(0);
                     }
                     $links[] = $link;
                 }
             }
             $extension->setDownloadableProductLinks($links);
         }
         if (isset($downloadable['sample']) && is_array($downloadable['sample'])) {
             $samples = [];
             foreach ($downloadable['sample'] as $sampleData) {
                 if (!$sampleData || isset($sampleData['is_delete']) && (bool) $sampleData['is_delete']) {
                     continue;
                 } else {
                     unset($sampleData['sample_id']);
                     $sample = $this->sampleFactory->create(['data' => $sampleData]);
                     $sample->setId(null);
                     $sample->setStoreId($product->getStoreId());
                     if (isset($sampleData['type'])) {
                         $sample->setSampleType($sampleData['type']);
                     }
                     if (isset($sampleData['sample_url'])) {
                         $sample->setSampleUrl($sampleData['sample_url']);
                     }
                     if (!$sample->getSortOrder()) {
                         $sample->setSortOrder(1);
                     }
                     $samples[] = $sample;
                 }
             }
             $extension->setDownloadableProductSamples($samples);
         }
         $product->setExtensionAttributes($extension);
         if ($product->getLinksPurchasedSeparately()) {
             $product->setTypeHasRequiredOptions(true)->setRequiredOptions(true);
         } else {
             $product->setTypeHasRequiredOptions(false)->setRequiredOptions(false);
         }
     }
     return $product;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:97,代码来源:Downloadable.php


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