本文整理汇总了PHP中Magento\Catalog\Api\Data\ProductInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface类的具体用法?PHP ProductInterface怎么用?PHP ProductInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProductInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: saveRelatedProducts
/**
* Save related products
*
* @param ProductInterface $product
* @return void
* @deprecated
*/
private function saveRelatedProducts(ProductInterface $product)
{
$productIds = $product->getAssociatedProductIds();
if (is_array($productIds)) {
$this->typeConfigurableFactory->create()->saveProducts($product, $productIds);
}
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:14,代码来源:Configurable.php
示例13: delete
/**
* {@inheritdoc}
*/
public function delete(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$sku = $product->getSku();
$productId = $product->getId();
try {
$this->resourceModel->delete($product);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\StateException(__('Unable to remove product %1', $sku));
}
unset($this->instances[$sku]);
unset($this->instancesById[$productId]);
return true;
}
开发者ID:nblair,项目名称:magescotch,代码行数:16,代码来源:ProductRepository.php
示例14: getOptions
/**
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return \Magento\Bundle\Api\Data\OptionTypeInterface[]
*/
private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product)
{
/** @var \Magento\Bundle\Model\Product\Type $productTypeInstance */
$productTypeInstance = $product->getTypeInstance();
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
$optionCollection = $productTypeInstance->getOptionsCollection($product);
$selectionCollection = $productTypeInstance->getSelectionsCollection($productTypeInstance->getOptionsIds($product), $product);
$options = $optionCollection->appendSelections($selectionCollection);
return $options;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:LinkManagement.php
示例15: updateLink
/**
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param LinkInterface $link
* @param bool $isGlobalScopeContent
* @return mixed
* @throws InputException
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function updateLink(\Magento\Catalog\Api\Data\ProductInterface $product, LinkInterface $link, $isGlobalScopeContent)
{
/** @var $existingLink \Magento\Downloadable\Model\Link */
$existingLink = $this->linkFactory->create()->load($link->getId());
if (!$existingLink->getId()) {
throw new NoSuchEntityException(__('There is no downloadable link with provided ID.'));
}
if ($existingLink->getProductId() != $product->getId()) {
throw new InputException(__('Provided downloadable link is not related to given product.'));
}
$validateLinkContent = $link->getLinkFileContent() === null ? false : true;
$validateSampleContent = $link->getSampleFileContent() === null ? false : true;
if (!$this->contentValidator->isValid($link, $validateLinkContent, $validateSampleContent)) {
throw new InputException(__('Provided link information is invalid.'));
}
if ($isGlobalScopeContent) {
$product->setStoreId(0);
}
$title = $link->getTitle();
if (empty($title)) {
if ($isGlobalScopeContent) {
throw new InputException(__('Link title cannot be empty.'));
}
}
if ($link->getLinkType() == 'file' && $link->getLinkFileContent() === null) {
$link->setLinkFile($existingLink->getLinkFile());
}
if ($link->getSampleType() == 'file' && $link->getSampleFileContent() === null) {
$link->setSampleFile($existingLink->getSampleFile());
}
$this->saveLink($product, $link, $isGlobalScopeContent);
return $existingLink->getId();
}
开发者ID:tingyeeh,项目名称:magento2,代码行数:43,代码来源:LinkRepository.php
示例16: validateStockItem
/**
* @param ProductInterface $product
* @param StockItemInterface $stockItem
* @throws LocalizedException
* @return void
*/
private function validateStockItem(ProductInterface $product, StockItemInterface $stockItem)
{
$defaultScopeId = $this->stockConfiguration->getDefaultScopeId();
$defaultStockId = $this->stockRegistry->getStock($defaultScopeId)->getStockId();
$stockId = $stockItem->getStockId();
if ($stockId !== null && $stockId != $defaultStockId) {
throw new LocalizedException(__('Invalid stock id: %1. Only default stock with id %2 allowed', $stockId, $defaultStockId));
}
$stockItemId = $stockItem->getItemId();
if ($stockItemId !== null && (!is_numeric($stockItemId) || $stockItemId <= 0)) {
throw new LocalizedException(__('Invalid stock item id: %1. Should be null or numeric value greater than 0', $stockItemId));
}
$defaultStockItemId = $this->stockRegistry->getStockItem($product->getId())->getItemId();
if ($defaultStockItemId && $stockItemId !== null && $defaultStockItemId != $stockItemId) {
throw new LocalizedException(__('Invalid stock item id: %1. Assigned stock item id is %2', $stockItemId, $defaultStockItemId));
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:23,代码来源:AroundProductRepositorySave.php
示例17: 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;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:31,代码来源:AroundProductRepositorySave.php
示例18: getVariationMatrixFromProduct
/**
* Get variation-matrix from product
*
* @param ProductInterface $product
* @return array
*/
private function getVariationMatrixFromProduct(ProductInterface $product)
{
$result = [];
$configurableMatrix = $product->hasData('configurable-matrix') ? $product->getData('configurable-matrix') : [];
foreach ($configurableMatrix as $item) {
if ($item['newProduct']) {
$result[$item['variationKey']] = $this->mapData($item);
if (isset($item['qty'])) {
$result[$item['variationKey']]['quantity_and_stock_status']['qty'] = $item['qty'];
}
}
}
return $result;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:Configurable.php
示例19: setProduct
/**
* Set the project associated with this text8
* @param \Magento\Catalog\Api\Data\ProductInterface $productInterface
* @return \Tudock\HelloWorld\Api\Data\HelloTextInterface
*/
public function setProduct(\Magento\Catalog\Api\Data\ProductInterface $productInterface)
{
$this->setData('product', $productInterface->getId());
return $this;
}
开发者ID:TUDOCK,项目名称:tudockblog-magento2-example,代码行数:10,代码来源:HelloText.php
示例20: fillData
/**
* Fill data column
*
* @param ProductInterface $linkedProduct
* @param ProductLinkInterface $linkItem
* @return array
*/
protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem)
{
/** @var \Magento\Framework\Currency $currency */
$currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
return ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()];
}
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:Grouped.php
注:本文中的Magento\Catalog\Api\Data\ProductInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论