Skip to content

Commit bbdc51b

Browse files
Merge pull request #9 from mageplaza/develop
Develop
2 parents 710087a + 3046f62 commit bbdc51b

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

Plugin/Controller/Category/View.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace Mageplaza\AjaxLayer\Plugin\Controller\Category;
2323

24-
use Magento\Framework\Json\Helper\Data;
2524
use Mageplaza\AjaxLayer\Helper\Data as LayerData;
2625

2726
/**
@@ -30,11 +29,6 @@
3029
*/
3130
class View
3231
{
33-
/**
34-
* @var Data
35-
*/
36-
protected $_jsonHelper;
37-
3832
/**
3933
* @var LayerData
4034
*/
@@ -43,14 +37,11 @@ class View
4337
/**
4438
* View constructor.
4539
*
46-
* @param Data $jsonHelper
4740
* @param LayerData $moduleHelper
4841
*/
4942
public function __construct(
50-
Data $jsonHelper,
5143
LayerData $moduleHelper
5244
) {
53-
$this->_jsonHelper = $jsonHelper;
5445
$this->_moduleHelper = $moduleHelper;
5546
}
5647

@@ -65,17 +56,12 @@ public function afterExecute(\Magento\Catalog\Controller\Category\View $action,
6556
if ($this->_moduleHelper->ajaxEnabled() && $action->getRequest()->isAjax()) {
6657
$navigation = $page->getLayout()->getBlock('catalog.leftnav');
6758
$products = $page->getLayout()->getBlock('category.products');
59+
$result = ['products' => $products->toHtml(), 'navigation' => $navigation->toHtml()];
6860
if ($this->_moduleHelper->getConfigValue('mpquickview/general/enabled')) {
69-
$quickView = $page->getLayout()->getBlock('mpquickview.quickview');
70-
$result = [
71-
'products' => $products->toHtml(),
72-
'navigation' => $navigation->toHtml(),
73-
'quickview' => $quickView->toHtml()
74-
];
75-
} else {
76-
$result = ['products' => $products->toHtml(), 'navigation' => $navigation->toHtml()];
61+
$quickView = $page->getLayout()->getBlock('mpquickview.quickview');
62+
$result['quickview'] = $quickView->toHtml();
7763
}
78-
$action->getResponse()->representJson($this->_jsonHelper->jsonEncode($result));
64+
$action->getResponse()->representJson(LayerData::jsonEncode($result));
7965
} else {
8066
return $page;
8167
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "mageplaza/module-ajax-layered-navigation",
33
"description": "Magento 2 Ajax Layered Navigation Extension",
44
"require": {
5-
"mageplaza/module-core": "^1.4.4"
5+
"mageplaza/module-core": "^1.4.5"
66
},
77
"type": "magento2-module",
8-
"version": "1.0.4",
8+
"version": "1.0.5",
99
"license": "proprietary",
1010
"authors": [
1111
{

view/frontend/templates/layer/view.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
?>
2222
<?php if ($block->canShowBlock()) : ?>
2323
<?php
24+
$helper = $this->helper(\Mageplaza\AjaxLayer\Helper\Data::class);
2425
$filters = $block->getFilters();
25-
$layerConfig = $this->helper(\Mageplaza\AjaxLayer\Helper\Data::class)->getLayerConfiguration($filters);
26+
$layerConfig = $helper->getLayerConfiguration($filters);
2627
$filtered = count($block->getLayer()->getState()->getFilters());
2728
?>
2829
<div class="block filter" id="layered-filter-block"
@@ -74,13 +75,15 @@
7475
});
7576
</script>
7677
<?php endif; ?>
78+
<?php if ($helper->ajaxEnabled()) : ?>
7779
<script type="text/x-magento-init">
7880
{
7981
".block-content.filter-content":{
8082
"mpAjax": <?= /** @noEscape */ $layerConfig ?>
8183
}
8284
}
8385
</script>
86+
<?php endif; ?>
8487
</div>
8588
</div>
8689
<?php endif; ?>

view/frontend/web/js/action/submit-filter.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ define(
3434

3535
return function (submitUrl, isChangeUrl) {
3636
/** save active state */
37-
var actives = [];
37+
var actives = [],
38+
data;
3839
$('.filter-options-item').each(function (index) {
3940
if ($(this).hasClass('active')) {
4041
actives.push($(this).attr('attribute'));
@@ -50,7 +51,13 @@ define(
5051
window.history.pushState({url: submitUrl}, '', submitUrl);
5152
}
5253

53-
return storage.post(submitUrl, JSON.stringify({'mp_layer': 1})).done(
54+
if (isChangeUrl){
55+
data = '{}';
56+
}else{
57+
data = JSON.stringify({'mp_layer': 1});
58+
}
59+
60+
return storage.post(submitUrl, data).done(
5461
function (response) {
5562
if (response.backUrl) {
5663
window.location = response.backUrl;

0 commit comments

Comments
 (0)