Skip to content

Commit

Permalink
fix: ALP varnish bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-net committed Oct 24, 2024
1 parent c9de69b commit 9fbbe54
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

declare(strict_types=1);

namespace Tweakwise\AttributeLandingTweakwise\Block\Product;

use Emico\AttributeLanding\Model\LandingPageRepository;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Block\Product\Context;
use Magento\Catalog\Helper\Output as OutputHelper;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\Helper\PostHelper;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Url\Helper\Data;
use Tweakwise\AttributeLandingTweakwise\Model\AjaxResultInitializer\LandingPageInitializer;
use Tweakwise\Magento2Tweakwise\Block\Product\ListProduct as TweakwiseListProduct;
use Tweakwise\AttributeLandingTweakwise\Model\Catalog\Layer\Url\RewriteResolver\LandingPageResolver;
use Tweakwise\Magento2Tweakwise\Helper\Cache;
use Tweakwise\Magento2Tweakwise\Model\Config;

class ListProduct extends TweakwiseListProduct
{
public function __construct(
Context $context,
PostHelper $postDataHelper,
Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository,
Data $urlHelper,
private readonly Config $tweakwiseConfig,
private readonly CookieManagerInterface $cookieManager,
private readonly Cache $cacheHelper,
private readonly Registry $registry,
private readonly RequestInterface $request,
private LandingPageRepository $landingPageRepository,
array $data = [],
?OutputHelper $outputHelper = null
) {
parent::__construct(
$context,
$postDataHelper,
$layerResolver,
$categoryRepository,
$urlHelper,
$tweakwiseConfig,
$cookieManager,
$cacheHelper,
$registry,
$request,
$data,
$outputHelper
);
}

/**
* @param string $route
* @param array $params
* @return string
*/

public function getUrl($route = '', $params = [], $queryParams = [])
{
if ($this->request->getModuleName() === 'emico_attributelanding') {
$landingPageId = (int)$this->request->getParam('id');
if (!empty($landingPageId)) {
$landingPage = $this->landingPageRepository->getById($landingPageId);
$filters = $this->registry->registry('tw_filters' . $landingPageId);
$filterTemplate = $landingPage->getTweakwiseFilterTemplate();
$sortTemplate = $landingPage->getTweakwiseSortTemplate();

foreach ($filters as $filter) {
$queryParams[$filter->getFacet()] = $filter->getValue();
}

if (!empty($filterTemplate)) {
$queryParams['tn_ft'] = $filterTemplate;
}

if (!empty($sortTemplate)) {
$queryParams['tn_st'] = $sortTemplate;
}
}
}

return parent::getUrl($route, $params, $queryParams);
}
}
1 change: 1 addition & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Emico\AttributeLanding\Model\FilterHider\FilterHiderInterface" type="Tweakwise\AttributeLandingTweakwise\Model\FilterHider\TweakwiseFilterHider"/>
<preference for="Tweakwise\Magento2Tweakwise\Block\Product\ListProduct" type="Tweakwise\AttributeLandingTweakwise\Block\Product\ListProduct"/>
<type name="Emico\AttributeLanding\Model\FilterApplier\AggregateFilterApplier">
<arguments>
<argument name="appliers" xsi:type="array">
Expand Down

0 comments on commit 9fbbe54

Please sign in to comment.