How to get Product custom options name?
How to get Product custom options name?
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
Array
(
[options] => Array
(
[536] => 6535
[447] => 2985
)
[qty] => 1
[product] => 543
)
In options array, 536 is option label name & 6535 is value of selected option.
same for [447] is option label name => 2985 is value of selected option.
But i want option array in below format instead of option_id & value of option id.
[options] => Array
(
[color] => red
[size] => large
)
Please help.
thanx in advance
Updated:
i have create my own custom controller.
Custom_Inquiry_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default'));
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
$this->renderLayout();
}
}
magento-1.9 product custom-options
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
How to get Product custom options name?
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
Array
(
[options] => Array
(
[536] => 6535
[447] => 2985
)
[qty] => 1
[product] => 543
)
In options array, 536 is option label name & 6535 is value of selected option.
same for [447] is option label name => 2985 is value of selected option.
But i want option array in below format instead of option_id & value of option id.
[options] => Array
(
[color] => red
[size] => large
)
Please help.
thanx in advance
Updated:
i have create my own custom controller.
Custom_Inquiry_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default'));
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
$this->renderLayout();
}
}
magento-1.9 product custom-options
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
How to get Product custom options name?
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
Array
(
[options] => Array
(
[536] => 6535
[447] => 2985
)
[qty] => 1
[product] => 543
)
In options array, 536 is option label name & 6535 is value of selected option.
same for [447] is option label name => 2985 is value of selected option.
But i want option array in below format instead of option_id & value of option id.
[options] => Array
(
[color] => red
[size] => large
)
Please help.
thanx in advance
Updated:
i have create my own custom controller.
Custom_Inquiry_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default'));
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
$this->renderLayout();
}
}
magento-1.9 product custom-options
How to get Product custom options name?
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
Array
(
[options] => Array
(
[536] => 6535
[447] => 2985
)
[qty] => 1
[product] => 543
)
In options array, 536 is option label name & 6535 is value of selected option.
same for [447] is option label name => 2985 is value of selected option.
But i want option array in below format instead of option_id & value of option id.
[options] => Array
(
[color] => red
[size] => large
)
Please help.
thanx in advance
Updated:
i have create my own custom controller.
Custom_Inquiry_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default'));
$data = $this->getRequest()->getParams();
echo "<pre>"; print_r($data); die;
$this->renderLayout();
}
}
magento-1.9 product custom-options
magento-1.9 product custom-options
edited Sep 11 '17 at 5:07
Pankaj
asked Sep 8 '17 at 9:01
PankajPankaj
1801121
1801121
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
I don't know in which controller are you getting this result, but the solution is to put the values of the attributes instead of the id in the page in question before sending them to the controller, or you load a product model in the controller with your product id then you get all your attributes and you get what you need. the other solution is to parse all the keys and values of your array, then you replace them with the value but this is not the right approach !.
So for me, you should instead go on this way:
$_productId = $sessdata[product]; // 543
$_product = Mage::getModel('catalog/product')->load($_productId);
$color = $_product->getColor(); //red
$size = $_product->getSize(); //large
//If even you get the attribute id instead of value, you can use this:
$_product->getAttributeText('attr_id');
see my updated question
– Pankaj
Sep 11 '17 at 5:04
1
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
add a comment |
To get Option array as your format you have to do two thing-
First you have to get attribute code from your attribute id
// in your case for color attrId is 536
$attrId = 536;
$attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode();
// here in $attrCode you will get 'color'
After that you have to load attribute option label by attribute code and attribute option value
//here option id is value of color
$optionId = 6535;
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode);
$label = $attribute->getStoreLabel();
$optionLabel = $attribute->getFrontend()->getOption($optionId);// red
you have to repeat it for other attributes, you can loop it in foreach
For the product Custom option you can get All the custom option by product using this
$_product = Mage::getModel("catalog/product")->load('product_id');
$theoptions = $_product->getOptions();
$i=0;
$array = array();
foreach($theoptions as $opkey=> $opval)
{
$title = $opval->getTitle();
if($opval->getType() == 'drop_down'){
foreach($opval->getValues() as $value) {
$valueTitle = $value->getTitle();
}
}
}
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
add a comment |
This is what I coded years ago, placed it in your resource model:
/**
* Get option title
*
* @param int option_id
* @param int store_id
* @return string
*/
public function getOptionTitle($optionId, $storeId=0)
{
$bind = array('option_id' => $optionId, 'store_id'=>$storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_title'), array('title'))
->where('`option_id` = :option_id')
->where('`store_id` = :store_id')
;
return $adapter->fetchOne($select, $bind);
}
/**
* Get the option_type_title (text in dropdown or radio or checkbox) given option_type_id
*
* @param int
* @param int
* @return string
*/
public function getOptionTypeTitle($optionTypeId, $storeId = 0)
{
$bind = array('option_type_id' => $optionTypeId, 'store_id'=> $storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_type_title'), array('title'))
->where('`option_type_id` = :option_type_id')
->where('`store_id` = :store_id');
return $adapter->fetchOne($select, $bind);
}
In the given example:$optionId
is the keys 536 and 447$optionTypeId
is the values 6535 and 2985
add a comment |
Try code below :
$product = Mage::getModel('catalog/product');
$productId = 10; /* you can change $productId to your product id you want display custom options name */
$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>';
}
Let me know if you have any question !
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f192506%2fhow-to-get-product-custom-options-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't know in which controller are you getting this result, but the solution is to put the values of the attributes instead of the id in the page in question before sending them to the controller, or you load a product model in the controller with your product id then you get all your attributes and you get what you need. the other solution is to parse all the keys and values of your array, then you replace them with the value but this is not the right approach !.
So for me, you should instead go on this way:
$_productId = $sessdata[product]; // 543
$_product = Mage::getModel('catalog/product')->load($_productId);
$color = $_product->getColor(); //red
$size = $_product->getSize(); //large
//If even you get the attribute id instead of value, you can use this:
$_product->getAttributeText('attr_id');
see my updated question
– Pankaj
Sep 11 '17 at 5:04
1
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
add a comment |
I don't know in which controller are you getting this result, but the solution is to put the values of the attributes instead of the id in the page in question before sending them to the controller, or you load a product model in the controller with your product id then you get all your attributes and you get what you need. the other solution is to parse all the keys and values of your array, then you replace them with the value but this is not the right approach !.
So for me, you should instead go on this way:
$_productId = $sessdata[product]; // 543
$_product = Mage::getModel('catalog/product')->load($_productId);
$color = $_product->getColor(); //red
$size = $_product->getSize(); //large
//If even you get the attribute id instead of value, you can use this:
$_product->getAttributeText('attr_id');
see my updated question
– Pankaj
Sep 11 '17 at 5:04
1
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
add a comment |
I don't know in which controller are you getting this result, but the solution is to put the values of the attributes instead of the id in the page in question before sending them to the controller, or you load a product model in the controller with your product id then you get all your attributes and you get what you need. the other solution is to parse all the keys and values of your array, then you replace them with the value but this is not the right approach !.
So for me, you should instead go on this way:
$_productId = $sessdata[product]; // 543
$_product = Mage::getModel('catalog/product')->load($_productId);
$color = $_product->getColor(); //red
$size = $_product->getSize(); //large
//If even you get the attribute id instead of value, you can use this:
$_product->getAttributeText('attr_id');
I don't know in which controller are you getting this result, but the solution is to put the values of the attributes instead of the id in the page in question before sending them to the controller, or you load a product model in the controller with your product id then you get all your attributes and you get what you need. the other solution is to parse all the keys and values of your array, then you replace them with the value but this is not the right approach !.
So for me, you should instead go on this way:
$_productId = $sessdata[product]; // 543
$_product = Mage::getModel('catalog/product')->load($_productId);
$color = $_product->getColor(); //red
$size = $_product->getSize(); //large
//If even you get the attribute id instead of value, you can use this:
$_product->getAttributeText('attr_id');
edited Sep 10 '17 at 21:45
answered Sep 10 '17 at 21:36
PЯINCƏPЯINCƏ
7,75121136
7,75121136
see my updated question
– Pankaj
Sep 11 '17 at 5:04
1
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
add a comment |
see my updated question
– Pankaj
Sep 11 '17 at 5:04
1
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
see my updated question
– Pankaj
Sep 11 '17 at 5:04
see my updated question
– Pankaj
Sep 11 '17 at 5:04
1
1
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
@Pankaj Please accept some answer that you find helpful
– PЯINCƏ
Sep 16 '17 at 2:00
add a comment |
To get Option array as your format you have to do two thing-
First you have to get attribute code from your attribute id
// in your case for color attrId is 536
$attrId = 536;
$attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode();
// here in $attrCode you will get 'color'
After that you have to load attribute option label by attribute code and attribute option value
//here option id is value of color
$optionId = 6535;
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode);
$label = $attribute->getStoreLabel();
$optionLabel = $attribute->getFrontend()->getOption($optionId);// red
you have to repeat it for other attributes, you can loop it in foreach
For the product Custom option you can get All the custom option by product using this
$_product = Mage::getModel("catalog/product")->load('product_id');
$theoptions = $_product->getOptions();
$i=0;
$array = array();
foreach($theoptions as $opkey=> $opval)
{
$title = $opval->getTitle();
if($opval->getType() == 'drop_down'){
foreach($opval->getValues() as $value) {
$valueTitle = $value->getTitle();
}
}
}
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
add a comment |
To get Option array as your format you have to do two thing-
First you have to get attribute code from your attribute id
// in your case for color attrId is 536
$attrId = 536;
$attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode();
// here in $attrCode you will get 'color'
After that you have to load attribute option label by attribute code and attribute option value
//here option id is value of color
$optionId = 6535;
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode);
$label = $attribute->getStoreLabel();
$optionLabel = $attribute->getFrontend()->getOption($optionId);// red
you have to repeat it for other attributes, you can loop it in foreach
For the product Custom option you can get All the custom option by product using this
$_product = Mage::getModel("catalog/product")->load('product_id');
$theoptions = $_product->getOptions();
$i=0;
$array = array();
foreach($theoptions as $opkey=> $opval)
{
$title = $opval->getTitle();
if($opval->getType() == 'drop_down'){
foreach($opval->getValues() as $value) {
$valueTitle = $value->getTitle();
}
}
}
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
add a comment |
To get Option array as your format you have to do two thing-
First you have to get attribute code from your attribute id
// in your case for color attrId is 536
$attrId = 536;
$attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode();
// here in $attrCode you will get 'color'
After that you have to load attribute option label by attribute code and attribute option value
//here option id is value of color
$optionId = 6535;
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode);
$label = $attribute->getStoreLabel();
$optionLabel = $attribute->getFrontend()->getOption($optionId);// red
you have to repeat it for other attributes, you can loop it in foreach
For the product Custom option you can get All the custom option by product using this
$_product = Mage::getModel("catalog/product")->load('product_id');
$theoptions = $_product->getOptions();
$i=0;
$array = array();
foreach($theoptions as $opkey=> $opval)
{
$title = $opval->getTitle();
if($opval->getType() == 'drop_down'){
foreach($opval->getValues() as $value) {
$valueTitle = $value->getTitle();
}
}
}
To get Option array as your format you have to do two thing-
First you have to get attribute code from your attribute id
// in your case for color attrId is 536
$attrId = 536;
$attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode();
// here in $attrCode you will get 'color'
After that you have to load attribute option label by attribute code and attribute option value
//here option id is value of color
$optionId = 6535;
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode);
$label = $attribute->getStoreLabel();
$optionLabel = $attribute->getFrontend()->getOption($optionId);// red
you have to repeat it for other attributes, you can loop it in foreach
For the product Custom option you can get All the custom option by product using this
$_product = Mage::getModel("catalog/product")->load('product_id');
$theoptions = $_product->getOptions();
$i=0;
$array = array();
foreach($theoptions as $opkey=> $opval)
{
$title = $opval->getTitle();
if($opval->getType() == 'drop_down'){
foreach($opval->getValues() as $value) {
$valueTitle = $value->getTitle();
}
}
}
edited Sep 11 '17 at 8:14
answered Sep 11 '17 at 5:30
PiyushPiyush
4,76872053
4,76872053
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
add a comment |
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
above code is not working for me.
– Pankaj
Sep 11 '17 at 5:56
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
is it generating any error?
– Piyush
Sep 11 '17 at 5:59
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
$attrId = 536; $attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode(); echo "sdsdsd".$attrCode; die; this print only sdsdsd
– Pankaj
Sep 11 '17 at 6:02
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
One more thing, actually there are custom option of simple products not attribute. [options] => Array ( [536] => 6535 [447] => 2985 )
– Pankaj
Sep 11 '17 at 6:03
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
check my update ,you can get custom option detail using that
– Piyush
Sep 11 '17 at 6:33
add a comment |
This is what I coded years ago, placed it in your resource model:
/**
* Get option title
*
* @param int option_id
* @param int store_id
* @return string
*/
public function getOptionTitle($optionId, $storeId=0)
{
$bind = array('option_id' => $optionId, 'store_id'=>$storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_title'), array('title'))
->where('`option_id` = :option_id')
->where('`store_id` = :store_id')
;
return $adapter->fetchOne($select, $bind);
}
/**
* Get the option_type_title (text in dropdown or radio or checkbox) given option_type_id
*
* @param int
* @param int
* @return string
*/
public function getOptionTypeTitle($optionTypeId, $storeId = 0)
{
$bind = array('option_type_id' => $optionTypeId, 'store_id'=> $storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_type_title'), array('title'))
->where('`option_type_id` = :option_type_id')
->where('`store_id` = :store_id');
return $adapter->fetchOne($select, $bind);
}
In the given example:$optionId
is the keys 536 and 447$optionTypeId
is the values 6535 and 2985
add a comment |
This is what I coded years ago, placed it in your resource model:
/**
* Get option title
*
* @param int option_id
* @param int store_id
* @return string
*/
public function getOptionTitle($optionId, $storeId=0)
{
$bind = array('option_id' => $optionId, 'store_id'=>$storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_title'), array('title'))
->where('`option_id` = :option_id')
->where('`store_id` = :store_id')
;
return $adapter->fetchOne($select, $bind);
}
/**
* Get the option_type_title (text in dropdown or radio or checkbox) given option_type_id
*
* @param int
* @param int
* @return string
*/
public function getOptionTypeTitle($optionTypeId, $storeId = 0)
{
$bind = array('option_type_id' => $optionTypeId, 'store_id'=> $storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_type_title'), array('title'))
->where('`option_type_id` = :option_type_id')
->where('`store_id` = :store_id');
return $adapter->fetchOne($select, $bind);
}
In the given example:$optionId
is the keys 536 and 447$optionTypeId
is the values 6535 and 2985
add a comment |
This is what I coded years ago, placed it in your resource model:
/**
* Get option title
*
* @param int option_id
* @param int store_id
* @return string
*/
public function getOptionTitle($optionId, $storeId=0)
{
$bind = array('option_id' => $optionId, 'store_id'=>$storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_title'), array('title'))
->where('`option_id` = :option_id')
->where('`store_id` = :store_id')
;
return $adapter->fetchOne($select, $bind);
}
/**
* Get the option_type_title (text in dropdown or radio or checkbox) given option_type_id
*
* @param int
* @param int
* @return string
*/
public function getOptionTypeTitle($optionTypeId, $storeId = 0)
{
$bind = array('option_type_id' => $optionTypeId, 'store_id'=> $storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_type_title'), array('title'))
->where('`option_type_id` = :option_type_id')
->where('`store_id` = :store_id');
return $adapter->fetchOne($select, $bind);
}
In the given example:$optionId
is the keys 536 and 447$optionTypeId
is the values 6535 and 2985
This is what I coded years ago, placed it in your resource model:
/**
* Get option title
*
* @param int option_id
* @param int store_id
* @return string
*/
public function getOptionTitle($optionId, $storeId=0)
{
$bind = array('option_id' => $optionId, 'store_id'=>$storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_title'), array('title'))
->where('`option_id` = :option_id')
->where('`store_id` = :store_id')
;
return $adapter->fetchOne($select, $bind);
}
/**
* Get the option_type_title (text in dropdown or radio or checkbox) given option_type_id
*
* @param int
* @param int
* @return string
*/
public function getOptionTypeTitle($optionTypeId, $storeId = 0)
{
$bind = array('option_type_id' => $optionTypeId, 'store_id'=> $storeId);
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('catalog/product_option_type_title'), array('title'))
->where('`option_type_id` = :option_type_id')
->where('`store_id` = :store_id');
return $adapter->fetchOne($select, $bind);
}
In the given example:$optionId
is the keys 536 and 447$optionTypeId
is the values 6535 and 2985
edited Aug 25 '18 at 4:07
answered Aug 25 '18 at 4:01
kiatngkiatng
539215
539215
add a comment |
add a comment |
Try code below :
$product = Mage::getModel('catalog/product');
$productId = 10; /* you can change $productId to your product id you want display custom options name */
$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>';
}
Let me know if you have any question !
add a comment |
Try code below :
$product = Mage::getModel('catalog/product');
$productId = 10; /* you can change $productId to your product id you want display custom options name */
$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>';
}
Let me know if you have any question !
add a comment |
Try code below :
$product = Mage::getModel('catalog/product');
$productId = 10; /* you can change $productId to your product id you want display custom options name */
$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>';
}
Let me know if you have any question !
Try code below :
$product = Mage::getModel('catalog/product');
$productId = 10; /* you can change $productId to your product id you want display custom options name */
$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>';
}
Let me know if you have any question !
answered Aug 25 '18 at 6:43
Vu Tran KienVu Tran Kien
3321224
3321224
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f192506%2fhow-to-get-product-custom-options-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown