Skip to content

Commit

Permalink
last added item should be removed for session after reading (#108)
Browse files Browse the repository at this point in the history
Closes #107
  • Loading branch information
kaplansin committed Dec 8, 2023
1 parent 8f4dd0d commit e778ed4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Block/Checkout/Cart/Crosssell/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,18 @@ protected function getType()

public function aroundGetLastAddedProduct(Crosssell $crossell, Closure $proceed)
{
$product = null;
$productId = $this->_getLastAddedProductId();
if ($productId) {
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
$product = null;
if ($this->lastAddedProduct === null) {
$product = null;
$productId = $this->_getLastAddedProductId();
if ($productId) {
try {
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
$product = null;
}
}
$this->lastAddedProduct = $product;
}
$this->lastAddedProduct = $product;

return $this->lastAddedProduct;
}
Expand All @@ -108,7 +110,7 @@ public function aroundGetLastAddedProduct(Crosssell $crossell, Closure $proceed)
*/
protected function _getLastAddedProductId()
{
return $this->checkoutSession->getLastAddedProductId(false);
return $this->checkoutSession->getLastAddedProductId(true);
}

/**
Expand Down

0 comments on commit e778ed4

Please sign in to comment.