I'm trying to filter my product collection by tier price.
I currently have this code but it doesn't work and it returns error:
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 getProductCollectionTot()
{
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$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('price_index.Tier_price < price_index.price');
return $collection;
}
How can I filter my collection by tier price?