12
12
use Magento \Catalog \Model \Product as ProductModel ;
13
13
use Magento \Catalog \Model \ProductFactory ;
14
14
use Magento \Eav \Api \Data \AttributeInterface ;
15
+ use Magento \Framework \App \ObjectManager ;
16
+ use Magento \Framework \App \RequestInterface ;
15
17
use Magento \Framework \AuthorizationInterface ;
16
18
use Magento \Framework \Exception \AuthorizationException ;
17
19
use Magento \Framework \Exception \NoSuchEntityException ;
@@ -32,14 +34,24 @@ class Authorization
32
34
*/
33
35
private $ productFactory ;
34
36
37
+ /**
38
+ * @var RequestInterface
39
+ */
40
+ protected $ request ;
41
+
35
42
/**
36
43
* @param AuthorizationInterface $authorization
37
44
* @param ProductFactory $factory
45
+ * @param RequestInterface|null $request
38
46
*/
39
- public function __construct (AuthorizationInterface $ authorization , ProductFactory $ factory )
40
- {
47
+ public function __construct (
48
+ AuthorizationInterface $ authorization ,
49
+ ProductFactory $ factory ,
50
+ ?RequestInterface $ request = null
51
+ ) {
41
52
$ this ->authorization = $ authorization ;
42
53
$ this ->productFactory = $ factory ;
54
+ $ this ->request = $ request ?: ObjectManager::getInstance ()->get (RequestInterface::class);;
43
55
}
44
56
45
57
/**
@@ -121,6 +133,10 @@ private function hasProductChanged(ProductModel $product, ?array $oldProduct = n
121
133
if (!array_key_exists ($ designAttribute , $ attributes )) {
122
134
continue ;
123
135
}
136
+ $ useDefaults = (array ) $ this ->request ->getPost ('use_default ' , []);
137
+ if (isset ($ useDefaults [$ designAttribute ]) && $ useDefaults [$ designAttribute ]) {
138
+ continue ;
139
+ }
124
140
$ attribute = $ attributes [$ designAttribute ];
125
141
$ oldValues = $ this ->fetchOldValues ($ attribute , $ oldProduct );
126
142
try {
0 commit comments