controller - Magento - Query for Product Options -
i want write controller finds different options given product (eg. large, medium, small, red, blue etc...).
can show me code write controller?
additional details
i'm getting closer, still can't figure out. here's code wrote in controller
$db = mage::getmodel('catalog/product')->load($productid); print_r($db->getoptions()); // returns empty array echo $db->gethasoptions(); // echos 1
but when print_r() on second line, getoptions returns empty array. third line echo's value 1, means there should options.
additional details tried clockworkgeek's solution of $db->getproductoptions()
, returned nothing. tried $db->getproductoptionscollection()
, , got output
array ( [totalrecords] => 0 [items] => array ( ) )
what's wrong code such not returning allowable product options?
instead of getoptions()
please try getcustomoptions()
or getproductoptionscollection()
or getproductoptionscollection()->load()
.
edit
tried on product knew had options.
<?php require 'app/mage.php'; mage::app(); $product = mage::getmodel('catalog/product')->load($productid); foreach ($product->getproductoptions() $option) { print_r($option->debug()); }
and got this:
array ( [option_id] => 37 [product_id] => 8 [type] => multidate [is_require] => 1 [sku] => [image_size_x] => 0 [image_size_y] => 0 [sort_order] => 1 [default_title] => dates [title] => dates )
however, getoptions()
worked me don't know what's going on.
post-edit
confusion 1 of semantics. simple product can have "custom options", allow creation of few form fields recorded part of order. configurable product uses "associated products" create form conditional fields.
for example might selling socks large-green, small-green or large-blue - no small-blue ones. simple product have field large/small , field blue/green - allows customer select small-blue , wrong.
so find component parts of configurable might this:
if ($product->isconfigurable()) { $configurable = $product->gettypeinstance(); $childproducts = $product->getusedproducts($product); foreach ($childproducts $child) { // have $child } }
to find equivalent of getoptions()
need this:
if ($product->isconfigurable()) { $configurable = $product->gettypeinstance(); $attributes = $configurable->getconfigurableattributes($product); // $attributes mage_catalog_model_resource_eav_mysql4_product_type_configurable_attribute_collection foreach ($attributes $attribute) { // $attribute mage_catalog_model_product_type_configurable_attribute print $attribute->getlabel(); } }
mage_catalog_model_product_type_configurable_attribute
doesn't have reveal itself.
Comments
Post a Comment