Commit 7ab0ea0b by dhn

详情页Related Products修改推荐大分类商品

parent cbf302ef
...@@ -99,29 +99,15 @@ class Related extends AbstractProduct implements IdentityInterface ...@@ -99,29 +99,15 @@ class Related extends AbstractProduct implements IdentityInterface
{ {
$product = $this->getProduct(); $product = $this->getProduct();
/* @var $product Product */ /* @var $product Product */
$this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect( $this->_itemCollection = $this->_collectionFactory->create();
'required_options' $this->_itemCollection->addAttributeToSelect('*');
)->setPositionOrder()->addStoreFilter(); //$this->_itemCollection->addCategoriesFilter(['in' => $product->getCategoryIds()]);
if ($this->moduleManager->isEnabled('Magento_Checkout')) {
$this->_addProductAttributesAndPrices($this->_itemCollection);
}
$this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds()); $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
$this->_itemCollection->getSelect()->order('rand()');
$this->_itemCollection->load(); $this->_itemCollection->setPageSize(10);
$this->_itemCollection->addStoreFilter($product->getStoreId());
if (!count($this->_itemCollection->getItems())){ $this->_itemCollection->getSelect()->limit(10);
$collection = $this->_collectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['in' => $product->getCategoryIds()]);
$collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
$collection->getSelect()->order('rand()');
$collection->setPageSize(10);
$collection->addStoreFilter($product->getStoreId());
$this->_itemCollection = $collection;
}
foreach ($this->_itemCollection as $product) { foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true); $product->setDoNotUseCategoryId(true);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment