I need to override
protected function _productLimitationPrice($joinLeft = false)
in magento 2 which is located at
public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.php
How can i override method in product collection.
class Collection extends
\Magento\Catalog\Model\ResourceModel\Product\Collection
{
protected function _productLimitationPrice($joinLeft = false)
{
$filters = $this->_productLimitationFilters;
if (!$filters->isUsingPriceIndex() ||
!isset($filters['website_id']) ||
(string)$filters['website_id'] === '' ||
!isset($filters['customer_group_id']) ||
(string)$filters['customer_group_id'] === ''
) {
return $this;
}
// Preventing overriding price loaded from EAV because we want to use the one from index
$this->removeAttributeToSelect('price');
$connection = $this->getConnection();
$select = $this->getSelect();
$joinCond = join(
' AND ',
[
'price_index.entity_id = e.entity_id',
$connection->quoteInto('price_index.website_id = ?', $filters['website_id']),
$connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])
]
);
$fromPart = $select->getPart(\Magento\Framework\DB\Select::FROM);
if (!isset($fromPart['price_index'])) {
$least = $connection->getLeastSql(['price_index.min_price', 'price_index.tier_price']);
$minimalExpr = $connection->getCheckSql(
'price_index.tier_price IS NOT NULL',
$least,
'price_index.min_price'
);
$colls = [
'price',
'tax_class_id',
'final_price',
'minimal_price' => $minimalExpr,
'min_price',
'max_price',
'tier_price',
];
$tableName = [
'price_index' => $this->priceTableResolver->resolve(
'catalog_product_index_price',
[
$this->dimensionFactory->create(
CustomerGroupDimensionProvider::DIMENSION_NAME,
(string)$filters['customer_group_id']
),
$this->dimensionFactory->create(
WebsiteDimensionProvider::DIMENSION_NAME,
(string)$filters['website_id']
)
]
)
];
if ($joinLeft) {
$select->joinLeft($tableName, $joinCond, $colls);
} else {
$select->joinLeft($tableName, $joinCond, $colls);
}
// Set additional field filters
foreach ($this->_priceDataFieldFilters as $filterData) {
$select->where(call_user_func_array('sprintf', $filterData));
}
} else {
$fromPart['price_index']['joinCondition'] = $joinCond;
$select->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
}
//Clean duplicated fields
$this->_resourceHelper->prepareColumnsList($select);
return $this;
}