Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fix-3326
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
lukeholder committed Nov 22, 2023
2 parents 679bb47 + 333c0f9 commit a6f8831
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 39 deletions.
4 changes: 2 additions & 2 deletions example-templates/dist/shop/customer/cards.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
</div>

{# Provide a management link for Stripe-provided payment sources: #}
{% if className(gateway) == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' %}
{% if className(gateway) == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' and gateway['billingPortalUrl'] is defined %}
<div class="mt-2">
<a class="text-blue-500 hover:text-blue-600" href="{{ gateway.billingPortalUrl(currentUser) }}">Manage on Stripe &rarr;</a>
<a class="text-blue-500 hover:text-blue-600" href="{{ gateway.getBillingPortalUrl(currentUser) }}">Manage on Stripe &rarr;</a>
</div>
{% endif %}
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions example-templates/src/shop/customer/cards.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
</div>

{# Provide a management link for Stripe-provided payment sources: #}
{% if className(gateway) == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' %}
{% if className(gateway) == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' and gateway['billingPortalUrl'] is defined %}
<div class="mt-2">
<a class="[[classes.a]]" href="{{ gateway.billingPortalUrl(currentUser) }}">Manage on Stripe &rarr;</a>
<a class="[[classes.a]]" href="{{ gateway.getBillingPortalUrl(currentUser) }}">Manage on Stripe &rarr;</a>
</div>
{% endif %}
{% endfor %}
Expand Down
14 changes: 7 additions & 7 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ public function getCustomerLinkHtml(): string
public function getOrderStatusHtml(): string
{
if ($status = $this->getOrderStatus()) {
return '<span class="commerceStatusLabel"><span class="status ' . $status->color . '"></span> ' . $status->name . '</span>';
return '<span class="commerceStatusLabel nowrap"><span class="status ' . $status->color . '"></span>' . $status->name . '</span>';
}

return '';
Expand All @@ -2469,10 +2469,10 @@ public function getOrderStatusHtml(): string
public function getPaidStatusHtml(): string
{
return match ($this->getPaidStatus()) {
self::PAID_STATUS_OVERPAID => '<span class="commerceStatusLabel"><span class="status blue"></span> ' . Craft::t('commerce', 'Overpaid') . '</span>',
self::PAID_STATUS_PAID => '<span class="commerceStatusLabel"><span class="status green"></span> ' . Craft::t('commerce', 'Paid') . '</span>',
self::PAID_STATUS_PARTIAL => '<span class="commerceStatusLabel"><span class="status orange"></span> ' . Craft::t('commerce', 'Partial') . '</span>',
self::PAID_STATUS_UNPAID => '<span class="commerceStatusLabel"><span class="status red"></span> ' . Craft::t('commerce', 'Unpaid') . '</span>',
self::PAID_STATUS_OVERPAID => '<span class="commerceStatusLabel nowrap"><span class="status blue"></span>' . Craft::t('commerce', 'Overpaid') . '</span>',
self::PAID_STATUS_PAID => '<span class="commerceStatusLabel nowrap"><span class="status green"></span>' . Craft::t('commerce', 'Paid') . '</span>',
self::PAID_STATUS_PARTIAL => '<span class="commerceStatusLabel nowrap"><span class="status orange"></span>' . Craft::t('commerce', 'Partial') . '</span>',
self::PAID_STATUS_UNPAID => '<span class="commerceStatusLabel nowrap"><span class="status red"></span>' . Craft::t('commerce', 'Unpaid') . '</span>',
default => '',
};
}
Expand Down Expand Up @@ -2926,7 +2926,7 @@ public function setShippingAddress(AddressElement|array|null $address): void

// Ensure that address can only belong to this order
if ($address->ownerId != $this->id) {
throw new InvalidArgumentException('Can not set a shipping address on the order that is is not owned by the order.');
throw new InvalidArgumentException('Can not set a shipping address on the order that is not owned by the order.');
}

$this->shippingAddressId = $address->id;
Expand Down Expand Up @@ -3024,7 +3024,7 @@ public function setBillingAddress(AddressElement|array|null $address): void

// Ensure that address can only belong to this order
if ($address->ownerId !== $this->id) {
throw new InvalidArgumentException('Can not set a billing address on the order that is is not owned by the order.');
throw new InvalidArgumentException('Can not set a billing address on the order that is not owned by the order.');
}

$address->ownerId = $this->id;
Expand Down
1 change: 0 additions & 1 deletion src/elements/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ function($attribute, $params, Validator $validator) use ($lineItem, $getQty) {
}
},
],
[['qty'], 'integer', 'min' => 1, 'skipOnError' => false],
];
}

Expand Down
5 changes: 2 additions & 3 deletions src/elements/db/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,12 +1126,11 @@ private function _applyHasVariantParam(): void

$variantQuery->limit = null;
$variantQuery->select('commerce_variants.productId');
$productIds = $variantQuery->asArray()->column();

// Remove any blank product IDs (if any)
$productIds = array_filter($productIds);
$variantQuery->andWhere(['not', ['commerce_variants.productId' => null]]);

$this->subQuery->andWhere(['commerce_products.id' => array_values($productIds)]);
$this->subQuery->andWhere(['commerce_products.id' => $variantQuery]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/elements/db/VariantQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,11 @@ private function _applyHasProductParam(): void

$productQuery->limit = null;
$productQuery->select('commerce_products.id');
$productIds = $productQuery->column();

// Remove any blank product IDs (if any)
$productIds = array_filter($productIds);
$this->subQuery->andWhere(['commerce_variants.productId' => $productIds]);
$productQuery->andWhere(['not', ['commerce_products.id' => null]]);

$this->subQuery->andWhere(['commerce_variants.productId' => $productQuery]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/models/LineItemStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getCpEditUrl(): string

public function getLabelHtml(): string
{
return sprintf('<span class="commerceStatusLabel"><span class="status %s"></span>%s</span>', $this->color, Html::encode($this->name));
return sprintf('<span class="commerceStatusLabel nowrap"><span class="status %s"></span>%s</span>', $this->color, Html::encode($this->name));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/models/OrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function getEmails(): array

public function getLabelHtml(): string
{
return sprintf('<span class="commerceStatusLabel"><span class="status %s"></span>%s</span>', $this->color, Html::encode($this->getDisplayName()));
return sprintf('<span class="commerceStatusLabel nowrap"><span class="status %s"></span>%s</span>', $this->color, Html::encode($this->getDisplayName()));
}

/**
Expand Down
44 changes: 31 additions & 13 deletions src/services/Carts.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ public function init()
$this->cartCookie = Craft::cookieConfig($this->cartCookie);

$session = Craft::$app->getSession();
$requestCookies = $request->getCookies();

// If we have a cart cookie, assign it to the cart number.
// Also check pre Commerce 4.0 for a cart number in the session just in case.
if ($requestCookies->has($this->cartCookie['name'])) {
$this->setSessionCartNumber($requestCookies->getValue($this->cartCookie['name']));
} elseif (($session->getHasSessionId() || $session->getIsActive()) && $session->has('commerce_cart')) {
if (($session->getHasSessionId() || $session->getIsActive()) && $session->has('commerce_cart')) {
$this->setSessionCartNumber($session->get('commerce_cart'));
$session->remove('commerce_cart');
}
Expand All @@ -116,7 +112,7 @@ public function getCart(bool $forceSave = false): Order
// If there is no cart set for this request, and we can't get a cart from session, create one.
if (!isset($this->_cart) && !$this->_cart = $this->_getCart()) {
$this->_cart = new Order();
$this->_cart->number = $this->getSessionCartNumber();
$this->_cart->number = $this->generateCartNumber();
if ($currentUser) {
$this->_cart->setCustomer($currentUser); // Will ensure the email is also set
}
Expand Down Expand Up @@ -265,10 +261,24 @@ public function getHasSessionCartNumber(): bool
*/
protected function getSessionCartNumber(): string
{
if (!Craft::$app->getRequest()->getIsConsoleRequest()) {
$request = Craft::$app->getRequest();
$requestCookies = $request->getCookies();

if (!$this->_cartNumber && $cookieNumber = $requestCookies->getValue($this->cartCookie['name'])) {
$this->_cartNumber = $cookieNumber;
}
}

if ($this->_cartNumber === null) {
$this->_cartNumber = $this->generateCartNumber();
}

/// Just in case the current cart is not the one in session, clear the cached cart.
if ($this->_cart && $this->_cart->number !== $this->_cartNumber) {
$this->_cart = null;
}

return $this->_cartNumber;
}

Expand Down Expand Up @@ -300,24 +310,32 @@ public function setSessionCartNumber(string $cartNumber): void
public function restorePreviousCartForCurrentUser(): void
{
$currentUser = Craft::$app->getUser()->getIdentity();
$cart = $this->getCart();

// 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 $previousCart */
$previousCart = Order::find()
/** @var Order|null $previousCartsWithLineItems */
$previousCartsWithLineItems = Order::find()
->customer($currentUser)
->isCompleted(false)
->hasLineItems()
->trashed(false)
->one();

/** @var Order|null $anyPreviousCart */
$anyPreviousCart = Order::find()
->customer($currentUser)
->isCompleted(false)
->trashed(false)
->one();

if ($currentUser &&
$cart->getIsEmpty() &&
$previousCart
$previousCartsWithLineItems
) {
$this->_cart = $previousCart;
$this->setSessionCartNumber($previousCart->number);
$this->_cart = $previousCartsWithLineItems;
$this->setSessionCartNumber($previousCartsWithLineItems->number);
} elseif ($currentUser && $anyPreviousCart) {
$this->_cart = $anyPreviousCart;
$this->setSessionCartNumber($anyPreviousCart->number);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/LineItemStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ public function handleChangedLineItemStatus(ConfigEvent $event): void
$statusRecord->sortOrder = $data['sortOrder'] ?? 99;
$statusRecord->default = $data['default'];
$statusRecord->uid = $statusUid;
$statusRecord->isArchived = false;
$statusRecord->dateArchived = null;

// Save the volume
$statusRecord->save(false);

if ($statusRecord->default) {
Expand Down
8 changes: 6 additions & 2 deletions src/services/OrderStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ public function handleChangedOrderStatus(ConfigEvent $event)
$statusRecord->default = $data['default'];
$statusRecord->uid = $statusUid;

// Save the volume
$statusRecord->save(false);
// Save the status
if ($wasTrashed = (bool)$statusRecord->dateDeleted) {
$statusRecord->restore();
} else {
$statusRecord->save(false);
}

$connection = Craft::$app->getDb();
// Drop them all and we will recreate the new ones.
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/web/assets/commerceui/src/js/order/apps/OrderActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
methods: {
...mapActions(['edit']),
...mapActions(['edit', 'handleTabs']),
cancel() {
window.location.reload();
Expand All @@ -69,6 +69,12 @@
}
});
// re-init the tabs after hiding the non-static ones
// see: https://github.com/craftcms/cms/issues/13911 for more details
Craft.cp.initTabs();
// and handle tabs dropdown
this.handleTabs();
// For custom tabs, if the selected tab is dynamic, find corresponding static tab and select it instead.
const $selectedTabLink = window.document.querySelector(
'#tabs a.custom-tab.sel'
Expand Down
64 changes: 64 additions & 0 deletions src/web/assets/commerceui/src/js/order/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,37 @@ export default new Vuex.Store({
let $transactionsTabContent =
window.document.querySelector('#transactionsTab');
$transactionsTabContent.classList.add('hidden');

// for the dropdown tab menu
const tabManager = Craft.cp.tabManager;
const tabsDropdownMenu = tabManager.$menuBtn.data('menubtn').menu;
const transactionsOption = tabsDropdownMenu.$container.find(
'[data-id="order-transactions"]'
);

// this will disable clicking on the transactions option in the dropdown tab menu
if (transactionsOption.length > 0) {
$(transactionsOption)
.disable()
.attr('disabled', 'disabled')
.css('pointer-events', 'none');
}

// and this is a fallback for selecting the transactions tab differently
let $prevSelectedTab = null;
let $selectedTab = tabManager.$selectedTab[0];

tabManager.on('selectTab', function (ev) {
$prevSelectedTab = $selectedTab;
$selectedTab = $(ev.$tab[0]);
});

tabsDropdownMenu.on('optionselect', function (ev) {
let $selectedOption = $(ev.selectedOption);
if ($selectedOption.data('id') === 'order-transactions') {
$prevSelectedTab.trigger('click');
}
});
},

edit({commit, state, dispatch}) {
Expand Down Expand Up @@ -330,6 +361,39 @@ export default new Vuex.Store({

// Update `editing` state
commit('updateEditing', true);

// handle duplicate content (fields) tabs
dispatch('handleTabs');
},

handleTabs({state}) {
const tabManagerMenuBtn = Craft.cp.tabManager.$menuBtn.data('menubtn');
const tabsDropdownMenu = tabManagerMenuBtn.menu;
if (tabsDropdownMenu !== undefined) {
const optionSelector =
'[id^="' + tabsDropdownMenu.menuId + '-option-"]';

const staticOptions = tabsDropdownMenu.$container.find(
optionSelector + '[data-id^="static-fields-"]'
);
const fieldsOptions = tabsDropdownMenu.$container.find(
optionSelector + '[data-id^="fields-"]'
);

if (state.editing) {
staticOptions.disable();
staticOptions.parent().addClass('hidden');

fieldsOptions.enable();
fieldsOptions.parent().removeClass('hidden');
} else {
staticOptions.enable();
staticOptions.parent().removeClass('hidden');

fieldsOptions.disable();
fieldsOptions.parent().addClass('hidden');
}
}
},

getOrder({state, commit}) {
Expand Down

0 comments on commit a6f8831

Please sign in to comment.