magento2 – Custom Product View Based on Attribute Set Name

I am trying to create a different product view based on the Attribute Set Name (not ID, or specific attribute value). I’ve looked at a couple different tickets here already, and have tried to implement this using a plugin for beforeInitProductLayout … but I can’t seem to get it to work.

Magento 2 – Layout based on attribute set

Layout handle from attribute set

Vendor/Namespace/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCatalogHelperProductView">
        <plugin name="vendor_namespace_helper_product_view" type="VendorNamespacePluginHelperProductView" />
    </type>
</config>

Vendor/Namespace/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Namespace" setup_version="1.0.0">
    </module>
</config>

Vendor/Namespace/Plugin/Helper/Product/View.php

namespace VendorNamespacePluginHelperProduct;

use MagentoBundleModelProductType;
use MagentoFrameworkDataObject;
use MagentoFrameworkDataObjectFactory;

class View
{
    const PRODUCT_LAYOUT_HANDLE = 'catalog_product_view_boxedcard';

    /**
     * @var DataObjectFactory
     */
    private $dataObjectFactory;

    /**
     * @param DataObjectFactory $dataObjectFactory
     */
    public function __construct(
        DataObjectFactory $dataObjectFactory
    ) {
        $this->dataObjectFactory = $dataObjectFactory;
    }

    public function beforeInitProductLayout(
        MagentoCatalogHelperProductView $view,
        MagentoFrameworkViewResultPage $resultPage,
        $product,
        $params = null
    )
    {

        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');
        $attributeSet = $objectManager->create('MagentoEavApiAttributeSetRepositoryInterface');
        $attributeSetRepository = $attributeSet->get($product->getAttributeSetId());
        $attribute_set_name = $attributeSetRepository->getAttributeSetName();

       if ($attribute_set_name == "Boxed Card Image Roles") {
           if (!$params) {
               $params = new MagentoFrameworkDataObject();
           }
               $afterHandles = $params->getAfterHandles();
               if (!$afterHandles) {
                   $afterHandles = array();
               }
               $afterHandles() = PRODUCT_LAYOUT_HANDLE;
               $params->setAfterHandles($afterHandles);
           }
           return ($resultPage, $product, $params);
        }
}

Vendor/Namespace/view/frontend/layout/catalog_product_view_boxedcard.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>

    <referenceBlock name="product.info.media.image" remove="true"/>

        <referenceContainer name="product.info.media">
            <block class="MagentoCatalogBlockProductViewGallery" name="boxed.card.gallery" template="Vendor_Namespace::product/view/gallery.phtml" />
        </referenceContainer>
    </body>
</page>

When I go to products on my local site that have this Product Attribute Set, it says the page can’t be found and renders like this:

enter image description here