Hello,
I have a couple products at checkout that I need to be able to get all of the custom options that are selected for them through code.
Any help is much appreciated!
Hello,
I have a couple products at checkout that I need to be able to get all of the custom options that are selected for them through code.
Any help is much appreciated!
I will just give you an example of one product. Let's say that you know the Sku (for example, let it be "ABCDE") of your required product. So you will be able to get the ID of that product.
The code will be somewhat like:-
$productSku = "ABCDE";
$product = Mage::getModel('catalog/product');
$productId = $product->getIdBySku( $productSku );
$product->load($productId);
if($product->hasCustomOptions()) {
echo '<pre>';
foreach ($product->getOptions() as $o) {
$optionType = $o->getType();
echo 'Type = '.$optionType;
if ($optionType == 'drop_down') {
$values = $o->getValues();
foreach ($values as $k => $v) {
print_r($v);
}
}
else {
print_r($o);
}
}
echo '</pre>';
}
I think this will let you get started.
Depending upon the type of the option in the variable "$optionType
", you need to call another nested "foreach
" loop. I have worked on text boxes, text fields, drop downs, but not on other types. So I suppose you need to do some more RnD by yourself.