本文整理汇总了PHP中Magento\Catalog\Model\Product::unsetData方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::unsetData方法的具体用法?PHP Product::unsetData怎么用?PHP Product::unsetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::unsetData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSelectionFinalPrice
/**
* Obtain final price of selection in a bundle product
*
* @param ItemInterface $item
* @param \Magento\Catalog\Model\Product $selectionProduct
* @return float
*/
public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Model\Product $selectionProduct)
{
$selectionProduct->unsetData('final_price');
$product = $item->getProduct();
/** @var \Magento\Bundle\Model\Product\Price $price */
$price = $product->getPriceModel();
return $price->getSelectionFinalTotalPrice($product, $selectionProduct, $item->getQty(), $this->getSelectionQty($product, $selectionProduct->getSelectionId()), false, true);
}
示例2: beforeSave
/**
* Prepare inventory data from custom attribute
*
* @param Product $object
* @return void
*/
public function beforeSave($object)
{
$stockData = $object->getData($this->getAttribute()->getAttributeCode());
if (isset($stockData['qty']) && $stockData['qty'] === '') {
$stockData['qty'] = null;
}
if ($object->getStockData() !== null || $stockData !== null) {
$object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData));
}
$object->unsetData($this->getAttribute()->getAttributeCode());
parent::beforeSave($object);
}
示例3: beforeInitializeLinks
/**
* Initialize grouped product links
*
* @param \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $subject
* @param \Magento\Catalog\Model\Product $product
* @param array $links
*
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function beforeInitializeLinks(\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $subject, \Magento\Catalog\Model\Product $product, array $links)
{
if ($product->getTypeId() == TypeGrouped::TYPE_CODE && !$product->getGroupedReadonly()) {
$links = isset($links[self::TYPE_NAME]) ? $links[self::TYPE_NAME] : $product->getGroupedLinkData();
if ($product->getGroupedLinkData()) {
$links = array_merge($links, $product->getGroupedLinkData());
}
$newLinks = [];
$existingLinks = $product->getProductLinks();
$product->unsetData('_cache_instance_associated_products');
if ($links) {
foreach ($links as $linkId => $linkRaw) {
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
$productLink = $this->productLinkFactory->create();
if (isset($linkRaw['id'])) {
$productId = $linkRaw['id'];
} else {
$productId = $linkId;
}
$linkedProduct = $this->productRepository->getById($productId);
$productLink->setSku($product->getSku())->setLinkType(self::TYPE_NAME)->setLinkedProductSku($linkedProduct->getSku())->setLinkedProductType($linkedProduct->getTypeId())->setPosition($linkRaw['position'])->getExtensionAttributes()->setQty($linkRaw['qty']);
if (isset($linkRaw['custom_attributes'])) {
$productLinkExtension = $productLink->getExtensionAttributes();
if ($productLinkExtension === null) {
$productLinkExtension = $this->productLinkExtensionFactory->create();
}
foreach ($linkRaw['custom_attributes'] as $option) {
$name = $option['attribute_code'];
$value = $option['value'];
$setterName = 'set' . ucfirst($name);
// Check if setter exists
if (method_exists($productLinkExtension, $setterName)) {
call_user_func([$productLinkExtension, $setterName], $value);
}
}
$productLink->setExtensionAttributes($productLinkExtension);
}
$newLinks[] = $productLink;
}
}
$existingLinks = $this->removeUnExistingLinks($existingLinks, $newLinks);
$product->setProductLinks(array_merge($existingLinks, $newLinks));
}
}
示例4: testIsSalable
public function testIsSalable()
{
$this->_product->unsetData('is_salable');
$this->assertTrue($this->_model->isSalable($this->_product));
}
示例5: resetConfigurableAttributes
/**
* Reset the cached configurable attributes of a product
*
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function resetConfigurableAttributes($product)
{
$product->unsetData($this->_configurableAttributes);
return $this;
}
示例6: dropRelationProductsCache
/**
* @param \Magento\Catalog\Model\Product $product
* @return void
*/
private function dropRelationProductsCache(\Magento\Catalog\Model\Product $product)
{
$product->unsetData('up_sell_products');
$product->unsetData('up_sell_products_ids');
$product->unsetData('related_products');
$product->unsetData('related_products_ids');
$product->unsetData('cross_sell_products');
$product->unsetData('cross_sell_products_ids');
}
示例7: unsetData
/**
* {@inheritdoc}
*/
public function unsetData($key = null)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'unsetData');
if (!$pluginInfo) {
return parent::unsetData($key);
} else {
return $this->___callPlugins('unsetData', func_get_args(), $pluginInfo);
}
}
示例8: resetConfigurableAttributes
/**
* Reset the cached configurable attributes of a product
*
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function resetConfigurableAttributes($product)
{
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
$productId = $product->getData($metadata->getLinkField());
$product->unsetData($this->_configurableAttributes);
$cacheId = __CLASS__ . $productId . '_' . $product->getStoreId();
$this->getCache()->remove($cacheId);
$this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [self::TYPE_CODE . '_' . $productId]);
return $this;
}