Skip to content

Commit 8d79076

Browse files
committed
Merge remote-tracking branch 'origin/MC-23228' into 2.3-develop-pr104
2 parents fa7559d + a238dc5 commit 8d79076

File tree

5 files changed

+221
-23
lines changed

5 files changed

+221
-23
lines changed

app/code/Magento/Backend/Block/Dashboard/Graph.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ public function getChartUrl($directUrl = true)
190190
$params = [
191191
'cht' => 'lc',
192192
'chls' => '7',
193-
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
194-
'chm' => 'B,f4d4b2,0,0,0',
193+
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
194+
'chm' => 'B,f4d4b2,0,0,0',
195195
'chco' => 'db4814',
196196
'chxs' => '0,0,11|1,0,11',
197197
'chma' => '15,15,15,15'
@@ -237,7 +237,7 @@ public function getChartUrl($directUrl = true)
237237
case '1y':
238238
case '2y':
239239
$d = $dateStart->format('Y-m');
240-
$dateStart->modify('+1 month');
240+
$dateStart->modify('first day of next month');
241241
break;
242242
default:
243243
$d = $dateStart->format('Y-m-d H:00');
@@ -300,20 +300,23 @@ public function getChartUrl($directUrl = true)
300300
$minvalue = min($localminvalue);
301301

302302
// default values
303-
$yLabels = [];
304303
$miny = 0;
305304
$maxy = 0;
306305
$yorigin = 0;
306+
$xAxis = 'x';
307+
$xAxisIndex = 0;
308+
$yAxisIndex = 1;
307309

308310
if ($minvalue >= 0 && $maxvalue >= 0) {
309311
if ($maxvalue > 10) {
310-
$p = pow(10, $this->_getPow((int) $maxvalue));
312+
$p = pow(10, $this->_getPow((int)$maxvalue));
311313
$maxy = ceil($maxvalue / $p) * $p;
312-
$yLabels = range($miny, $maxy, $p);
314+
$yRange = "$yAxisIndex,$miny,$maxy,$p";
313315
} else {
314316
$maxy = ceil($maxvalue + 1);
315-
$yLabels = range($miny, $maxy, 1);
317+
$yRange = "$yAxisIndex,$miny,$maxy,1";
316318
}
319+
$params['chxr'] = $yRange;
317320
$yorigin = 0;
318321
}
319322

@@ -341,22 +344,11 @@ public function getChartUrl($directUrl = true)
341344

342345
$params['chd'] .= $buffer;
343346

344-
$valueBuffer = [];
345-
346347
if (count($this->_axisLabels) > 0) {
347348
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
348-
$indexid = 0;
349-
foreach ($this->_axisLabels as $idx => $labels) {
350-
if ($idx == 'x') {
351-
$this->formatAxisLabelDate((string) $idx, (string) $timezoneLocal);
352-
$tmpstring = implode('|', $this->_axisLabels[$idx]);
353-
$valueBuffer[] = $indexid . ":|" . $tmpstring;
354-
} elseif ($idx == 'y') {
355-
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
356-
}
357-
$indexid++;
358-
}
359-
$params['chxl'] = implode('|', $valueBuffer);
349+
$this->formatAxisLabelDate($xAxis, (string)$timezoneLocal);
350+
$customAxisLabels = $xAxisIndex . ":|" . implode('|', $this->_axisLabels[$xAxis]);
351+
$params['chxl'] = $customAxisLabels . $dataSetdelimiter;
360352
}
361353

362354
// chart size
@@ -368,7 +360,7 @@ public function getChartUrl($directUrl = true)
368360
foreach ($params as $name => $value) {
369361
$p[] = $name . '=' . urlencode($value);
370362
}
371-
return (string) self::API_URL . '?' . implode('&', $p);
363+
return (string)self::API_URL . '?' . implode('&', $p);
372364
}
373365
$gaData = urlencode(base64_encode(json_encode($params)));
374366
$gaHash = $this->_dashboardData->getChartDataHash($gaData);
@@ -392,7 +384,7 @@ private function formatAxisLabelDate($idx, $timezoneLocal)
392384
switch ($this->getDataHelper()->getParam('period')) {
393385
case '24h':
394386
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
395-
$period->setTime((int) $period->format('H'), 0, 0),
387+
$period->setTime((int)$period->format('H'), 0, 0),
396388
\IntlDateFormatter::NONE,
397389
\IntlDateFormatter::SHORT
398390
);

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects =
461461
$startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1;
462462
$startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1;
463463
$dateStart->setDate($dateStart->format('Y'), $startMonth, $startDay);
464+
$dateStart->modify('-1 year');
464465
if ($range == '2y') {
465466
$dateStart->modify('-1 year');
466467
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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\Backend\Block\Dashboard\Tab;
9+
10+
use Magento\Backend\Block\Dashboard\Graph;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test for \Magento\Backend\Block\Dashboard\Tab\Orders class.
18+
*
19+
* @magentoAppArea adminhtml
20+
*/
21+
class OrdersTest extends TestCase
22+
{
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var LayoutInterface
30+
*/
31+
private $layout;
32+
33+
/**
34+
* @var Graph
35+
*/
36+
private $graphBlock;
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
protected function setUp()
42+
{
43+
$this->objectManager = Bootstrap::getObjectManager();
44+
$this->layout = $this->objectManager->get(LayoutInterface::class);
45+
$this->graphBlock = $this->layout->createBlock(Graph::class);
46+
}
47+
48+
/**
49+
* @magentoDataFixture Magento/Sales/_files/order_list_with_invoice.php
50+
* @dataProvider chartUrlDataProvider
51+
* @param string $period
52+
* @param string $expectedAxisRange
53+
* @return void
54+
*/
55+
public function testGetChartUrl(string $period, string $expectedAxisRange): void
56+
{
57+
$this->graphBlock->getRequest()->setParams(['period' => $period]);
58+
$ordersBlock = $this->layout->createBlock(Orders::class);
59+
$decodedChartUrl = urldecode($ordersBlock->getChartUrl());
60+
$this->assertEquals($expectedAxisRange, $this->getUrlParamData($decodedChartUrl, 'chxr'));
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function chartUrlDataProvider(): array
67+
{
68+
return [
69+
'Last 24 Hours' => ['24h', '1,0,2,1'],
70+
'Last 7 Days' => ['7d', '1,0,3,1'],
71+
'Current Month' => ['1m', '1,0,3,1'],
72+
'YTD' => ['1y', '1,0,4,1'],
73+
'2YTD' => ['2y', '1,0,4,1'],
74+
];
75+
}
76+
77+
/**
78+
* @param string $chartUrl
79+
* @param string $paramName
80+
* @return string
81+
*/
82+
private function getUrlParamData(string $chartUrl, string $paramName): string
83+
{
84+
$chartUrlSegments = explode('&', $chartUrl);
85+
foreach ($chartUrlSegments as $chartUrlSegment) {
86+
[$paramKey, $paramValue] = explode('=', $chartUrlSegment);
87+
if ($paramKey === $paramName) {
88+
return $paramValue;
89+
}
90+
}
91+
92+
return '';
93+
}
94+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
use Magento\Framework\DB\Transaction;
9+
use Magento\Framework\Stdlib\DateTime;
10+
use Magento\Sales\Api\Data\OrderInterfaceFactory;
11+
use Magento\Sales\Api\InvoiceManagementInterface;
12+
use Magento\Sales\Api\OrderRepositoryInterface;
13+
use Magento\Sales\Model\Order;
14+
use Magento\Sales\Model\Order\Invoice;
15+
use Magento\Sales\Model\OrderFactory;
16+
17+
require __DIR__ . '/order.php';
18+
19+
/** @var OrderFactory $orderFactory */
20+
$orderFactory = $objectManager->get(OrderInterfaceFactory::class);
21+
/** @var OrderRepositoryInterface $orderRepository */
22+
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
23+
/** @var InvoiceManagementInterface $invoiceManagement */
24+
$invoiceManagement = $objectManager->get(InvoiceManagementInterface::class);
25+
/** @var Transaction $transaction */
26+
$transaction = $objectManager->get(Transaction::class);
27+
28+
$dateTime = new \DateTimeImmutable();
29+
$ordersData = [
30+
[
31+
'increment_id' => '100000002',
32+
'state' => Order::STATE_PROCESSING,
33+
'status' => 'processing',
34+
'base_to_global_rate' => 1,
35+
'base_grand_total' => 120.00,
36+
'grand_total' => 120.00,
37+
'subtotal' => 120.00,
38+
'created_at' => $dateTime->modify('-1 hour')->format(DateTime::DATETIME_PHP_FORMAT),
39+
],
40+
[
41+
'increment_id' => '100000003',
42+
'state' => Order::STATE_PROCESSING,
43+
'status' => 'processing',
44+
'base_to_global_rate' => 1,
45+
'base_grand_total' => 130.00,
46+
'grand_total' => 130.00,
47+
'subtotal' => 130.00,
48+
'created_at' => $dateTime->modify('-1 day')->format(DateTime::DATETIME_PHP_FORMAT),
49+
],
50+
[
51+
'increment_id' => '100000004',
52+
'state' => Order::STATE_PROCESSING,
53+
'status' => 'processing',
54+
'base_to_global_rate' => 1,
55+
'base_grand_total' => 140.00,
56+
'grand_total' => 140.00,
57+
'subtotal' => 140.00,
58+
'created_at' => $dateTime->modify('-1 month')->format(DateTime::DATETIME_PHP_FORMAT),
59+
],
60+
[
61+
'increment_id' => '100000005',
62+
'state' => Order::STATE_PROCESSING,
63+
'status' => 'processing',
64+
'base_to_global_rate' => 1,
65+
'base_grand_total' => 150.00,
66+
'grand_total' => 150.00,
67+
'subtotal' => 150.00,
68+
'created_at' => $dateTime->modify('-1 year')->format(DateTime::DATETIME_PHP_FORMAT),
69+
],
70+
[
71+
'increment_id' => '100000006',
72+
'state' => Order::STATE_PROCESSING,
73+
'status' => 'processing',
74+
'base_to_global_rate' => 1,
75+
'base_grand_total' => 160.00,
76+
'grand_total' => 160.00,
77+
'subtotal' => 160.00,
78+
'created_at' => $dateTime->modify('-2 year')->format(DateTime::DATETIME_PHP_FORMAT),
79+
],
80+
];
81+
82+
foreach ($ordersData as $orderData) {
83+
/** @var Order $order */
84+
$order = $orderFactory->create();
85+
$order
86+
->setData($orderData)
87+
->addItem($orderItem)
88+
->setCustomerIsGuest(true)
89+
->setCustomerEmail('customer@null.com')
90+
->setBillingAddress($billingAddress)
91+
->setShippingAddress($shippingAddress)
92+
->setPayment($payment);
93+
$orderRepository->save($order);
94+
95+
/** @var Invoice $invoice */
96+
$invoice = $invoiceManagement->prepareInvoice($order);
97+
$invoice->register();
98+
$order->setIsInProcess(true);
99+
$transaction
100+
->addObject($order)
101+
->addObject($invoice)
102+
->save();
103+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
require __DIR__ . '/default_rollback.php';

0 commit comments

Comments
 (0)