Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #184 from EmicoEcommerce/bug/pagination-issues-no-…
Browse files Browse the repository at this point in the history
…ajax

Bug/pagination issues no ajax
  • Loading branch information
Hnto authored Oct 15, 2021
2 parents 1c5208d + ec0fd7a commit c1b9cfe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
10 changes: 9 additions & 1 deletion Model/Catalog/Layer/ItemCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ public function getCollection(Category $category)
}

try {
return $this->collectionFactory->create(['navigationContext' => $this->navigationContext]);
$collection = $this->collectionFactory->create(['navigationContext' => $this->navigationContext]);

if (count($collection->getItems()) < 1) {
$collection = $this->collectionFactory
->create(['navigationContext' => $this->navigationContext->resetPagination()])
;
}

return $collection;
} catch (TweakwiseException $e) {
$this->log->critical($e);
$this->config->setTweakwiseExceptionThrown();
Expand Down
26 changes: 23 additions & 3 deletions Model/Catalog/Layer/NavigationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NavigationContext
/**
* @var ProductNavigationRequest
*/
protected $request;
protected $request = null;

/**
* @var RequestFactory
Expand All @@ -49,9 +49,9 @@ class NavigationContext
protected $client;

/**
* @var ProductNavigationResponse
* @var ProductNavigationResponse|null
*/
protected $response;
protected $response = null;

/**
* @var Url
Expand Down Expand Up @@ -150,6 +150,7 @@ public function getResponse(): ProductNavigationResponse
{
if (!$this->response) {
$request = $this->getRequest();

$this->initializeRequest($request);

$this->response = $this->client->request($request);
Expand All @@ -168,6 +169,25 @@ public function hasResponse(): bool
return $this->response !== null;
}

/**
* @return $this
*/
public function resetPagination(): self
{
$params = $this->request->getParameters();
$params['resetPagination'] = true;
$params['tn_fk_p'] = 1;
$params['tn_p'] = 1;

$this->request = null;

$request = $this->getRequest()->setParameters($params);

$this->response = null;

return $this->initializeRequest($request);
}

/**
* @param $attributeCodes
* @return Attribute[]
Expand Down
3 changes: 2 additions & 1 deletion Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ public function apply(MagentoHttpRequest $request, ProductNavigationRequest $nav
}

$page = $this->getPage($request);
if ($page) {

if ($page && (bool) $navigationRequest->getParameter('resetPagination') === false) {
$navigationRequest->setPage($page);
}

Expand Down

0 comments on commit c1b9cfe

Please sign in to comment.