Skip to content

Commit

Permalink
Merge pull request #37 from EmicoEcommerce/beta
Browse files Browse the repository at this point in the history
Merge beta into master
  • Loading branch information
ah-net authored Dec 17, 2024
2 parents 48200b4 + 0759086 commit cffc452
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/Plugin/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Tweakwise\AttributeLandingTweakwise\Plugin\Block\Product;

use Emico\AttributeLanding\Api\LandingPageRepositoryInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Tweakwise\Magento2Tweakwise\Block\Product\ListProduct as Subject;
use Tweakwise\Magento2Tweakwise\Helper\Cache;

class ListProduct
{
/**
* @param RequestInterface $request
* @param Cache $cacheHelper
* @param LandingPageRepositoryInterface $landingPageRepository
*/
public function __construct(
private readonly RequestInterface $request,
private readonly Cache $cacheHelper,
private readonly LandingPageRepositoryInterface $landingPageRepository
) {
}

/**
* @param Subject $subject
* @param string $route
* @param array $params
* @return array
*/
public function beforeGetUrl(Subject $subject, $route = '', $params = [])
{
$landingPageId = (int)$this->request->getParam('id');
if (
!$this->isAttributeLandingRequest() ||
!$landingPageId ||
!$this->cacheHelper->personalMerchandisingCanBeApplied() ||
$route !== 'page_cache/block/esi'
) {
return [$route, $params];
}

try {
$landingPage = $this->landingPageRepository->getById($landingPageId);
} catch (NoSuchEntityException | LocalizedException $e) {
return [$route, $params];
}

$filters = $landingPage->getFilters();
$filterTemplate = $landingPage->getTweakwiseFilterTemplate();
$sortTemplate = $landingPage->getTweakwiseSortTemplate();

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

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

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

return [$route, $params];
}

/**
* @return bool
*/
private function isAttributeLandingRequest(): bool
{
return $this->request->getModuleName() === 'emico_attributelanding';
}
}
4 changes: 4 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@
type="Tweakwise\AttributeLandingTweakwise\Plugin\Block\LayeredNavigation\RenderLayered\RendererPlugin"/>
</type>

<type name="Tweakwise\Magento2Tweakwise\Block\Product\ListProduct">
<plugin name="Tweakwise_AttributeLandingTweakwise_Plugin_Block_Product_ListProduct"
type="Tweakwise\AttributeLandingTweakwise\Plugin\Block\Product\ListProduct"/>
</type>
</config>

0 comments on commit cffc452

Please sign in to comment.