Commit 914312cd by lmf

可能感兴趣的产品系统自动推荐

parent 32d4d3cd
......@@ -117,7 +117,7 @@ class Related extends AbstractProduct implements IdentityInterface
$collection->addCategoriesFilter(['in' => $product->getCategoryIds()]);
$collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
$collection->getSelect()->order('rand()');
$collection->setPageSize(6);
$collection->setPageSize(10);
$collection->addStoreFilter($product->getStoreId());
$this->_itemCollection = $collection;
}
......
......@@ -16,6 +16,7 @@ use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\DataObject;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Module\Manager;
use Magento\Reports\Model\ResourceModel\Product\CollectionFactory;
/**
* Catalog product upsell items block
......@@ -27,6 +28,11 @@ use Magento\Framework\Module\Manager;
class Upsell extends AbstractProduct implements IdentityInterface
{
/**
* @var Collection
*/
protected $_collectionFactory;
/**
* @var int
*/
protected $_columnCount = 4;
......@@ -86,8 +92,10 @@ class Upsell extends AbstractProduct implements IdentityInterface
ProductVisibility $catalogProductVisibility,
CheckoutSession $checkoutSession,
Manager $moduleManager,
CollectionFactory $collectionFactory,
array $data = []
) {
$this->_collectionFactory = $collectionFactory;
$this->_checkoutCart = $checkoutCart;
$this->_catalogProductVisibility = $catalogProductVisibility;
$this->_checkoutSession = $checkoutSession;
......@@ -120,6 +128,18 @@ class Upsell extends AbstractProduct implements IdentityInterface
['product' => $product, 'collection' => $this->_itemCollection, 'limit' => null]
);
if (!count($this->_itemCollection->getItems())){
$collection = $this->_collectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['not 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) {
$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