0

Tried filtering with option_id and value_id but it is looking for value and when I change it to catalog_product_entity_int.value_id or at_manufacturer.value_id it returns syntax error.

Trying to filter with code

$productcollection = $this->collectionFactory->create()->addAttributeToSelect('manufacturer')->addFieldToFilter('something here',['eq'=>'value id or option_id here']);

https://i.stack.imgur.com/A6C7O.png

query looks like that when debugging

SELECT `e`.*, `at_manufacturer`.`value` AS `manufacturer` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_entity_int` AS `at_manufacturer` ON (`at_manufacturer`.`entity_id` = `e`.`entity_id`) AND (`at_manufacturer`.`attribute_id` = '81') AND (`at_manufacturer`.`store_id` = 0) WHERE (at_manufacturer.value = 'LG')

How to filter that properly?

2
  • What is the error message? Apr 14, 2020 at 0:49
  • when I use manufacturer as a first argument it's not filtering right. when I use main_table.value_id it returns syntax error. Apr 14, 2020 at 7:22

1 Answer 1

1

Instead of LG, you should provide it's id. I am not sure how you are using this collection but you should be able to do this if you know your manufacturer option id:

//collectionFactory = \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
$productcollection = $this->collectionFactory->create()
   ->addAttributeToSelect('manufacturer')
   ->addFieldToFilter('manufacturer',['eq'=>'21']); //value

This create sql like this:

SELECT `e`.*, `at_manufacturer`.`value` AS `manufacturer` FROM `catalog_product_entity` AS `e`
   LEFT JOIN `catalog_product_entity_int` AS `at_manufacturer` ON (`at_manufacturer`.`row_id` = `e`.`row_id`) AND (`at_manufacturer`.`attribute_id` = '81') AND (`at_manufacturer`.`store_id` = 0) WHERE ((at_manufacturer.value = '21')) AND (e.created_in <= 1) AND (e.updated_in > 1)

Hope this helps.

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.