Skip to content

Instantly share code, notes, and snippets.

@mrkhoa99
Created March 12, 2017 15:19
Show Gist options
  • Save mrkhoa99/1ce8bfbddeff957ce369c7256bcc6316 to your computer and use it in GitHub Desktop.
Save mrkhoa99/1ce8bfbddeff957ce369c7256bcc6316 to your computer and use it in GitHub Desktop.
addPageLayoutHandles Plugin
<?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