0

I can't find the what query rendes here and i can't it is not readable so any can to find what query renders hear please tell what are the table involved here

 public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter)
    {
        // clone select from collection with filters
        $select = clone $filter->getLayer()->getProductCollection()->getSelect();
        // reset columns, order and limitation conditions
        $select->reset(\Magento\Framework\DB\Select::COLUMNS);
        $select->reset(\Magento\Framework\DB\Select::ORDER);
        $select->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
        $select->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);

        $connection = $this->getConnection();
        $attribute = $filter->getAttributeModel();
        $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
        $conditions = [
            "{$tableAlias}.entity_id = e.entity_id",
            $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()),
            $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()),
        ];

        $select->join(
            [$tableAlias => $this->getMainTable()],
            join(' AND ', $conditions),
            ['value', 'count' => new \Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")]
        )->group(
            "{$tableAlias}.value"
        );

        return $connection->fetchPairs($select);
    }
1
  • Dont worry this is not array when echo this before return. Commented Jun 22, 2020 at 11:11

2 Answers 2

0

Before return you can print this and check which table you want.

  echo $select->__toString();
7
  • How can print if it is array?
    – Sabareesh
    Commented Jun 22, 2020 at 11:08
  • echo used and die; Commented Jun 22, 2020 at 11:09
  • It is not working bro if i put die also it is coming
    – Sabareesh
    Commented Jun 22, 2020 at 11:13
  • If die is not working here so please check its overide. Commented Jun 22, 2020 at 11:14
  • No it is not overrided it is a model file it is only in vendor/*
    – Sabareesh
    Commented Jun 22, 2020 at 11:28
0

instead of dying, you can log the query:

you may use these 3 lines:

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/querytounderstand.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($select->__toString()); // as per Jijay suggestion

Add a log in Magento is talke about here: Magento 2: Replacement for Mage::log method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.