0

I have to create new layout on product view page using xml on the bases of product attribute set......

Trying this but no luck: layout/catalog_product_view_attribute_set_id_10.xml

Any idea to achieve this?

1 Answer 1

1

Using a custom module, you can create a plugin for the Magento\Catalog\Helper\Product\View class's initProductLayout method.

Your plugin class would be something like this:

use Magento\Catalog\Model\Product;
use Magento\Framework\View\Result\Page as ResultPage;

class View
{
    public function beforeInitProductLayout(
        \Magento\Catalog\Helper\Product\View $subject,
        ResultPage $resultPage, Product $product, $params = null
    ) {
        $resultPage->addPageLayoutHandles(
          ['attribute_set_id' => $product->getAttributeSetId()]
        );

        return [$resultPage, $product, $params];
    }
}

Then catalog_product_view_attribute_set_id_10.xml will be included for products that use attribute set 10.

0

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.