Sunday, 13 July 2014
In this post, I would like to show you how can we get product option values.
For this, let us start with creating a sample product that holds some custom options. Our Product has name Test Product With Option and below I am showing you its custom option that we set through admin
Now its frontend view will look like this.
This is how we can obtain each option value
Here what we have done is, first we load our product that holds custom options. We load the product through its id. So $product holds our product. Now we assigns all options of product to $option. getOptions() will return an array of object that of class Mage_Catalog_Model_Product_Option. Then we are looping through each options and then loads option values by invoking getValues(). This method will also return an array that holds objects of class Mage_Catalog_Model_Product_Option_Value. Each of this object holds complete information of a particular value.
So the output will look like this
Thus getting option values of custom option of a product is pretty straight forward and easy to understand.
For this, let us start with creating a sample product that holds some custom options. Our Product has name Test Product With Option and below I am showing you its custom option that we set through admin
Now its frontend view will look like this.
This is how we can obtain each option value
Here what we have done is, first we load our product that holds custom options. We load the product through its id. So $product holds our product. Now we assigns all options of product to $option. getOptions() will return an array of object that of class Mage_Catalog_Model_Product_Option. Then we are looping through each options and then loads option values by invoking getValues(). This method will also return an array that holds objects of class Mage_Catalog_Model_Product_Option_Value. Each of this object holds complete information of a particular value.
So the output will look like this
Option :custom checkbox
Values:
Array
(
[option_type_id] => 7
[option_id] => 4
[sku] =>
[sort_order] => 0
[default_title] => custom checkbox value 1
[store_title] =>
[title] => custom checkbox value 1
[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] => 4
[sku] =>
[sort_order] => 0
[default_title] => custom checkbox value 2
[store_title] =>
[title] => custom checkbox value 2
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
Option :custom dropdown
Values:
Array
(
[option_type_id] => 9
[option_id] => 5
[sku] =>
[sort_order] => 0
[default_title] => custom option value 1
[store_title] =>
[title] => custom option value 1
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
Array
( [option_type_id] => 10
[option_id] => 5
[sku] =>
[sort_order] => 0
[default_title] => custom option value 2
[store_title] =>
[title] => custom option value 2
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
Array
(
[option_type_id] => 11
[option_id] => 5
[sku] =>
[sort_order] => 0
[default_title] => custom option value 3
[store_title] =>
[title] => custom option value 3
[default_price] => 0.0000
[default_price_type] => fixed
[store_price] =>
[store_price_type] =>
[price] => 0.0000
[price_type] => fixed
)
Option :Custom Text Field
Values:
Thus getting option values of custom option of a product is pretty straight forward and easy to understand.
Subscribe to:
Post Comments (Atom)
Stack Exchange
Recently Answered
Popular Posts
-
In this post, I would like to show you how can we get product option values. For this, let us start with creating a sample product that h...
-
Static blocks are very useful tools in Magento. We can effectively use them in different situations. They provide us enough power on content...
-
Some times, it would be great if we can add a collapse/expand functionality in CMS Pages in Magento. A perfect example would be a read more ...
-
By default every Magento product list page has to modes of view. They are List and Grid . We can set default mode through admin. For this ...
-
Here in this tutorial, I would like to share you how can we set page size for a particular category. The Page Size is actually a property...
-
The main reason, in fact the inspiration behind this blog is this THREAD . In this thread, the user want to add layout that render by...
-
Introduction ---------------------- When I started to do Module Development in Magento, a lot of time I got an error like this Fat...
Blog Archive
Categories
Powered by Blogger.
Thanks a-lot Rajeev for this helpful post.
ReplyDeleteglad to help you out :)
Delete