Reputation: 119
$i = 1;
foreach ($product->getOptions() as $o) {
$values = $o->getValues();
foreach ($values as $v) {
print_r($v->getData());
}
$i++;
}
The above code outputs the following result:
Array
(
[option_type_id] => 9
[option_id] => 3
[sku] =>
[sort_order] => 0
[default_title] => Black
[store_title] =>
[title] => Black
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
Array
(
[option_type_id] => 7
[option_id] => 3
[sku] =>
[sort_order] => 0
[default_title] => Red
[store_title] =>
[title] => Red
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
Array
(
[option_type_id] => 8
[option_id] => 3
[sku] =>
[sort_order] => 0
[default_title] => White
[store_title] =>
[title] => White
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
I want to output the [title]
value. How do I do that? Thank you. I've tried to use $v->getData()['title']
, but it did not work.
Upvotes: 0
Views: 59
Reputation: 160843
Before php5.4, you can't do $v->getData()['title']
, you need use a variable.
$i = 1;
foreach ($product->getOptions() as $o) {
$values = $o->getValues();
foreach ($values as $v) {
$data = $v->getData();
echo $data['title'];
}
$i++;
}
Upvotes: 4