Skip to content

Commit 9f81b49

Browse files
committed
return to source, plugin added
1 parent 6fde4ba commit 9f81b49

File tree

8 files changed

+209
-292
lines changed

8 files changed

+209
-292
lines changed

app/code/Magento/CatalogUrlRewrite/Model/SetSaveRewriteHistory.php

Lines changed: 0 additions & 69 deletions
This file was deleted.

app/code/Magento/CatalogUrlRewrite/Plugin/Model/UpdateCategoryDataList.php renamed to app/code/Magento/CatalogUrlRewrite/Plugin/Model/CategorySetSaveRewriteHistory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Webapi\Rest\Request as RestRequest;
1212
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
1313

14-
class UpdateCategoryDataList
14+
class CategorySetSaveRewriteHistory
1515
{
1616
private const SAVE_REWRITES_HISTORY = 'save_rewrites_history';
1717

app/code/Magento/CatalogUrlRewrite/Plugin/Webapi/Controller/Rest/CategoryInputParamsResolver.php

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest;
10+
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\Webapi\Rest\Request as RestRequest;
13+
14+
/**
15+
* Plugin for InputParamsResolver
16+
*
17+
* Used to modify product data with save_rewrites_history flag
18+
*/
19+
class InputParamsResolver
20+
{
21+
/**
22+
* @var RestRequest
23+
*/
24+
private $request;
25+
26+
/**
27+
* @param RestRequest $request
28+
*/
29+
public function __construct(RestRequest $request)
30+
{
31+
$this->request = $request;
32+
}
33+
34+
/**
35+
* Add 'save_rewrites_history' param to the product data
36+
*
37+
* @see \Magento\CatalogUrlRewrite\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper
38+
* @param \Magento\Webapi\Controller\Rest\InputParamsResolver $subject
39+
* @param array $result
40+
* @return array
41+
*/
42+
public function afterResolve(\Magento\Webapi\Controller\Rest\InputParamsResolver $subject, array $result): array
43+
{
44+
$route = $subject->getRoute();
45+
$serviceMethodName = $route->getServiceMethod();
46+
$serviceClassName = $route->getServiceClass();
47+
$requestBodyParams = $this->request->getBodyParams();
48+
49+
if ($this->isProductSaveCalled($serviceClassName, $serviceMethodName)
50+
&& $this->isCustomAttributesExists($requestBodyParams)) {
51+
foreach ($requestBodyParams['product']['custom_attributes'] as $attribute) {
52+
if ($attribute['attribute_code'] === 'save_rewrites_history') {
53+
foreach ($result as $resultItem) {
54+
if ($resultItem instanceof \Magento\Catalog\Model\Product) {
55+
$resultItem->setData('save_rewrites_history', (bool)$attribute['value']);
56+
break 2;
57+
}
58+
}
59+
break;
60+
}
61+
}
62+
}
63+
return $result;
64+
}
65+
66+
/**
67+
* Check that product save method called
68+
*
69+
* @param string $serviceClassName
70+
* @param string $serviceMethodName
71+
* @return bool
72+
*/
73+
private function isProductSaveCalled(string $serviceClassName, string $serviceMethodName): bool
74+
{
75+
return $serviceClassName === ProductRepositoryInterface::class && $serviceMethodName === 'save';
76+
}
77+
78+
/**
79+
* Check is any custom options exists in product data
80+
*
81+
* @param array $requestBodyParams
82+
* @return bool
83+
*/
84+
private function isCustomAttributesExists(array $requestBodyParams): bool
85+
{
86+
return !empty($requestBodyParams['product']['custom_attributes']);
87+
}
88+
}

app/code/Magento/CatalogUrlRewrite/Plugin/Webapi/Controller/Rest/ProductInputParamsResolver.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)