8
8
9
9
namespace Magento \CatalogUrlRewrite \Plugin \Webapi \Controller \Rest ;
10
10
11
+ use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
13
use Magento \Framework \Webapi \Rest \Request as RestRequest ;
13
14
18
19
*/
19
20
class InputParamsResolver
20
21
{
22
+ const SAVE_REWRITES_HISTORY = 'save_rewrites_history ' ;
23
+
21
24
/**
22
25
* @var RestRequest
23
26
*/
@@ -32,7 +35,7 @@ public function __construct(RestRequest $request)
32
35
}
33
36
34
37
/**
35
- * Add 'save_rewrites_history' param to the product data
38
+ * Add 'save_rewrites_history' param to the product and category data
36
39
*
37
40
* @see \Magento\CatalogUrlRewrite\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper
38
41
* @param \Magento\Webapi\Controller\Rest\InputParamsResolver $subject
@@ -47,12 +50,27 @@ public function afterResolve(\Magento\Webapi\Controller\Rest\InputParamsResolver
47
50
$ requestBodyParams = $ this ->request ->getBodyParams ();
48
51
49
52
if ($ this ->isProductSaveCalled ($ serviceClassName , $ serviceMethodName )
50
- && $ this ->isCustomAttributesExists ($ requestBodyParams )) {
53
+ && $ this ->isCustomAttributesExists ($ requestBodyParams, ' product ' )) {
51
54
foreach ($ requestBodyParams ['product ' ]['custom_attributes ' ] as $ attribute ) {
52
- if ($ attribute ['attribute_code ' ] === ' save_rewrites_history ' ) {
55
+ if ($ attribute ['attribute_code ' ] === self :: SAVE_REWRITES_HISTORY ) {
53
56
foreach ($ result as $ resultItem ) {
54
57
if ($ resultItem instanceof \Magento \Catalog \Model \Product) {
55
- $ resultItem ->setData ('save_rewrites_history ' , (bool )$ attribute ['value ' ]);
58
+ $ resultItem ->setData (self ::SAVE_REWRITES_HISTORY , (bool )$ attribute ['value ' ]);
59
+ break 2 ;
60
+ }
61
+ }
62
+ break ;
63
+ }
64
+ }
65
+ }
66
+
67
+ if ($ this ->isCategorySaveCalled ($ serviceClassName , $ serviceMethodName )
68
+ && $ this ->isCustomAttributesExists ($ requestBodyParams , 'category ' )) {
69
+ foreach ($ requestBodyParams ['category ' ]['custom_attributes ' ] as $ attribute ) {
70
+ if ($ attribute ['attribute_code ' ] === self ::SAVE_REWRITES_HISTORY ) {
71
+ foreach ($ result as $ resultItem ) {
72
+ if ($ resultItem instanceof \Magento \Catalog \Model \Category) {
73
+ $ resultItem ->setData (self ::SAVE_REWRITES_HISTORY , (bool )$ attribute ['value ' ]);
56
74
break 2 ;
57
75
}
58
76
}
@@ -75,14 +93,27 @@ private function isProductSaveCalled(string $serviceClassName, string $serviceMe
75
93
return $ serviceClassName === ProductRepositoryInterface::class && $ serviceMethodName === 'save ' ;
76
94
}
77
95
96
+ /**
97
+ * Check that category save method called
98
+ *
99
+ * @param string $serviceClassName
100
+ * @param string $serviceMethodName
101
+ * @return bool
102
+ */
103
+ private function isCategorySaveCalled (string $ serviceClassName , string $ serviceMethodName ): bool
104
+ {
105
+ return $ serviceClassName === CategoryRepositoryInterface::class && $ serviceMethodName === 'save ' ;
106
+ }
107
+
78
108
/**
79
109
* Check is any custom options exists in product data
80
110
*
81
111
* @param array $requestBodyParams
112
+ * @param string $entityCode
82
113
* @return bool
83
114
*/
84
- private function isCustomAttributesExists (array $ requestBodyParams ): bool
115
+ private function isCustomAttributesExists (array $ requestBodyParams, string $ entityCode ): bool
85
116
{
86
- return !empty ($ requestBodyParams [' product ' ]['custom_attributes ' ]);
117
+ return !empty ($ requestBodyParams [$ entityCode ]['custom_attributes ' ]);
87
118
}
88
119
}
0 commit comments