In my block code I am trying to programmatically retrieve a list of products that have a attribute with a specific value.
Alternately if that is not possible how would one retrieve all products then filter them to just list the products with a specific attribute?
How would I perform a search using standard boolean filters AND
or OR
to match a subset of my products?
I have added line
in
in function
_getProductCollection()
and then call it in
By writing code
Now it is working in Magento 1.4.x
To Get
TEXT
attributes added from admin to front end on product listing page.Thanks Anita Mourya
I have found there is two methods. Let say product attribute called "na_author" is added from backend as text field.
METHOD 1
on
list.phtml
FOR EACH PRODUCT LOAD BY SKU AND GET ATTRIBUTE INSIDE FOREACH
METHOD 2
Mage/Catalog/Block/Product/List.phtml
OVER RIDE and set in 'local folder'i.e. Copy From
and PASTE TO
change the function by adding 2 lines shown in bold below.
and you will be happy to see it....!!
create attribute name is "
price_screen_tab_name
". and access using this simple formula.This is a follow up to my original question to help out others with the same problem. If you need to filter by an attribute, rather than manually looking up the id you can use the following code to retrieve all the id, value pairs for an attribute. The data is returned as an array with the attribute name as the key.
Here is a function you can use to get products by their attribute set id. Retrieved using the previous function.
Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model.
To instantiate a Product collection, do the following
Products are a Magento EAV style Model, so you'll need to add on any additional attributes that you want to return.
There's multiple syntaxes for setting filters on collections. I always use the verbose one below, but you might want to inspect the Magento source for additional ways the filtering methods can be used.
The following shows how to filter by a range of values (greater than AND less than)
While this will filter by a name that equals one thing OR another.
A full list of the supported short conditionals (eq,lt, etc.) can be found in the
_getConditionSql
method inlib/Varien/Data/Collection/Db.php
Finally, all Magento collections may be iterated over (the base collection class implements on of the the iterator interfaces). This is how you'll grab your products once filters are set.