7

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 Answers 2

5

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
    Commented Mar 28, 2015 at 20:08
  • Just remove get resource()
    – Amit Bera
    Commented Mar 28, 2015 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
    Commented Mar 29, 2015 at 0:21
  • update answer.. please check
    – Amit Bera
    Commented Mar 29, 2015 at 5:05
  • @AmitBera, pls help on this: magento.stackexchange.com/questions/210021/… Commented Jan 19, 2018 at 6:00
13

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
    Commented Jul 2, 2017 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. Commented May 21, 2020 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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