本文整理汇总了PHP中Magento\Catalog\Model\Product::setExtensionAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::setExtensionAttributes方法的具体用法?PHP Product::setExtensionAttributes怎么用?PHP Product::setExtensionAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::setExtensionAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: setExtensionAttributes
/**
* {@inheritdoc}
*/
public function setExtensionAttributes(\Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'setExtensionAttributes');
if (!$pluginInfo) {
return parent::setExtensionAttributes($extensionAttributes);
} else {
return $this->___callPlugins('setExtensionAttributes', func_get_args(), $pluginInfo);
}
}
示例5: 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;
}