本文整理汇总了PHP中Magento\Catalog\Api\Data\ProductInterface::getTypeId方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getTypeId方法的具体用法?PHP ProductInterface::getTypeId怎么用?PHP ProductInterface::getTypeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Api\Data\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::getTypeId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: addChild
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function addChild(\Magento\Catalog\Api\Data\ProductInterface $product, $optionId, \Magento\Bundle\Api\Data\LinkInterface $linkedProduct)
{
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
throw new InputException(__('Product with specified sku: "%1" is not a bundle product', $product->getSku()));
}
$options = $this->optionCollection->create();
$options->setProductIdFilter($product->getId())->joinValues($this->storeManager->getStore()->getId());
$isNewOption = true;
/** @var \Magento\Bundle\Model\Option $option */
foreach ($options as $option) {
if ($option->getOptionId() == $optionId) {
$isNewOption = false;
break;
}
}
if ($isNewOption) {
throw new InputException(__('Product with specified sku: "%1" does not contain option: "%2"', [$product->getSku(), $optionId]));
}
/* @var $resource \Magento\Bundle\Model\Resource\Bundle */
$resource = $this->bundleFactory->create();
$selections = $resource->getSelectionsData($product->getId());
/** @var \Magento\Catalog\Model\Product $linkProductModel */
$linkProductModel = $this->productRepository->get($linkedProduct->getSku());
if ($linkProductModel->isComposite()) {
throw new InputException(__('Bundle product could not contain another composite product'));
}
if ($selections) {
foreach ($selections as $selection) {
if ($selection['option_id'] == $optionId && $selection['product_id'] == $linkProductModel->getId()) {
throw new CouldNotSaveException(__('Child with specified sku: "%1" already assigned to product: "%2"', [$linkedProduct->getSku(), $product->getSku()]));
}
}
}
$selectionModel = $this->bundleSelection->create();
$selectionModel->setOptionId($optionId)->setPosition($linkedProduct->getPosition())->setSelectionQty($linkedProduct->getQty())->setSelectionPriceType($linkedProduct->getPriceType())->setSelectionPriceValue($linkedProduct->getPrice())->setSelectionCanChangeQty($linkedProduct->getCanChangeQuantity())->setProductId($linkProductModel->getId())->setParentProductId($product->getId())->setIsDefault($linkedProduct->getIsDefault())->setWebsiteId($this->storeManager->getStore()->getWebsiteId());
try {
$selectionModel->save();
} catch (\Exception $e) {
throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e);
}
return $selectionModel->getId();
}
示例5: addChild
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function addChild(\Magento\Catalog\Api\Data\ProductInterface $product, $optionId, \Magento\Bundle\Api\Data\LinkInterface $linkedProduct)
{
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
throw new InputException(__('Product with specified sku: "%1" is not a bundle product', $product->getSku()));
}
$options = $this->optionCollection->create();
$options->setIdFilter($optionId);
$existingOption = $options->getFirstItem();
if (!$existingOption->getId()) {
throw new InputException(__('Product with specified sku: "%1" does not contain option: "%2"', [$product->getSku(), $optionId]));
}
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
$resource = $this->bundleFactory->create();
$selections = $resource->getSelectionsData($product->getData($linkField));
/** @var \Magento\Catalog\Model\Product $linkProductModel */
$linkProductModel = $this->productRepository->get($linkedProduct->getSku());
if ($linkProductModel->isComposite()) {
throw new InputException(__('Bundle product could not contain another composite product'));
}
if ($selections) {
foreach ($selections as $selection) {
if ($selection['option_id'] == $optionId && $selection['product_id'] == $linkProductModel->getEntityId()) {
if (!$product->getCopyFromView()) {
throw new CouldNotSaveException(__('Child with specified sku: "%1" already assigned to product: "%2"', [$linkedProduct->getSku(), $product->getSku()]));
} else {
return $this->bundleSelection->create()->load($linkProductModel->getEntityId());
}
}
}
}
$selectionModel = $this->bundleSelection->create();
$selectionModel = $this->mapProductLinkToSelectionModel($selectionModel, $linkedProduct, $linkProductModel->getEntityId(), $product->getData($linkField));
$selectionModel->setOptionId($optionId);
try {
$selectionModel->save();
$resource->addProductRelation($product->getData($linkField), $linkProductModel->getEntityId());
} catch (\Exception $e) {
throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e);
}
return $selectionModel->getId();
}
示例6: isAllowedProductType
/**
* Check that product type is allowed
*
* @param ProductInterface $product
* @return bool
*/
public function isAllowedProductType(ProductInterface $product)
{
return in_array($product->getTypeId(), $this->allowedProductTypes);
}