Skip to content

Commit

Permalink
Merge branch '4.x' into 5.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
#	composer.lock
#	src/elements/Order.php
#	src/services/Carts.php
#	src/templates/products/_variant_matrix.twig
  • Loading branch information
lukeholder committed May 22, 2024
2 parents 9d6eb0a + b3dc067 commit 55c3f01
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/behaviors/CustomerAddressBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use craft\elements\User;
use craft\events\DefineRulesEvent;
use yii\base\Behavior;
use yii\base\InvalidConfigException;

/**
* Customer address behavior.
Expand Down Expand Up @@ -40,6 +41,7 @@ public function events(): array

/**
* @param DefineRulesEvent $event
* @throws InvalidConfigException
*/
public function defineRules(DefineRulesEvent $event): void
{
Expand Down
24 changes: 16 additions & 8 deletions src/services/Carts.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ public function restorePreviousCartForCurrentUser(): void
$currentUser = Craft::$app->getUser()->getIdentity();
$currentStoreId = Plugin::getInstance()->getStores()->getCurrentStore()->id;

if (!$currentUser) {
return;
}

// If the current cart is empty see if the logged-in user has a previous cart
// Get any cart that is not empty, is not trashed or complete, and belongings to the user
/** @var Order|null $previousCartsWithLineItems */
Expand Down Expand Up @@ -370,17 +374,21 @@ public function restorePreviousCartForCurrentUser(): void
->storeId($currentStoreId)
->one();

if ($currentUser &&
$previousCartsWithLineItems
) {
// Restore previous cart that has line items
$this->_cart = $previousCartsWithLineItems;
$this->setSessionCartNumber($previousCartsWithLineItems->number);
} elseif ($currentUser && $currentCartInSession) {
/**
* Cart restoring preference order:
* 1. Give the cart in session to the current customer if they are logging in and there are items in the cart
* 2. Restore a previous cart belonging to the customer that has line items
* 3. Restore any other previous cart for the customer
*/
if ($currentCartInSession) {
// Give the cart to the current customer if they are logging in and there are items in the cart
// Call get cart as this will switch the user and save it if needed
$this->getCart();
} elseif ($currentUser && $anyPreviousCart) {
} elseif ($previousCartsWithLineItems) {
// Restore previous cart that has line items
$this->_cart = $previousCartsWithLineItems;
$this->setSessionCartNumber($previousCartsWithLineItems->number);
} elseif ($anyPreviousCart) {
// Finally try to restore any other previous cart for the customer
$this->_cart = $anyPreviousCart;
$this->setSessionCartNumber($anyPreviousCart->number);
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/variantmatrix/dist/VariantMatrix.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/variantmatrix/dist/VariantMatrix.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/web/assets/variantmatrix/src/VariantMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@
// }

this.$container.children('input[name$="[enabled]"]:first').val('');
this.$container.addClass('disabled');
this.$container.addClass('disabled-entry');

setTimeout(
$.proxy(function () {
Expand All @@ -607,7 +607,7 @@

enable: function () {
this.$container.children('input[name$="[enabled]"]:first').val('1');
this.$container.removeClass('disabled');
this.$container.removeClass('disabled-entry');

setTimeout(
$.proxy(function () {
Expand Down Expand Up @@ -645,7 +645,7 @@
this.$actionMenu
.find('a[data-action=disable]:first')
.parent()
.removeClass('disabled');
.removeClass('disabled-entry');
},

isDefault: function () {
Expand Down

0 comments on commit 55c3f01

Please sign in to comment.