Tuesday, 15 March 2011

php - Magento If product has attribute, get it's ID -


I need to get a product ID for the product, which is a specialty with a specific value.

What I've done so far:

  $ found = false; Forex Currency ($ _productCollection $ _product) {$ attribute = $ _product- & gt; GetResource () - & gt; GetAttribute ('attribute'); $ Id = $ _product- & gt; GetId (); If ($ attribute = NULL) {// Do Nothing} if ($ attribute = "value1") {echo $ attribute "& lt; br>"; $ Value1 = $ id; } If ($ attribute = "value2") {echo $ attribute "& lt; br>"; $ Value2 = $ id; } If ($ attribute = "value3") {echo $ attribute "& lt; br>"; $ Value3 = $ id; } If ($ value1 & amp; $ value2 & amp; $ value3) {$ found = true; "All id found" echo "& Lt; br & gt;"; } If ($ mil = true) {break; }} Echo "value 1 id =" $ value1. "& Lt; br & gt;" "Value 2 ID =" $ Value2. "& Lt; br & gt;" "Value 3 id =" $ value3;  

It mostly works, it is fine through products, and it can achieve attribute values ​​for each product. But it is showing the ID for the first product in the category for each product, even if they have a feature.

value3 all id value value 1 id = 17024 value 2 id = 17024 (should be 17025) value 3 id = 17024 (must be 17026) < P> How can I get it that if there is a product in the category with attribute, and one of the specific values, then it will list the product ID?

Edit:

Using the ==, part of my problem has been fixed.

The other problem was that:

  $ _products-> getResource () - & gt; GetAttribute ('attribute');  

The attribute is not found in the way that allows me to use its values. Instead of using it:

  $ _product-> getAttributeText ('attribute');  

and set the attribute in the 'Use in Product List'. If this statement is used for each value, then every time I am specifying the value.

  if ($ attribute = "value1") {< Code> 

Use twice to compare:

  if ($ attribute = = "Value1") { 

No comments:

Post a Comment