Created
March 12, 2017 15:19
-
-
Save mrkhoa99/1ce8bfbddeff957ce369c7256bcc6316 to your computer and use it in GitHub Desktop.
addPageLayoutHandles Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Some\Module\Plugin; | |
use Magento\Catalog\Api\ProductRepositoryInterface; | |
use Magento\Framework\View\Result\Page; | |
class ProductLayout | |
{ | |
protected $productRepository; | |
public function __construct(ProductRepositoryInterface $productRepository) | |
{ | |
$this->productRepository = $productRepository; | |
} | |
public function beforeAddPageLayoutHandles(Page $subject, ...$args) | |
{ | |
if (is_array($args) && count($args) == 1) { | |
$params = $args[0]; | |
if (isset($params['sku'])) { | |
$product = $this->productRepository->getById($params['id']); | |
if ($product->getPageLayout() === 'subscription') { | |
$subject->getLayout()->getUpdate()->removeHandle($subject->getDefaultLayoutHandle()); | |
return [$params, 'catalog_product_subscription']; | |
} | |
} | |
} | |
return $args; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment