Commit 7ab0ea0b by dhn

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

parent cbf302ef
......@@ -100,28 +100,14 @@ class Related extends AbstractProduct implements IdentityInterface
$product = $this->getProduct();
/* @var $product Product */
$this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect(
'required_options'
)->setPositionOrder()->addStoreFilter();
if ($this->moduleManager->isEnabled('Magento_Checkout')) {
$this->_addProductAttributesAndPrices($this->_itemCollection);
}
$this->_itemCollection = $this->_collectionFactory->create();
$this->_itemCollection->addAttributeToSelect('*');
//$this->_itemCollection->addCategoriesFilter(['in' => $product->getCategoryIds()]);
$this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
$this->_itemCollection->load();
if (!count($this->_itemCollection->getItems())){
$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;
}
$this->_itemCollection->getSelect()->order('rand()');
$this->_itemCollection->setPageSize(10);
$this->_itemCollection->addStoreFilter($product->getStoreId());
$this->_itemCollection->getSelect()->limit(10);
foreach ($this->_itemCollection as $product) {
$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