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?

asked May 15, 2017 at 21:45

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.

answered May 15, 2017 at 23:14
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.