Get Custom Options in Checkout/cart page Programmatically Magento
Hardik
Checkout/cart,
Custom Options,
magento,
magento customers,
magento get product options
1 comment
A Magento client of mine wanted to be able to change the calls to action on the cart and checkout pages based on the product configuration that the customers have selected for purchase. The following bit of code loops through the products in the Magento shopping basket and gets the chosen custom options and / or configuration.
// Load the session
$session
= Mage::getSingleton(
'checkout/session'
);
// Array to hold the final result
$finalResult
=
array
();
// Loop through all items in the cart
foreach
(
$session
->getQuote()->getAllItems()
as
$item
)
{
// Array to hold the item's options
$result
=
array
();
// Load the configured product options
$options
=
$item
->getProduct()->getTypeInstance(true)
->getOrderOptions(
$item
->getProduct());
// Check for options
if
(
$options
)
{
if
(isset(
$options
[
'options'
]))
{
$result
=
array_merge
(
$result
,
$options
[
'options'
]);
}
if
(isset(
$options
[
'additional_options'
]))
{
$result
=
array_merge
(
$result
,
$options
[
'additional_options'
]);
}
if
(!
empty
(
$options
[
'attributes_info'
]))
{
$result
=
array_merge
(
$options
[
'attributes_info'
],
$result
);
}
}
$finalResult
=
array_merge
(
$finalResult
,
$result
);
}
// Now you have the final array of all configured options
Zend_Debug::dump(
$finalResult
);
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)
Hi thanks for this code.
ReplyDeleteI have a problem , if I have a custom option.
For example "color label" and i buy two products, same sku but different custom options: one with "blue" value and one with "green" value,
it shows up just the last inserted "green". how to solve this issue? I need to have both.
thanks a lot