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


PHP Data\ProductInterface类代码示例

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


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

示例1: setUp

 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->locatorMock = $this->getMockBuilder(LocatorInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getTypeId'])->getMockForAbstractClass();
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->productMock->expects($this->any())->method('getTypeId')->willReturn(GroupedProductType::TYPE_CODE);
     $this->linkedProductMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getName', 'getPrice'])->getMockForAbstractClass();
     $this->linkedProductMock->expects($this->any())->method('getId')->willReturn(self::LINKED_PRODUCT_ID);
     $this->linkedProductMock->expects($this->any())->method('getName')->willReturn(self::LINKED_PRODUCT_NAME);
     $this->linkedProductMock->expects($this->any())->method('getPrice')->willReturn(self::LINKED_PRODUCT_PRICE);
     $this->linkMock = $this->getMockBuilder(ProductLinkInterface::class)->setMethods(['getLinkType', 'getLinkedProductSku', 'getPosition', 'getExtensionAttributes'])->getMockForAbstractClass();
     $this->linkExtensionMock = $this->getMockBuilder(ProductLinkExtensionInterface::class)->setMethods(['getQty'])->getMockForAbstractClass();
     $this->linkExtensionMock->expects($this->any())->method('getQty')->willReturn(self::LINKED_PRODUCT_QTY);
     $this->linkMock->expects($this->any())->method('getExtensionAttributes')->willReturn($this->linkExtensionMock);
     $this->linkMock->expects($this->any())->method('getPosition')->willReturn(self::LINKED_PRODUCT_POSITION);
     $this->linkMock->expects($this->any())->method('getLinkedProductSku')->willReturn(self::LINKED_PRODUCT_SKU);
     $this->linkMock->expects($this->any())->method('getLinkType')->willReturn(Grouped::LINK_TYPE);
     $this->linkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->setMethods(['getList'])->getMockForAbstractClass();
     $this->linkRepositoryMock->expects($this->any())->method('getList')->with($this->productMock)->willReturn([$this->linkMock]);
     $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->any())->method('get')->with(self::LINKED_PRODUCT_SKU)->willReturn($this->linkedProductMock);
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:GroupedTest.php

