You have added a new attribute origin of the type varchar to the product entity.
Which two calls will filter a product collection with origin set to "California"? (Choose two.)
A. $collection->addFieldToFilter(‘origin’, "California");
B. $collection->addAttributeToSelect(‘origin’, "California");
C. $collection->joinAttribute(‘origin’, ‘catalog_product/origin’, ‘origin’, ‘California");
D. $collection->addAttributeToFilter(‘origin’, "California");
Answer:- A, D
Regarding the answer B “California” is a value of attribute not a attribute name so this is wrong
I think B and D are correct answer
https://www.linkedin.com/in/magento-two-developer/
You’re right
B is select
C could be right but there are wrong arguments
A and D are correct since it’s alias
Correct Answer A and D
To confirm Answer = A & D
Question is asking for filters NOT selection here.
addAttributeToFilter is for EAV entities such as products.
Is for addFieldToFilter non-EAV attributes however, when called on EAV collections acts as an alias of addAttributeToFilter
Nice question.
A is wrong because product is EAV entity so it can’t use addFieldToFilter. addFieldToFilter is for flat tables…
B is wrong because it’s select
C is correct. There is such function.
vendor/magento/module-catalog/Block/Adminhtml/Product/Grid.php:180
$collection->joinAttribute(‘status’, ‘catalog_product/status’, ‘entity_id’, null, ‘inner’);
D is correct addAttributeToFilter is for EAV product entities
If you would not add attribute to select, how you would be able to filter that attribute?
So B anad D is right. Also A is similar to D.
The description of joinAttribute method in AbstractCollection class says: “Add attribute from joined entity to select”
How can this be used as a filter?
I think BD is correct
https://magento.stackexchange.com/questions/164252/magento-2-product-collection-with-filters
Yeah I agree with you. It is attribute to select and then filter
Ive looked at this one again and $collection->addAttributeToSelect(‘origin’, “California”); Cant take the 2nd argument it should be $collection->addAttributeToSelect(‘origin’);
I agree has to be filter not select so A and D
It seems that correct answers are A & D. Option B can’t be correct answer.