3

How would I go about getting the Admin value for an attribute, regardless of the visitor's chosen store view?

I've tried:
$_product = $this->getProduct(); $_condition = $_product->getAttributeText('condition'); $_conditionDefault = $_product->setStoreID(0)->getAttributeText('condition');

However, setStoreId() does not work in this context.

Regardless of the language or store view that the visitor is currently viewing, I would like to be able to output the value for the Admin Store View and the value for the User's Current Store View.

The Condition attribute is a DropDown.

2

It typo mistake it should be setStoreId instead of setStoreID and use -getResource()

$_condition = $_product->getAttributeText('condition');
$prod= $_product->setStoreId(0);
$_coditionDefault =$_product->getResource()->getAttribute('condition')->getFrontend()->getValue($_product);
5
  • Thanks for the suggestion. I tried it and I got an error: Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product::getAttributeText() in /app/design/frontend/sm_market/default/template/catalog/product/view/type/default.phtml on line 42 – pallazzio Mar 28 '15 at 20:08
  • Just remove get resource() – Amit Bera Mar 28 '15 at 20:14
  • I tried that too with no luck. Both $_condition and $_conditionDefault are outputting the same value, which is the value of the current store view. I still can't get it to output the value for Admin Store View. Any other ways it might work? – pallazzio Mar 29 '15 at 0:21
  • update answer.. please check – Amit Bera Mar 29 '15 at 5:05
  • @AmitBera, pls help on this: magento.stackexchange.com/questions/210021/… – Magento 2 Learner Jan 19 '18 at 6:00
10

Thank you very much Amit Bera. Based on the very helpful suggestions, here is the working code!

$_condition = $_product->getAttributeText('condition');
$_coditionDefault = $_product->getResource()->getAttribute('condition')->setStoreId(0)->getFrontend()->getValue($_product);
2
  • Excellent! Happy to confirm this works on Magento 2.1.7 – Dan Norris Jul 2 '17 at 20:28
  • For further readers, this solutions works for Magento version 2.3.5. Note that the above solution (the marked and valie) seems to be oriented to Magento 1. – Manuel García Solipa May 21 '20 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.