Skip to content

Commit b904ee5

Browse files
committed
ACP2E-3276: Order reports showing the wrong currency symbol
1 parent 7c8bc75 commit b904ee5

File tree

2 files changed

+225
-0
lines changed

2 files changed

+225
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Directory\Test\Fixture;
20+
21+
use Magento\Directory\Model\Currency;
22+
use Magento\Framework\App\ResourceConnection;
23+
use Magento\Framework\DataObject;
24+
use Magento\Framework\Locale\FormatInterface;
25+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
26+
27+
/**
28+
* Data fixture for currency rate.
29+
*/
30+
class CurrencyRate implements RevertibleDataFixtureInterface
31+
{
32+
/**
33+
* @var FormatInterface
34+
*/
35+
private $format;
36+
37+
/**
38+
* @var Currency
39+
*/
40+
private $currency;
41+
42+
/**
43+
* @var ResourceConnection
44+
*/
45+
private $resourceConnection;
46+
47+
public function __construct(
48+
FormatInterface $format,
49+
Currency $currency,
50+
ResourceConnection $resourceConnection
51+
) {
52+
$this->format = $format;
53+
$this->currency = $currency;
54+
$this->resourceConnection = $resourceConnection;
55+
}
56+
57+
public function apply(array $data = []): ?DataObject
58+
{
59+
if (is_array($data)) {
60+
foreach ($data as $currencyCode => $rate) {
61+
foreach ($rate as $currencyTo => $value) {
62+
$value = abs((float) $this->format->getNumber($value));
63+
$data[$currencyCode][$currencyTo] = $value;
64+
}
65+
}
66+
return $this->currency->saveRates($data);
67+
}
68+
}
69+
70+
public function revert(DataObject $data): void
71+
{
72+
$connection = $this->resourceConnection->getConnection();
73+
$currencyTable = $this->resourceConnection->getTableName('directory_currency_rate');
74+
75+
foreach ($data as $currencyCode => $rate) {
76+
foreach ($rate as $currencyTo) {
77+
$connection->delete(
78+
$currencyTable,
79+
[
80+
'currency_from = ?' => $currencyCode,
81+
'currency_to = ?' => $currencyTo,
82+
]
83+
);
84+
}
85+
}
86+
}
87+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Reports\Controller\Adminhtml\Report\Sales;
9+
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
12+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
13+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
14+
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
15+
use Magento\Customer\Test\Fixture\Customer;
16+
use Magento\Directory\Test\Fixture\CurrencyRate;
17+
use Magento\Framework\Exception\CouldNotSaveException;
18+
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Framework\Exception\NoSuchEntityException;
20+
use Magento\Framework\Exception\StateException;
21+
use Magento\Framework\View\LayoutInterface;
22+
use Magento\Quote\Api\CartManagementInterface;
23+
use Magento\Quote\Api\CartRepositoryInterface;
24+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
25+
use Magento\Quote\Test\Fixture\CustomerCart;
26+
use Magento\Sales\Api\InvoiceOrderInterface;
27+
use Magento\Store\Model\ScopeInterface;
28+
use Magento\Store\Model\Store;
29+
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
30+
use Magento\Store\Test\Fixture\Store as StoreFixture;
31+
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
32+
use Magento\TestFramework\Fixture\AppArea;
33+
use Magento\TestFramework\Fixture\AppIsolation;
34+
use Magento\TestFramework\Fixture\Config;
35+
use Magento\TestFramework\Fixture\DataFixture;
36+
use Magento\TestFramework\Fixture\DataFixtureStorage;
37+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
38+
use Magento\TestFramework\Fixture\DbIsolation;
39+
use Magento\TestFramework\Request;
40+
use Magento\TestFramework\TestCase\AbstractBackendController;
41+
42+
class AdminOrderReports extends AbstractBackendController
43+
{
44+
/**
45+
* @var DataFixtureStorage
46+
*/
47+
private $fixtures;
48+
49+
/**
50+
* @var CartManagementInterface
51+
*/
52+
private $cartManagement;
53+
54+
/**
55+
* @var InvoiceOrderInterface
56+
*/
57+
private $invoiceOrder;
58+
59+
/**
60+
* @var CartRepositoryInterface
61+
*/
62+
private $quoteRepository;
63+
64+
protected function setUp(): void
65+
{
66+
parent::setUp();
67+
$this->cartManagement = $this->_objectManager->get(CartManagementInterface::class);
68+
$this->invoiceOrder = $this->_objectManager->get(InvoiceOrderInterface::class);
69+
$this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
70+
$this->fixtures = $this->_objectManager->get(DataFixtureStorageManager::class)->getStorage();
71+
}
72+
73+
/**
74+
* @throws NoSuchEntityException
75+
* @throws CouldNotSaveException
76+
* @throws StateException
77+
* @throws LocalizedException
78+
*/
79+
#[
80+
DbIsolation(false),
81+
AppIsolation(true),
82+
AppArea('adminhtml'),
83+
Config('catalog/price/scope', Store::PRICE_SCOPE_WEBSITE),
84+
DataFixture(WebsiteFixture::class, as: 'website2'),
85+
DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'group2'),
86+
DataFixture(StoreFixture::class, ['website_id' => '$website2.id$'], 'store2'),
87+
Config('currency/options/default', 'EUR', 'website', '$website2.code$'),
88+
Config('currency/options/allow', 'EUR', 'website', '$website2.code$'),
89+
DataFixture(CurrencyRate::class, ['USD' => ['EUR' => '0.8']]),
90+
DataFixture(ProductFixture::class, ['website_ids' => [1, '$website2.id$']], as: 'p1'),
91+
DataFixture(Customer::class, ['website_id' => '$website2.id$'], as: 'customer'),
92+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'cart'),
93+
DataFixture(
94+
AddProductToCartFixture::class,
95+
['cart_id' => '$cart.id$', 'product_id' => '$p1.id$', 'qty' => 1]
96+
),
97+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$'], as: 'billingAddress'),
98+
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$'], as: 'shippingAddress'),
99+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$cart.id$']),
100+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$']),
101+
]
102+
public function testAdminOrderReportsForMultiWebsiteWithDifferentDisplayCurrency()
103+
{
104+
$cart = $this->fixtures->get('cart');
105+
$storeId = $this->fixtures->get('store2')->getId();
106+
$websiteId = (int) $this->fixtures->get('website2')->getId();
107+
108+
$cart->setStoreId($storeId);
109+
$this->quoteRepository->save($cart);
110+
111+
$orderId = $this->cartManagement->placeOrder($cart->getId());
112+
$this->assertNotEmpty($orderId);
113+
$invoiceId = $this->invoiceOrder->execute($orderId);
114+
$this->assertNotEmpty($invoiceId);
115+
116+
$this->_objectManager->create('Magento\Sales\Model\ResourceModel\Report\Order')->aggregate();
117+
118+
$beforeCurrentdate = date('m-d-Y', strtotime('-1 day'));
119+
$afterCurrentdate = date('m-d-Y', strtotime('+1 day'));
120+
121+
$requestArray = [
122+
'report_type' => 'created_at_order',
123+
'period_type' => 'day',
124+
'from' => $beforeCurrentdate,
125+
'to' => $afterCurrentdate,
126+
'show_order_statuses' => '0',
127+
'show_empty_rows' => '0',
128+
'show_actual_columns' => '0',
129+
];
130+
$filterData = base64_encode(http_build_query($requestArray));
131+
$this->dispatch("backend/reports/report_sales/sales/website/{$websiteId}/filter/{$filterData}/");
132+
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
133+
$layout = $this->_objectManager->get(LayoutInterface::class);
134+
$salesReportGrid = $layout->getBlock('adminhtml_sales_sales.grid');
135+
$blockHtml = $salesReportGrid->toHtml();
136+
$this->assertNotEmpty($blockHtml);
137+
}
138+
}

0 commit comments

Comments
 (0)