Skip to content

Commit

Permalink
Merge branch 'release/4.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Apr 24, 2024
2 parents 77a3164 + f820db9 commit 1655240
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Craft Commerce

## 4.5.4 - 2024-04-24

- Fixed a bug where date ranges weren’t displayed correctly on the Discounts index page. ([#3457](https://github.com/craftcms/commerce/issues/3457))
- Fixed a bug where guest carts weren’t getting assigned to users after login. ([#3445](https://github.com/craftcms/commerce/issues/3445))

## 4.5.3 - 2024-04-02

- The “Postcode Condition Formula” condition rule now allows multi-line input. ([#3147](https://github.com/craftcms/commerce/issues/3147)
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/DiscountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ public function actionTableData(): Response
$result = $sqlQuery->all();

$tableData = [];
$dateFormat = Craft::$app->getFormattingLocale()->getDateTimeFormat('short');
$dateFormat = Craft::$app->getFormattingLocale()->getDateTimeFormat('short', Locale::FORMAT_PHP);
foreach ($result as $item) {
$dateFrom = $item['dateFrom'] ? DateTimeHelper::toDateTime($item['dateFrom']) : null;
$dateTo = $item['dateTo'] ? DateTimeHelper::toDateTime($item['dateTo']) : null;
$dateRange = ($dateFrom ? $dateFrom->format($dateFormat) : '∞') . ' - ' > ($dateTo ? $dateTo->format($dateFormat) : '∞');
$dateRange = ($dateFrom ? $dateFrom->format($dateFormat) : '∞') . ' - ' . ($dateTo ? $dateTo->format($dateFormat) : '∞');

$dateRange = !$dateFrom && !$dateTo ? '∞' : $dateRange;

$tableData[] = [
Expand Down
14 changes: 14 additions & 0 deletions src/services/Carts.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,26 @@ public function restorePreviousCartForCurrentUser(): void
->trashed(false)
->one();

/** @var Order|null $currentCartInSession */
$currentCartInSession = Order::find()
->number($this->getSessionCartNumber())
->isCompleted(false)
->hasLineItems()
->trashed(false)
->one();

if ($currentUser &&
$previousCartsWithLineItems
) {
// Restore previous cart that has line items
$this->_cart = $previousCartsWithLineItems;
$this->setSessionCartNumber($previousCartsWithLineItems->number);
} elseif ($currentUser && $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) {
// Finally try to restore any other previous cart for the customer
$this->_cart = $anyPreviousCart;
$this->setSessionCartNumber($anyPreviousCart->number);
}
Expand Down
85 changes: 85 additions & 0 deletions tests/unit/helpers/CurrencyHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craftcommercetests\unit\helpers;

use Codeception\Test\Unit;
use craft\commerce\errors\CurrencyException;
use craft\commerce\helpers\Currency;
use craft\commerce\helpers\Locale;
use UnitTester;
use yii\base\InvalidConfigException;

/**
* CurrencyHelperTest
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.5.4
*/
class CurrencyHelperTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;

/**
* @param string $currency
* @param string $language
* @param string $expected
* @return void
* @throws InvalidConfigException
* @throws CurrencyException
* @dataProvider formatAsCurrencyDataProvider
*/
public function testFormatAsCurrency(string $currency, string $language, string $expected): void
{
$originalLocale = \Craft::$app->getLocale();
Locale::switchAppLanguage($language);
$amount = 1234.56;
$formattedValue = Currency::formatAsCurrency($amount, $currency);

self::assertEquals($expected, $formattedValue);
Locale::switchAppLanguage($originalLocale->getLanguageID());
}

public function formatAsCurrencyDataProvider(): array
{
return [
'USD-US' => [
'USD',
'en-US',
'$1,234.56',
],
'USD-GB' => [
'USD',
'en-GB',
'US$1,234.56',
],
'USD-FR' => [
'USD',
'fr-FR',
'1 234,56 $US',
],
'EUR-US' => [
'EUR',
'en-US',
'€1,234.56',
],
'EUR-GB' => [
'EUR',
'en-GB',
'€1,234.56',
],
'EUR-FR' => [
'EUR',
'fr-FR',
'1 234,56 €',
],
];
}
}

0 comments on commit 1655240

Please sign in to comment.