I'm writing a custom display for certain attributes based on its label. Within the 'configurable.phtml' file, it has the following lines:
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
I can loop through the attributes array and check the label no problem:
$special_attr = false;
foreach ($_attributes as $_attribute) {
echo $_attribute->getLabel().'<br>';
if ($_attribute->getLabel() === 'FooBar') {
$special_attr = $_attribute;
}
}
This will print out all of the labels ("Color", "Size", etc.). I'm trying to get a list of all options and their values given this special attribute now, and I'm completely stumped. All of the other questions I have found have said something along the lines of using ->getSource()->getAllOptions(false), however, calling getSource() on this attribute just returns null.
How can I get all options given this special attribute?
if ($special_attr) {
$options = $special_attr->??????
// list all options??
}
-
are you sure the special attribute in your question is a select attribute ?Rajeev K Tomy– Rajeev K Tomy2016年07月18日 04:04:29 +00:00Commented Jul 18, 2016 at 4:04
-
use full links : magento.stackexchange.com/questions/5092/… stackoverflow.com/questions/3994224/…PG Sutariya– PG Sutariya2016年07月18日 04:26:25 +00:00Commented Jul 18, 2016 at 4:26
1 Answer 1
You can try below code to get options of configurable attributes within configurable.phtml
$special_attr = false;
foreach ($_attributes as $_attribute) {
echo $_attribute->getLabel().'<br>';
if ($_attribute->getLabel() === 'FooBar') {
$special_attr = $_attribute->getPrices();
}
}
As you can see, the trick lies in $_attribute->getPrices(). This will give you an output like this for color attribute (if that is configurable)
Array
(
[0] => Array
(
[product_super_attribute_id] => 13
[value_index] => 183
[label] => Brown
[default_label] => Brown
[store_label] => Brown
[is_percent] => 0
[pricing_value] => 10.0000
[use_default_value] => 1
[value_id] => 15
)
[1] => Array
(
[product_super_attribute_id] => 13
[value_index] => 174
[label] => Orange
[default_label] => Orange
[store_label] => Orange
[is_percent] => 0
[pricing_value] => 20.0000
[use_default_value] => 1
[value_id] => 16
)
)
I believe this will be enough in your case.
-
Yes, this is perfect. I wish this info was under something less misleading than "getPrices" though. Thanks!Steven Jeffries– Steven Jeffries2016年07月18日 21:49:39 +00:00Commented Jul 18, 2016 at 21:49
-
@StevenJeffries In fact, yes it is a misleading terminology. But on another hand, it is logical too. Because each option of a configurable product determine the actual price of configurable productRajeev K Tomy– Rajeev K Tomy2016年07月19日 04:29:37 +00:00Commented Jul 19, 2016 at 4:29
Explore related questions
See similar questions with these tags.