本文整理匯總了PHP中Magento\Catalog\Model\Product::getLinkInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getLinkInstance方法的具體用法?PHP Product::getLinkInstance怎麽用?PHP Product::getLinkInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::getLinkInstance方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: build
/**
* Build product links
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Product $duplicate
* @return void
*/
public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate)
{
$data = [];
$attributes = [];
$link = $product->getLinkInstance();
$link->useCrossSellLinks();
foreach ($link->getAttributes() as $attribute) {
if (isset($attribute['code'])) {
$attributes[] = $attribute['code'];
}
}
/** @var \Magento\Catalog\Model\Product\Link $link */
foreach ($product->getCrossSellLinkCollection() as $link) {
$data[$link->getLinkedProductId()] = $link->toArray($attributes);
}
$duplicate->setCrossSellLinkData($data);
}
示例2: build
/**
* Build product links
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Product $duplicate
* @return void
*/
public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate)
{
if ($product->getTypeId() !== \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) {
//do nothing if not grouped product
return;
}
$data = [];
$attributes = [];
$link = $product->getLinkInstance();
$link->setLinkTypeId(\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED);
foreach ($link->getAttributes() as $attribute) {
if (isset($attribute['code'])) {
$attributes[] = $attribute['code'];
}
}
/** @var \Magento\Catalog\Model\Product\Link $link */
foreach ($this->_getGroupedLinkCollection($product) as $link) {
$data[$link->getLinkedProductId()] = $link->toArray($attributes);
}
$duplicate->setGroupedLinkData($data);
}
示例3: getAssociatedProductCollection
/**
* Retrieve collection of associated products
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection
*/
public function getAssociatedProductCollection($product)
{
/** @var \Magento\Catalog\Model\Product\Link $links */
$links = $product->getLinkInstance();
$links->setLinkTypeId(\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED);
$collection = $links->getProductCollection()->setFlag('require_stock_items', true)->setFlag('product_children', true)->setIsStrongMode();
$collection->setProduct($product);
return $collection;
}
示例4: testGetLinkInstance
public function testGetLinkInstance()
{
$model = $this->_model->getLinkInstance();
$this->assertInstanceOf('Magento\\Catalog\\Model\\Product\\Link', $model);
$this->assertSame($model, $this->_model->getLinkInstance());
}
示例5: getLinkInstance
/**
* {@inheritdoc}
*/
public function getLinkInstance()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getLinkInstance');
if (!$pluginInfo) {
return parent::getLinkInstance();
} else {
return $this->___callPlugins('getLinkInstance', func_get_args(), $pluginInfo);
}
}