2

In my project trying to pull product from selected category which have a specific attribute value.

$currentCategory = Mage::getModel('catalog/layer')->getCurrentCategory();

$products = Mage::getModel('catalog/product')
    ->getCollection()
    //->addFieldToFilter(???????) //category id ????
    ->addAttributeToSelect('name','price','special_price')
    ->addAttributeToSelect('showme',array('eq' => 'Yes'))
    ->load();

or within whole categories tree (I mean category and its childrens)

I stuck and don't really have an idea.

How to achieve it ?

Then check if there is more than one then pick the first one and "show".

EDIT:

I just forgotten to add: two parameters must be checked, "if showme and category" then show :)

1 Answer 1

2

If your showme attribute is a yes/no attribute then you need to call the following:

->addAttributeToFilter('showme', 1);

The problem in your case is that you're calling addAttributeToSelect which will not let you filter the results.

If you need to filter by category you can call

->addCategoryFilter($category);

where $category is an instance of Mage_Catalog_Model_Category that corresponds to the category to filter.

2
  • Thank you Raph, it works even as it is but .... I would like to add filter by category so it should display products within current category and with "showme" = 1
    – Rob D. A.
    Apr 20, 2017 at 15:02
  • @RobertA. see my edited answer Apr 20, 2017 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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