-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbfc9b5
commit c399c9d
Showing
3 changed files
with
82 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Magento\Framework\Registry; | ||
use Tweakwise\Magento2Tweakwise\Block\Product\ListProduct as Subject; | ||
use Tweakwise\Magento2Tweakwise\Helper\Cache; | ||
|
||
class ListProduct | ||
{ | ||
/** | ||
* @param RequestInterface $request | ||
* @param Cache $cacheHelper | ||
* @param LandingPageRepositoryInterface $landingPageRepository | ||
* @param Registry $registry | ||
*/ | ||
public function __construct( | ||
private readonly RequestInterface $request, | ||
private readonly Cache $cacheHelper, | ||
private readonly LandingPageRepositoryInterface $landingPageRepository, | ||
private readonly Registry $registry | ||
) { | ||
} | ||
|
||
/** | ||
* @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 = $this->registry->registry(sprintf('alp_filters_%s', $landingPageId)) ?? []; | ||
$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]; | ||
} | ||
|
||
private function isAttributeLandingRequest(): bool | ||
{ | ||
return $this->request->getModuleName() === 'emico_attributelanding'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters