Skip to content

Commit

Permalink
Merge pull request #3878 from craftcms/bugfix/3873
Browse files Browse the repository at this point in the history
Move recalculation inside of cart controller
  • Loading branch information
lukeholder authored Feb 5, 2025
2 parents fee301f + f568ee5 commit 2088456
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug where the `commerce/cart/update-cart` action could return unnecessary validation errors. ([3873](https://github.com/craftcms/commerce/issues/3873))
- Improved logging when a user deletion is prevented due to the user having Commerce orders. ([#3686](https://github.com/craftcms/commerce/issues/3686))

## 4.8.0.1 - 2025-02-03
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ private function _returnCart(): ?Response

$updateCartSearchIndexes = Plugin::getInstance()->getSettings()->updateCartSearchIndexes;

$this->_cart->recalculate();
$this->_cart->recalculationMode = Order::RECALCULATION_MODE_NONE;

// Do not clear errors, as errors could be added to the cart before _returnCart is called.
if (!$this->_cart->validate($attributes, false) || !Craft::$app->getElements()->saveElement($this->_cart, false, false, $updateCartSearchIndexes)) {
$error = Craft::t('commerce', 'Unable to update cart.');
Expand Down Expand Up @@ -559,6 +562,8 @@ private function _returnCart(): ?Response
$this->_mutex->release($this->_mutexLockName);
}

$this->_cart->recalculationMode = Order::RECALCULATION_MODE_ALL;

return $this->asModelSuccess(
$this->_cart,
$message,
Expand Down

0 comments on commit 2088456

Please sign in to comment.