示例2: getLinkedProducts

 /**
  * Get linked to configurable simple products
  *
  * @param ProductInterface $product
  * @return int[]
  */
 private function getLinkedProducts(ProductInterface $product)
 {
     /** @var Configurable $typeInstance */
     $typeInstance = $product->getTypeInstance();
     $childrenIds = $typeInstance->getChildrenIds($product->getId());
     if (isset($childrenIds[0])) {
         return $childrenIds[0];
     } else {
         return [];
     }
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:ReadHandler.php

示例3: addProductFilter

 /**
  * Add Product Filter to Collection
  *
  * @param int|array|ProductInterface $product
  * @return $this
  */
 public function addProductFilter($product)
 {
     $id = -1;
     if ($product instanceof ProductInterface) {
         $id = $product->getId();
     } else {
         if (is_numeric($product)) {
             $id = $product;
         }
     }
     $this->addFieldToFilter('product', $id);
     return $this;
 }
开发者ID:TUDOCK,项目名称:tudockblog-magento2-example,代码行数:19,代码来源:Collection.php

示例4: getGalleryImages

 /**
  * Retrieve collection of gallery images
  *
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @return \Magento\Catalog\Model\Product\Image[]|null
  */
 public function getGalleryImages(\Magento\Catalog\Api\Data\ProductInterface $product)
 {
     $images = $product->getMediaGalleryImages();
     if ($images instanceof \Magento\Framework\Data\Collection) {
         foreach ($images as $image) {
             /** @var $image \Magento\Catalog\Model\Product\Image */
             $image->setData('small_image_url', $this->imageHelper->init($product, 'product_page_image_small')->setImageFile($image->getFile())->getUrl());
             $image->setData('medium_image_url', $this->imageHelper->init($product, 'product_page_image_medium')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($image->getFile())->getUrl());
             $image->setData('large_image_url', $this->imageHelper->init($product, 'product_page_image_large')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($image->getFile())->getUrl());
         }
     }
     return $images;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:19,代码来源:Data.php

示例5: 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

示例6: create

 /**
  * Populate product with variation of attributes
  *
  * @param \Magento\Catalog\Api\Data\ProductInterface $product
  * @param array $attributes
  * @return \Magento\Catalog\Api\Data\ProductInterface[]
  */
 public function create(\Magento\Catalog\Api\Data\ProductInterface $product, $attributes)
 {
     $variations = $this->variationMatrix->getVariations($attributes);
     $products = [];
     foreach ($variations as $variation) {
         $price = $product->getPrice();
         /** @var \Magento\Catalog\Model\Product $item */
         $item = $this->productFactory->create();
         $item->setData($product->getData());
         $suffix = '';
         foreach ($variation as $attributeId => $valueInfo) {
             $suffix .= '-' . $valueInfo['value'];
             $customAttribute = $this->customAttributeFactory->create()->setAttributeCode($attributes[$attributeId]['attribute_code'])->setValue($valueInfo['value']);
             $customAttributes = array_merge($item->getCustomAttributes(), [$attributes[$attributeId]['attribute_code'] => $customAttribute]);
             $item->setData('custom_attributes', $customAttributes);
             $priceInfo = $valueInfo['price'];
             $price += (!empty($priceInfo['is_percent']) ? $product->getPrice() / 100.0 : 1.0) * $priceInfo['pricing_value'];
         }
         $item->setPrice($price);
         $item->setName($product->getName() . $suffix);
         $item->setSku($product->getSku() . $suffix);
         $item->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
         $products[] = $item;
     }
     return $products;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:33,代码来源:ProductVariationsBuilder.php

示例7: load

 /**
  * @param ProductInterface $product
  * @return OptionInterface[]
  */
 public function load(ProductInterface $product)
 {
     $options = [];
     /** @var Configurable $typeInstance */
     $typeInstance = $product->getTypeInstance();
     $attributeCollection = $typeInstance->getConfigurableAttributeCollection($product);
     $this->extensionAttributesJoinProcessor->process($attributeCollection);
     foreach ($attributeCollection as $attribute) {
         $values = [];
         $attributeOptions = $attribute->getOptions();
         if (is_array($attributeOptions)) {
             foreach ($attributeOptions as $option) {
                 /** @var \Magento\ConfigurableProduct\Api\Data\OptionValueInterface $value */
                 $value = $this->optionValueFactory->create();
                 $value->setValueIndex($option['value_index']);
                 $values[] = $value;
             }
         }
         $attribute->setValues($values);
         $options[] = $attribute;
     }
     return $options;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:27,代码来源:Loader.php

示例8: getWebsites

 /**
  * Retrieve websites
  *
  * @param ProductInterface $product
  * @param EavAttribute $eavAttribute
  * @return array
  */
 public function getWebsites(ProductInterface $product, EavAttribute $eavAttribute)
 {
     if (null !== $this->websites) {
         return $this->websites;
     }
     $websites = [['value' => 0, 'label' => $this->formatLabel(__('All Websites'), $this->directoryHelper->getBaseCurrencyCode())]];
     if ($this->storeManager->hasSingleStore() || $eavAttribute->getEntityAttribute() && $eavAttribute->getEntityAttribute()->isScopeGlobal()) {
         return $this->websites = $websites;
     }
     if ($storeId = $this->locator->getStore()->getId()) {
         /** @var WebsiteInterface $website */
         $website = $this->storeManager->getStore($storeId)->getWebsite();
         $websites[$website->getId()] = ['value' => $website->getId(), 'label' => $this->formatLabel($website->getName(), $website->getConfig(Currency::XML_PATH_CURRENCY_BASE))];
     } else {
         /** @var WebsiteInterface $website */
         foreach ($this->storeManager->getWebsites() as $website) {
             if (!in_array($website->getId(), $product->getWebsiteIds())) {
                 continue;
             }
             $websites[$website->getId()] = ['value' => $website->getId(), 'label' => $this->formatLabel($website->getName(), $website->getConfig(Currency::XML_PATH_CURRENCY_BASE))];
         }
     }
     return $this->websites = $websites;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:31,代码来源:Website.php

示例9: getProducts

 /**
  * {@inheritdoc}
  */
 public function getProducts(ProductInterface $product)
 {
     if (!isset($this->products[$product->getId()])) {
         if ($this->requestSafety->isSafeMethod()) {
             $productIds = $this->resource->getConnection()->fetchCol('(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')');
             $this->products[$product->getId()] = $this->collectionFactory->create()->addAttributeToSelect(['price', 'special_price'])->addIdFilter($productIds);
         } else {
             $this->products[$product->getId()] = $this->configurable->getUsedProducts($product);
         }
     }
     return $this->products[$product->getId()];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:ConfigurableOptionsProvider.php

示例10: testAroundSave

 public function testAroundSave()
 {
     $productId = 5494;
     $websiteId = 1;
     $storeId = 2;
     $sku = 'my product that needs saving';
     $this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtensionMock);
     $this->productExtensionMock->expects($this->once())->method('getStockItem')->willReturn($this->stockItemMock);
     $storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
     $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);
     $this->savedProductMock->expects($this->once())->method('getId')->willReturn($productId);
     $this->savedProductMock->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $this->savedProductMock->expects($this->atLeastOnce())->method('getSku')->willReturn($sku);
     $this->stockItemMock->expects($this->once())->method('setProductId')->with($productId);
     $this->stockItemMock->expects($this->once())->method('setWebsiteId')->with($websiteId);
     $this->stockRegistry->expects($this->once())->method('updateStockItemBySku')->with($sku, $this->stockItemMock);
     $newProductMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->disableOriginalConstructor()->getMock();
     $this->productRepositoryMock->expects($this->once())->method('get')->with($sku, false, $storeId, true)->willReturn($newProductMock);
     $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:AroundProductRepositorySaveTest.php

示例11: 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:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:33,代码来源:Configurable.php

示例12: testModifyMeta

 /**
  * @return void
  */
 public function testModifyMeta()
 {
     $this->locatorMock->expects($this->exactly(2))->method('getProduct')->willReturn($this->productMock);
     $this->productMock->expects($this->any())->method('getTypeId');
     $this->arrayManagerMock->expects($this->exactly(3))->method('set')->willReturn([]);
     $this->assertEquals([], $this->downloadablePanel->modifyMeta([]));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:DownloadablePanelTest.php

示例13: testAfterLoadWithExistingExtensionAttributes

 public function testAfterLoadWithExistingExtensionAttributes()
 {
     // test when extension attributes already exist
     $this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtensionMock);
     $this->productExtensionFactoryMock->expects($this->never())->method('create');
     $this->assertEquals($this->productMock, $this->plugin->afterLoad($this->productMock));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:7,代码来源:AfterProductLoadTest.php

示例14: getGalleryAttributeBackend

 /**
  * Retrieve backend model of product media gallery attribute
  *
  * @param Product $product
  * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
  * @throws StateException
  */
 protected function getGalleryAttributeBackend(Product $product)
 {
     $galleryAttributeBackend = $product->getGalleryAttributeBackend();
     if ($galleryAttributeBackend == null) {
         throw new StateException(__('Requested product does not support images.'));
     }
     return $galleryAttributeBackend;
 }
开发者ID:nja78,项目名称:magento2,代码行数:15,代码来源:GalleryManagement.php

示例15: testDisallowModifyMeta

 public function testDisallowModifyMeta()
 {
     $meta = ['some meta'];
     $modifiers = ['modifier1', 'modifier2'];
     $this->productMock->expects(static::any())->method('getTypeId')->willReturn(ConfigurableType::TYPE_CODE);
     $this->allowedProductTypesMock->expects(static::once())->method('isAllowedProductType')->with($this->productMock)->willReturn(false);
     $this->objectManagerMock->expects(static::never())->method('get');
     $this->assertSame($meta, $this->createCompositeModifier($modifiers)->modifyMeta($meta));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:9,代码来源:CompositeTest.php


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