Skip to content

Commit d52efeb

Browse files
committed
Merge branch '2.3-develop' of github.com:magento/magento2ce into 2.3.5-develop
2 parents 821dbed + 8a7d1fb commit d52efeb

File tree

36 files changed

+978
-450
lines changed

36 files changed

+978
-450
lines changed
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+
}

app/code/Magento/Catalog/Model/Template/Filter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
/**
1616
* Work with catalog(store, website) urls
17-
*
18-
* @package Magento\Catalog\Model\Template
1917
*/
2018
class Filter extends \Magento\Framework\Filter\Template
2119
{
@@ -30,6 +28,7 @@ class Filter extends \Magento\Framework\Filter\Template
3028
* Whether to allow SID in store directive: NO
3129
*
3230
* @var bool
31+
* @deprecated SID query parameter is not used in URLs anymore.
3332
*/
3433
protected $_useSessionInUrl = false;
3534

@@ -81,10 +80,14 @@ public function setUseAbsoluteLinks($flag)
8180
*
8281
* @param bool $flag
8382
* @return $this
83+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84+
* @deprecated SID query parameter is not used in URLs anymore.
8485
*/
8586
public function setUseSessionInUrl($flag)
8687
{
87-
$this->_useSessionInUrl = $flag;
88+
// phpcs:disable Magento2.Functions.DiscouragedFunction
89+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
90+
8891
return $this;
8992
}
9093

@@ -126,6 +129,7 @@ public function viewDirective($construction)
126129
*/
127130
public function mediaDirective($construction)
128131
{
132+
// phpcs:disable Magento2.Functions.DiscouragedFunction
129133
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
130134
return $this->_storeManager->getStore()
131135
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];

0 commit comments

Comments
 (0)