Zend certified PHP/Magento developer

Product collection search issue

I got two issues in one I can’t figure it out, any help would be precious.

  • Collection size
  • Product prices

I’m trying to analyse the result of a search by word and order by price request.

To do such a thing I went to : src/vendor/magento/module-catalog-search/Block/Result.php
And added some log like this :

public function getResultCount()
{
    if (!$this->getData('result_count')) {
        $size = $this->_getProductCollection()->getSize();
        var_dump($size);
        var_dump($this->productCollection->getSelect()->__toString());
        die();
        $this->_getQuery()->saveNumResults($size);
        $this->setResultCount($size);
    }
    return $this->getData('result_count');
}

I’m getting

As collection size I’m getting 72; which is the number of product printed in front after; so i’m fine with that…my issue is when I analyze my request.

"SELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, 
IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, 
IFNULL(review_summary.reviews_count, 0) AS `reviews_count`, 
IFNULL(review_summary.rating_summary, 0) AS `rating_summary`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e` 
INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.customer_group_id = 0 AND price_index.website_id = '1' 
INNER JOIN `catalog_product_website` AS `product_website` ON product_website.product_id = e.entity_id AND product_website.website_id = 1 
LEFT JOIN `review_entity_summary` AS `review_summary` ON e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = 1 AND review_summary.entity_type = (SELECT `review_entity`.`entity_id` 
FROM `review_entity` WHERE (entity_code = 'product')) 
INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id 
WHERE (stock_status_index.stock_status = 1) AND (e.entity_id IN (1093, 1094, 2, 23, 86, 30, 93, 1139, 1150, 1156, 1172, 242, 52, 71, 70, 176, 79, 3, 4, 22, 25, 26, 27, 28)) 
ORDER BY price_index.min_price = 0, price_index.min_price ASC "

This request only gets me 24 results matching all the entity_ids listed in the request.

So…how am I going from a request that gives 24 results to a collection size of 72…I’m missing something there.

Also, the issue I’m facing is that the 24 lines are indeed filtered…but the price used for the filter doesn’t match the price I have in my backoffice.

Exemple for the sql result the first line match this :

entity_id,attribute_set_id,type_id,sku,has_options,required_options,created_at,updated_at,price,tax_class_id,final_price,minimal_price,min_price,max_price,tier_price,reviews_count,rating_summary,is_salable

1093,4,simple,3000000000137,0,0,2020-01-24 23:03:21,2021-05-17 15:43:05,2.333333,,2.333333,2.333333,2.333333,2.333333,,0,0,1

In bo the price isn’t the same there :

price bo