init
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Category;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use WeltPixel\NavigationLinks\Model\Attribute\Source\CategoryLayout;
|
||||
|
||||
/**
|
||||
* Class Design
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Category
|
||||
*/
|
||||
class Design
|
||||
{
|
||||
/**
|
||||
* @var JsonFactory
|
||||
*/
|
||||
protected $_resultJsonFactory;
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $pageFactory;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
* @param JsonFactory $resultJsonFactory
|
||||
* @param UrlInterface $_storeManager
|
||||
* @param Data $wpHelper
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
JsonFactory $resultJsonFactory,
|
||||
UrlInterface $_storeManager,
|
||||
Data $wpHelper,
|
||||
PageFactory $pageFactory
|
||||
)
|
||||
{
|
||||
$this->_resultJsonFactory = $resultJsonFactory;
|
||||
$this->_storeManager = $_storeManager;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Design $subject
|
||||
* @param \Magento\Framework\DataObject $result
|
||||
* @param Category|Product $object
|
||||
* @return \Magento\Framework\DataObject
|
||||
*/
|
||||
public function afterGetDesignSettings(\Magento\Catalog\Model\Design $subject, $result, $object)
|
||||
{
|
||||
if(!$this->_wpHelper->isEnabled()) {
|
||||
return $result;
|
||||
}
|
||||
if ($object instanceof Product) {
|
||||
$currentCategory = $object->getCategory();
|
||||
} else {
|
||||
$currentCategory = $object;
|
||||
}
|
||||
|
||||
if (!$currentCategory) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$sideBarStyle = $this->_wpHelper->getSidebarStyle();
|
||||
if ($sideBarStyle != 3) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result->setPageLayout('1column');
|
||||
|
||||
$pageLayoutHandles = $result->getPageLayoutHandles();
|
||||
$horizontalLayoutHandle = ['wpln' => 'horizontalnavigation'];
|
||||
if (is_array($pageLayoutHandles)) {
|
||||
$pageLayoutHandles['wpln'] = 'horizontalnavigation';
|
||||
} else {
|
||||
$pageLayoutHandles = $horizontalLayoutHandle;
|
||||
}
|
||||
$result->setPageLayoutHandles($pageLayoutHandles);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Category;
|
||||
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Category
|
||||
*/
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* @var JsonFactory
|
||||
*/
|
||||
protected $_resultJsonFactory;
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $pageFactory;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
* @param JsonFactory $resultJsonFactory
|
||||
* @param UrlInterface $_storeManager
|
||||
* @param Data $wpHelper
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
JsonFactory $resultJsonFactory,
|
||||
UrlInterface $_storeManager,
|
||||
Data $wpHelper,
|
||||
PageFactory $pageFactory
|
||||
)
|
||||
{
|
||||
$this->_resultJsonFactory = $resultJsonFactory;
|
||||
$this->_storeManager = $_storeManager;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Action $subject
|
||||
* @param $page
|
||||
* @return $this|void
|
||||
*/
|
||||
public function afterExecute(Action $subject, $page)
|
||||
{
|
||||
if ($this->_wpHelper->isEnabled()) {
|
||||
$this->_wpHelper->updateSliderBodyClass();
|
||||
}
|
||||
if(!$this->_wpHelper->isAjaxEnabled() || !$this->_wpHelper->isEnabled()) {
|
||||
return $page;
|
||||
}
|
||||
|
||||
$response = $page;
|
||||
if ($response instanceof Page) {
|
||||
if ($subject->getRequest()->getParam('ajax') == 1) {
|
||||
$subject->getRequest()->getQuery()->set('ajax', null);
|
||||
$requestUri = $subject->getRequest()->getRequestUri();
|
||||
$requestUri = preg_replace('/(\?|&)ajax=1/', '', $requestUri);
|
||||
$subject->getRequest()->setRequestUri($requestUri);
|
||||
|
||||
$productsList = $response->getLayout()->getBlock('category.products.list');
|
||||
$listMode = $subject->getRequest()->getParam('product_list_mode');
|
||||
if($listMode) {
|
||||
$productsList->getChildBlock('product_list_toolbar')->setData('_current_grid_mode', $listMode);
|
||||
}
|
||||
$productsListBlockHtml = $productsList->toHtml();
|
||||
$leftNavBlockHtml = $response->getLayout()->getBlock('catalog.leftnav')->toHtml();
|
||||
|
||||
$dataLayerContent = '';
|
||||
$dataLayerContentGa4 = '';
|
||||
$dataLayerBlock = $response->getLayout()->getBlock('head.additional');
|
||||
if ($dataLayerBlock) {
|
||||
$dLBlockHtml = $dataLayerBlock->toHtml();
|
||||
preg_match('/var dlObjects ?= ?(.*?)];/', $dLBlockHtml, $matches);
|
||||
if (count($matches) == 2) {
|
||||
$dataLayerContent = $matches[1] . ']';
|
||||
}
|
||||
preg_match('/var dl4Objects ?= ?(.*?)];/', $dLBlockHtml, $matchesGa4);
|
||||
if (count($matchesGa4) == 2) {
|
||||
$dataLayerContentGa4 = $matchesGa4[1] . ']';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ga4ServerSideViewItemListContent = '';
|
||||
$ga4ServerSideViewItemListBlock = $response->getLayout()->getBlock('weltpixel-ga4-server-view-item-list');
|
||||
if ($ga4ServerSideViewItemListBlock) {
|
||||
$ga4ServerSideViewItemListBlockHtml = $ga4ServerSideViewItemListBlock->toHtml();
|
||||
preg_match('/<input.*id="wp_ga4_server_side_view_item_list".*value="(.*?)"/', $ga4ServerSideViewItemListBlockHtml, $matchesGa4ServerSide);
|
||||
if (count($matchesGa4ServerSide) == 2) {
|
||||
$ga4ServerSideViewItemListContent = $matchesGa4ServerSide[1];
|
||||
}
|
||||
}
|
||||
|
||||
$tags = [];
|
||||
$blocksList = [$productsList,$leftNavBlockHtml];
|
||||
foreach ($blocksList as $block) {
|
||||
if ($block instanceof \Magento\Framework\DataObject\IdentityInterface) {
|
||||
$tags = array_merge($tags, $block->getIdentities());
|
||||
}
|
||||
}
|
||||
$tags = array_unique($tags);
|
||||
|
||||
return $this->_resultJsonFactory->create()->setData(
|
||||
[
|
||||
'success' => true,
|
||||
'html' => [
|
||||
'products_list' => $productsListBlockHtml,
|
||||
'filters' => $leftNavBlockHtml,
|
||||
'dataLayer' => $dataLayerContent,
|
||||
'dataLayerGA4' => $dataLayerContentGa4,
|
||||
'ga4ServerSideItemListHash' => $ga4ServerSideViewItemListContent
|
||||
]
|
||||
]
|
||||
)->setHeader('X-Magento-Tags', implode(',', $tags));
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user