cancel
Showing results for 
Search instead for 
Did you mean: 

Making changes to Attribute set frontend display

Making changes to Attribute set frontend display

Hi there

I hope someone can point me in the right direction here.

 

I have a product attribute set that I select when adding certain new products.

 

I want to make some front end design changes to the extended product page only for the products using this attribute set.

 

The changes I want to make include using reference block  - remove  for certain elements

How do I best approach this?

 

I can achieve this in an xml file  - if I could target the correct attribute set

 

Kind Regards

Brad

2 REPLIES 2

Re: Making changes to Attribute set frontend display

I have found a solution dating back to 2019 supplied by @saneer_ladani 

 

namespace Vendor\ModuleName\Observer;

use Magento\Framework\Event\ObserverInterface;


class ProductViewLayout implements ObserverInterface
{
    protected $_resultPageFactory;

    public function __construct(\Magento\Framework\View\Result\PageFactory $resultPageFactory) {
        $this->_resultPageFactory = $resultPageFactory;
    }
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($observer->getProduct()->getId());
        $attributeValue = $_product->getResource()->getAttribute('type_of_product')->getFrontend()->getValue($_product);
        if($attributeValue=="Test 2"){
            $page = $this->_resultPageFactory->create();
            $page->addHandle('catalog_product_custom_layout');
        }
        return $this;
    }
}

However on Magento 2.3.7  I get this error

 

"PHP message: PHP Fatal error: Uncaught Error: Call to a member function getFrontend() on bool "  referencing link 18

 

Any help or advice graciously accepted

 

Re: Making changes to Attribute set frontend display

- Try this

$_product->getResource()->getAttribute('attribute_code')->setStoreId(0)->getFrontend()->getValue($_product);


- Or

$_product->getData('your_attribute');
LitExtension - #1 Shopping Cart Migration Expert

LitExtension helps store owners and agencies migrate all important data from one eCommerce platform to another accurately, securely and at the highest speed.

Visit website: http://litextension.com/