Which two calls will filter a product collection with origin set to "California"?

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");

Download Printable PDF. VALID exam to help you PASS.

12 thoughts on “Which two calls will filter a product collection with origin set to "California"?

  1. Answer:- A, D

    Regarding the answer B “California” is a value of attribute not a attribute name so this is wrong

  2. You’re right

    B is select
    C could be right but there are wrong arguments

    A and D are correct since it’s alias

  3. 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

  4. 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

    1. 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.

    2. The description of joinAttribute method in AbstractCollection class says: “Add attribute from joined entity to select”

      How can this be used as a filter?

      1. Ive looked at this one again and $collection->addAttributeToSelect(‘origin’, “California”); Cant take the 2nd argument it should be $collection->addAttributeToSelect(‘origin’);

        2
        1

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.