Get Attribute option Id by Attribute admin valueAssign Attribute to Product programmaticallyGet option Value from Option label for product/storeProduct attribute show/hide in admin depending on other attribute valueHow to get attribute “option label/attribute text” having “attribute value” (option_id)?Get attribute admin option value if you have option Id or store view valueGet Attribute Option Position from Option valueManage option value of attribute option disappearshow to get swatches attribute option in magento 2Multiselect attribute The value of Admin must be uniqueGet values of your attribute option text from productmagento 2 Get attribute option label by attribute option Id?
Adding two lambda-functions in C++
How to make thick Asian sauces?
Movie where a boy is transported into the future by an alien spaceship
X-shaped crossword
How to make a setting relevant?
Did thousands of women die every year due to illegal abortions before Roe v. Wade?
Why don't B747s start takeoffs with full throttle?
Java guess the number
C SIGINT signal in Linux
Are the AT-AT's from "Empire Strikes Back" a deliberate reference to Mecha?
Smooth switching between 12v batteries, with toggle switch
Bent spoke design wheels — feasible?
How can Iron Man's suit withstand this?
How can I instantiate a lambda closure type in C++11/14?
Payment instructions from HomeAway look fishy to me
Can a magnetic field of an object be stronger than its gravity?
Avoiding cliches when writing gods
What's the correct term for a waitress in the Middle Ages?
Do manufacturers try make their components as close to ideal ones as possible?
Is it legal in the UK for politicians to lie to the public for political gain?
Secure offsite backup, even in the case of hacker root access
How to generate random points without duplication?
Does the growth of home value benefit from compound interest?
How do photons get into the eyes?
Get Attribute option Id by Attribute admin value
Assign Attribute to Product programmaticallyGet option Value from Option label for product/storeProduct attribute show/hide in admin depending on other attribute valueHow to get attribute “option label/attribute text” having “attribute value” (option_id)?Get attribute admin option value if you have option Id or store view valueGet Attribute Option Position from Option valueManage option value of attribute option disappearshow to get swatches attribute option in magento 2Multiselect attribute The value of Admin must be uniqueGet values of your attribute option text from productmagento 2 Get attribute option label by attribute option Id?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
For a Magento Dropdown Attribute, it is possible to get an Attribute option Id by Attribute admin value?
attributes custom-options attribute-options
add a comment |
For a Magento Dropdown Attribute, it is possible to get an Attribute option Id by Attribute admin value?
attributes custom-options attribute-options
add a comment |
For a Magento Dropdown Attribute, it is possible to get an Attribute option Id by Attribute admin value?
attributes custom-options attribute-options
For a Magento Dropdown Attribute, it is possible to get an Attribute option Id by Attribute admin value?
attributes custom-options attribute-options
attributes custom-options attribute-options
edited Aug 25 '16 at 14:52
7ochem
5,89993770
5,89993770
asked Jul 8 '15 at 12:28
BizbossBizboss
2972724
2972724
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it.
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource())
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("Purple");
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
add a comment |
If you have the admin value :
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("purple");
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
add a comment |
Code below checks if the attribute already have an option then return its id other wise add new option and return its id
function addAttributeOption($attributeCode, $argValue)
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
$id = $attribute->getSource()->getOptionId($argValue);
if ($id)
return $id;
$value = array('value' => array(
'option' => array(
ucfirst($argValue),
ucfirst($argValue)
)
)
);
$attribute->setData('option', $value);
$attribute->save();
//getting id of newly inserted option
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
return $attribute->getSource()->getOptionId($argValue);
Use it as
$this->addAttributeOption("uniform_type", "leotard");
add a comment |
i was face same problem the solution work for me. because the frontend store values were not added. this code work for me.
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
if ($attr->usesSource())
$attributeOptions = $attr ->getSource()->getAllOptions();
foreach ($attributeOptions as $option)
if($option['label']=='Purple')
echo $curattributeid=$option['value'];
add a comment |
Yes you can get the option ID of an attribute by the admin value. You can use the eav/entity_attribute_option_collection
to achieve it:
$attributeCode = 'attr_code';
$attributeAdminValue = 'something';
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getId())
->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
->addFieldToFilter('tdv.value', $attributeAdminValue);
if ($collection->getSize() > 0)
echo $collection->getFirstItem()->getId();
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%2f73636%2fget-attribute-option-id-by-attribute-admin-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it.
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource())
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("Purple");
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
add a comment |
Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it.
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource())
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("Purple");
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
add a comment |
Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it.
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource())
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("Purple");
Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it.
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource())
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("Purple");
edited May 27 at 17:37
snh_nl
3,0531047107
3,0531047107
answered Jul 8 '15 at 12:35
Pradeep SankuPradeep Sanku
7,92113159
7,92113159
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
add a comment |
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
Thanks for help, but it works only with the Default Store View option value, when I try with the admin value I get NULL
– Bizboss
Jul 8 '15 at 12:59
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
This does not seem to work always. Somehow we now have an attr option admin value that just DOES NOT return an id.
– snh_nl
May 27 at 17:31
add a comment |
If you have the admin value :
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("purple");
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
add a comment |
If you have the admin value :
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("purple");
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
add a comment |
If you have the admin value :
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("purple");
If you have the admin value :
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("purple");
answered Aug 25 '16 at 14:34
Soleil BleuSoleil Bleu
411
411
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
add a comment |
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
This should be the accepted answer, as it is the only one that actually answers the question that was actually asked. Worked for me.
– Louis B.
May 31 '18 at 12:09
add a comment |
Code below checks if the attribute already have an option then return its id other wise add new option and return its id
function addAttributeOption($attributeCode, $argValue)
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
$id = $attribute->getSource()->getOptionId($argValue);
if ($id)
return $id;
$value = array('value' => array(
'option' => array(
ucfirst($argValue),
ucfirst($argValue)
)
)
);
$attribute->setData('option', $value);
$attribute->save();
//getting id of newly inserted option
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
return $attribute->getSource()->getOptionId($argValue);
Use it as
$this->addAttributeOption("uniform_type", "leotard");
add a comment |
Code below checks if the attribute already have an option then return its id other wise add new option and return its id
function addAttributeOption($attributeCode, $argValue)
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
$id = $attribute->getSource()->getOptionId($argValue);
if ($id)
return $id;
$value = array('value' => array(
'option' => array(
ucfirst($argValue),
ucfirst($argValue)
)
)
);
$attribute->setData('option', $value);
$attribute->save();
//getting id of newly inserted option
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
return $attribute->getSource()->getOptionId($argValue);
Use it as
$this->addAttributeOption("uniform_type", "leotard");
add a comment |
Code below checks if the attribute already have an option then return its id other wise add new option and return its id
function addAttributeOption($attributeCode, $argValue)
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
$id = $attribute->getSource()->getOptionId($argValue);
if ($id)
return $id;
$value = array('value' => array(
'option' => array(
ucfirst($argValue),
ucfirst($argValue)
)
)
);
$attribute->setData('option', $value);
$attribute->save();
//getting id of newly inserted option
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
return $attribute->getSource()->getOptionId($argValue);
Use it as
$this->addAttributeOption("uniform_type", "leotard");
Code below checks if the attribute already have an option then return its id other wise add new option and return its id
function addAttributeOption($attributeCode, $argValue)
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
$id = $attribute->getSource()->getOptionId($argValue);
if ($id)
return $id;
$value = array('value' => array(
'option' => array(
ucfirst($argValue),
ucfirst($argValue)
)
)
);
$attribute->setData('option', $value);
$attribute->save();
//getting id of newly inserted option
$attribute = Mage::getModel('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
if ($attribute->usesSource())
return $attribute->getSource()->getOptionId($argValue);
Use it as
$this->addAttributeOption("uniform_type", "leotard");
answered Apr 18 '16 at 9:42
TofeeqTofeeq
1613
1613
add a comment |
add a comment |
i was face same problem the solution work for me. because the frontend store values were not added. this code work for me.
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
if ($attr->usesSource())
$attributeOptions = $attr ->getSource()->getAllOptions();
foreach ($attributeOptions as $option)
if($option['label']=='Purple')
echo $curattributeid=$option['value'];
add a comment |
i was face same problem the solution work for me. because the frontend store values were not added. this code work for me.
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
if ($attr->usesSource())
$attributeOptions = $attr ->getSource()->getAllOptions();
foreach ($attributeOptions as $option)
if($option['label']=='Purple')
echo $curattributeid=$option['value'];
add a comment |
i was face same problem the solution work for me. because the frontend store values were not added. this code work for me.
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
if ($attr->usesSource())
$attributeOptions = $attr ->getSource()->getAllOptions();
foreach ($attributeOptions as $option)
if($option['label']=='Purple')
echo $curattributeid=$option['value'];
i was face same problem the solution work for me. because the frontend store values were not added. this code work for me.
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
if ($attr->usesSource())
$attributeOptions = $attr ->getSource()->getAllOptions();
foreach ($attributeOptions as $option)
if($option['label']=='Purple')
echo $curattributeid=$option['value'];
answered Jan 25 '16 at 7:59
Qaisar SattiQaisar Satti
27.1k1261110
27.1k1261110
add a comment |
add a comment |
Yes you can get the option ID of an attribute by the admin value. You can use the eav/entity_attribute_option_collection
to achieve it:
$attributeCode = 'attr_code';
$attributeAdminValue = 'something';
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getId())
->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
->addFieldToFilter('tdv.value', $attributeAdminValue);
if ($collection->getSize() > 0)
echo $collection->getFirstItem()->getId();
add a comment |
Yes you can get the option ID of an attribute by the admin value. You can use the eav/entity_attribute_option_collection
to achieve it:
$attributeCode = 'attr_code';
$attributeAdminValue = 'something';
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getId())
->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
->addFieldToFilter('tdv.value', $attributeAdminValue);
if ($collection->getSize() > 0)
echo $collection->getFirstItem()->getId();
add a comment |
Yes you can get the option ID of an attribute by the admin value. You can use the eav/entity_attribute_option_collection
to achieve it:
$attributeCode = 'attr_code';
$attributeAdminValue = 'something';
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getId())
->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
->addFieldToFilter('tdv.value', $attributeAdminValue);
if ($collection->getSize() > 0)
echo $collection->getFirstItem()->getId();
Yes you can get the option ID of an attribute by the admin value. You can use the eav/entity_attribute_option_collection
to achieve it:
$attributeCode = 'attr_code';
$attributeAdminValue = 'something';
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getId())
->setStoreFilter(Mage_Core_Model_App::ADMIN_STORE_ID)
->addFieldToFilter('tdv.value', $attributeAdminValue);
if ($collection->getSize() > 0)
echo $collection->getFirstItem()->getId();
answered May 31 '16 at 6:27
SimonSimon
4,63312060
4,63312060
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.
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%2f73636%2fget-attribute-option-id-by-attribute-admin-value%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