本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}