I need to get the product ID for product that have an attribute with a certain value.
Here's what I have so far:
$found = false;
foreach ($_productCollection as $_product) {
$attribute = $_product->getResource()->getAttribute('attribute');
$id = $_product->getId();
if ($attribute = NULL) {
// Do Nothing
}
if ($attribute = "value1") {
echo $attribute . "<br>";
$value1 = $id;
}
if ($attribute = "value2") {
echo $attribute . "<br>";
$value2 = $id;
}
if ($attribute = "value3") {
echo $attribute . "<br>";
$value3 = $id;
}
if ($value1 && $value2 && $value3) {
$found = true;
echo "All IDs Found" ."<br>";
}
if ($found = true) {
break;
}
}
echo "Value 1 ID = " . $value1 ."<br>". "Value 2 ID = " . $value2 ."<br>". "Value 3 ID = " . $value3;
This mostly work, it loops through the products correctly, and can get the attribute values for each product. But it is showing the ID for the first product in the category, for every product regardless of what attribute they have.
Like this:
value1
value2
value3
All IDs Found
Value 1 ID = 17024
Value 2 ID = 17024 (should be 17025)
Value 3 ID = 17024 (should be 17026)
How can I get it so that if there is a product in the category with the attribute, and one of the specific values, it will list that products' ID?
Aucun commentaire:
Enregistrer un commentaire