Skip to content

Commit 626358b

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 52567b9 + edc5c90 commit 626358b

File tree

18 files changed

+930
-178
lines changed

18 files changed

+930
-178
lines changed

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

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
*/
1515
class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
1616
{
17-
/**
18-
* Api URL
19-
*/
2017
const API_URL = 'https://image-charts.com/chart';
2118

2219
/**
@@ -190,8 +187,8 @@ public function getChartUrl($directUrl = true)
190187
$params = [
191188
'cht' => 'lc',
192189
'chls' => '7',
193-
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
194-
'chm' => 'B,f4d4b2,0,0,0',
190+
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
191+
'chm' => 'B,f4d4b2,0,0,0',
195192
'chco' => 'db4814',
196193
'chxs' => '0,0,11|1,0,11',
197194
'chma' => '15,15,15,15'
@@ -237,7 +234,7 @@ public function getChartUrl($directUrl = true)
237234
case '1y':
238235
case '2y':
239236
$d = $dateStart->format('Y-m');
240-
$dateStart->modify('+1 month');
237+
$dateStart->modify('first day of next month');
241238
break;
242239
default:
243240
$d = $dateStart->format('Y-m-d H:00');
@@ -300,20 +297,23 @@ public function getChartUrl($directUrl = true)
300297
$minvalue = min($localminvalue);
301298

302299
// default values
303-
$yLabels = [];
304300
$miny = 0;
305301
$maxy = 0;
306302
$yorigin = 0;
303+
$xAxis = 'x';
304+
$xAxisIndex = 0;
305+
$yAxisIndex = 1;
307306

308307
if ($minvalue >= 0 && $maxvalue >= 0) {
309308
if ($maxvalue > 10) {
310-
$p = pow(10, $this->_getPow((int) $maxvalue));
309+
$p = pow(10, $this->_getPow((int)$maxvalue));
311310
$maxy = ceil($maxvalue / $p) * $p;
312-
$yLabels = range($miny, $maxy, $p);
311+
$yRange = "$yAxisIndex,$miny,$maxy,$p";
313312
} else {
314313
$maxy = ceil($maxvalue + 1);
315-
$yLabels = range($miny, $maxy, 1);
314+
$yRange = "$yAxisIndex,$miny,$maxy,1";
316315
}
316+
$params['chxr'] = $yRange;
317317
$yorigin = 0;
318318
}
319319

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

342342
$params['chd'] .= $buffer;
343343

344-
$valueBuffer = [];
345-
346344
if (count($this->_axisLabels) > 0) {
347345
$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);
346+
$this->formatAxisLabelDate($xAxis, (string)$timezoneLocal);
347+
$customAxisLabels = $xAxisIndex . ":|" . implode('|', $this->_axisLabels[$xAxis]);
348+
$params['chxl'] = $customAxisLabels . $dataSetdelimiter;
360349
}
361350

362351
// chart size
@@ -368,7 +357,7 @@ public function getChartUrl($directUrl = true)
368357
foreach ($params as $name => $value) {
369358
$p[] = $name . '=' . urlencode($value);
370359
}
371-
return (string) self::API_URL . '?' . implode('&', $p);
360+
return (string)self::API_URL . '?' . implode('&', $p);
372361
}
373362
$gaData = urlencode(base64_encode(json_encode($params)));
374363
$gaHash = $this->_dashboardData->getChartDataHash($gaData);
@@ -392,7 +381,7 @@ private function formatAxisLabelDate($idx, $timezoneLocal)
392381
switch ($this->getDataHelper()->getParam('period')) {
393382
case '24h':
394383
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
395-
$period->setTime((int) $period->format('H'), 0, 0),
384+
$period->setTime((int)$period->format('H'), 0, 0),
396385
\IntlDateFormatter::NONE,
397386
\IntlDateFormatter::SHORT
398387
);
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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\Catalog\Model\Product\Webapi;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Framework\Webapi\Request;
12+
use Magento\Framework\Webapi\Rest\Request\DeserializerInterface;
13+
14+
/**
15+
* Class for checking empty array and remove it from the output result
16+
*/
17+
class ProductOutputProcessor
18+
{
19+
/**
20+
* @var Request
21+
*/
22+
private $request;
23+
24+
/**
25+
* @var DeserializerInterface
26+
*/
27+
private $deserializer;
28+
29+
/**
30+
* @param Request $request
31+
* @param DeserializerInterface $deserializer
32+
*/
33+
public function __construct(
34+
Request $request,
35+
DeserializerInterface $deserializer
36+
) {
37+
$this->request = $request;
38+
$this->deserializer = $deserializer;
39+
}
40+
41+
/**
42+
* Removing attribute from the result array if its null or empty
43+
*
44+
* @param ProductInterface $product
45+
* @param array $result
46+
* @return array
47+
*/
48+
public function execute(
49+
ProductInterface $product,
50+
array $result
51+
): array {
52+
$requestContent = $this->request->getContent() ?? [];
53+
if (empty($requestContent)) {
54+
return $result;
55+
}
56+
$requestContentDetails = (array)$this->deserializer->deserialize($requestContent);
57+
$requestProductList = $this->extractProductList($requestContentDetails);
58+
59+
$requestProductList = array_filter(
60+
$requestProductList,
61+
function ($requestProduct) use ($product) {
62+
return isset($requestProduct['sku']) && $requestProduct['sku'] === $product->getSku();
63+
}
64+
);
65+
66+
if (empty($requestProductList)) {
67+
return $result;
68+
}
69+
70+
$requestProduct = current($requestProductList);
71+
72+
if (empty($product->getTierPrices()) && !array_key_exists('tier_prices', $requestProduct)) {
73+
unset($result['tier_prices']);
74+
}
75+
76+
if (empty($product->getProductLinks()) && !array_key_exists('product_links', $requestProduct)) {
77+
unset($result['product_links']);
78+
}
79+
80+
return $result;
81+
}
82+
83+
/**
84+
* Extract product list from the request content details
85+
*
86+
* @param array $contentDetails
87+
* @return array
88+
*/
89+
private function extractProductList(array $contentDetails): array
90+
{
91+
$productList = [];
92+
$arrayIterator = new \RecursiveArrayIterator($contentDetails);
93+
$iterator = new \RecursiveIteratorIterator($arrayIterator, \RecursiveIteratorIterator::SELF_FIRST);
94+
foreach ($iterator as $iteratorKey => $iteratorValue) {
95+
if ($iteratorKey === 'product') {
96+
array_push($productList, $iteratorValue);
97+
}
98+
}
99+
return $productList;
100+
}
101+
}

0 commit comments

Comments
 (0)