1

I need the mysql query for the following magento code. Need to get the count of products with the given brand option id.

count($this->productCollectionFactory->create()
                ->addAttributeToSelect('*')
                ->addFieldToFilter('status','1')
                ->addAttributeToFilter('brand','120')
                ->load()->getData());

3 Answers 3

0

Can use echo $collection->getSelect() Example:

$collection = $this->productCollectionFactory->create()
                ->addAttributeToSelect('*')
                ->addFieldToFilter('status','1')
                ->addAttributeToFilter('brand','120')
                ->count();
echo $collection->getSelect();
0
$collection = $this->productCollectionFactory->create()
                ->addAttributeToSelect('*')
                ->addFieldToFilter('status','1')
                ->addAttributeToFilter('brand','120');
echo $collection->count();
0

This helped me to get the query string

  $collection = $this->productCollectionFactory->create()
                ->addAttributeToSelect('*')
                ->addFieldToFilter('status','1')
                ->addAttributeToFilter('brand','120');
            $collection->getSelect()->__toString();

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.