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);
/**
* In Magento Models or database schema level, the product's Custom Options are
* executed & maintained as only "options". So, when checking whether any product has
* Custom Options or not, we should check by using this method "hasOptions()" only.
*/
if($product->hasOptions()) {
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…