In my class I have filtered my collection by tier price and quantity.
If I put the display of only 3 products the code works, while if I set the display for all products I get this problem:
Item (Magento\Catalog\Model\Product\Interceptor) with the same ID "42" already exists
This is my code
namespace Vendor\Module\Block;
class ProductCollection extends \Magento\Framework\View\Element\Template
{
protected $_productCollectionFactory;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
array $data = []
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}
public function getProductCollectionSearch() {
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->setPageSize(3);
$collection->getSelect()->join('catalog_product_index_price as price_index', 'e.entity_id = price_index.entity_id');
$collection->getSelect()->join('catalog_product_entity_tier_price as tier', 'price_index.entity_id = tier.entity_id');
$collection->addFinalPrice()
->addMinimalPrice()
->getSelect()
->where('tier.all_groups = 0')
->where('tier.qty = 1000')
->where('tier.value <= 0.20');
return $collection;
}
}
Where is the issue?