@@ -54,6 +54,16 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
54
54
*/
55
55
private $ storeManager ;
56
56
57
+ /**
58
+ * @var \Magento\Framework\Escaper|null
59
+ */
60
+ private $ escaper ;
61
+
62
+ /**
63
+ * @var null|\Psr\Log\LoggerInterface
64
+ */
65
+ private $ logger ;
66
+
57
67
/**
58
68
* Save constructor.
59
69
*
@@ -63,20 +73,26 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
63
73
* @param \Magento\Catalog\Model\Product\Copier $productCopier
64
74
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager
65
75
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
76
+ * @param \Magento\Framework\Escaper|null $escaper
77
+ * @param \Psr\Log\LoggerInterface|null $logger
66
78
*/
67
79
public function __construct (
68
80
\Magento \Backend \App \Action \Context $ context ,
69
81
Product \Builder $ productBuilder ,
70
82
Initialization \Helper $ initializationHelper ,
71
83
\Magento \Catalog \Model \Product \Copier $ productCopier ,
72
84
\Magento \Catalog \Model \Product \TypeTransitionManager $ productTypeManager ,
73
- \Magento \Catalog \Api \ProductRepositoryInterface $ productRepository
85
+ \Magento \Catalog \Api \ProductRepositoryInterface $ productRepository ,
86
+ \Magento \Framework \Escaper $ escaper = null ,
87
+ \Psr \Log \LoggerInterface $ logger = null
74
88
) {
75
89
$ this ->initializationHelper = $ initializationHelper ;
76
90
$ this ->productCopier = $ productCopier ;
77
91
$ this ->productTypeManager = $ productTypeManager ;
78
92
$ this ->productRepository = $ productRepository ;
79
93
parent ::__construct ($ context , $ productBuilder );
94
+ $ this ->escaper = $ escaper ?? $ this ->_objectManager ->get (\Magento \Framework \Escaper::class);
95
+ $ this ->logger = $ logger ?? $ this ->_objectManager ->get (\Psr \Log \LoggerInterface::class);
80
96
}
81
97
82
98
/**
@@ -103,14 +119,14 @@ public function execute()
103
119
$ this ->productBuilder ->build ($ this ->getRequest ())
104
120
);
105
121
$ this ->productTypeManager ->processProduct ($ product );
106
-
107
122
if (isset ($ data ['product ' ][$ product ->getIdFieldName ()])) {
108
123
throw new \Magento \Framework \Exception \LocalizedException (
109
124
__ ('The product was unable to be saved. Please try again. ' )
110
125
);
111
126
}
112
127
113
128
$ originalSku = $ product ->getSku ();
129
+ $ canSaveCustomOptions = $ product ->getCanSaveCustomOptions ();
114
130
$ product ->save ();
115
131
$ this ->handleImageRemoveError ($ data , $ product ->getId ());
116
132
$ this ->getCategoryLinkManagement ()->assignProductToCategories (
@@ -120,20 +136,17 @@ public function execute()
120
136
$ productId = $ product ->getEntityId ();
121
137
$ productAttributeSetId = $ product ->getAttributeSetId ();
122
138
$ productTypeId = $ product ->getTypeId ();
123
-
124
- $ this ->copyToStores ($ data , $ productId );
139
+ $ extendedData = $ data ;
140
+ $ extendedData ['can_save_custom_options ' ] = $ canSaveCustomOptions ;
141
+ $ this ->copyToStores ($ extendedData , $ productId );
125
142
$ this ->messageManager ->addSuccessMessage (__ ('You saved the product. ' ));
126
143
$ this ->getDataPersistor ()->clear ('catalog_product ' );
127
144
if ($ product ->getSku () != $ originalSku ) {
128
145
$ this ->messageManager ->addNoticeMessage (
129
146
__ (
130
147
'SKU for product %1 has been changed to %2. ' ,
131
- $ this ->_objectManager ->get (
132
- \Magento \Framework \Escaper::class
133
- )->escapeHtml ($ product ->getName ()),
134
- $ this ->_objectManager ->get (
135
- \Magento \Framework \Escaper::class
136
- )->escapeHtml ($ product ->getSku ())
148
+ $ this ->escaper ->escapeHtml ($ product ->getName ()),
149
+ $ this ->escaper ->escapeHtml ($ product ->getSku ())
137
150
)
138
151
);
139
152
}
@@ -143,17 +156,18 @@ public function execute()
143
156
);
144
157
145
158
if ($ redirectBack === 'duplicate ' ) {
159
+ $ product ->unsetData ('quantity_and_stock_status ' );
146
160
$ newProduct = $ this ->productCopier ->copy ($ product );
147
161
$ this ->messageManager ->addSuccessMessage (__ ('You duplicated the product. ' ));
148
162
}
149
163
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
150
- $ this ->_objectManager -> get (\ Psr \ Log \LoggerInterface::class) ->critical ($ e );
164
+ $ this ->logger ->critical ($ e );
151
165
$ this ->messageManager ->addExceptionMessage ($ e );
152
166
$ data = isset ($ product ) ? $ this ->persistMediaData ($ product , $ data ) : $ data ;
153
167
$ this ->getDataPersistor ()->set ('catalog_product ' , $ data );
154
168
$ redirectBack = $ productId ? true : 'new ' ;
155
169
} catch (\Exception $ e ) {
156
- $ this ->_objectManager -> get (\ Psr \ Log \LoggerInterface::class) ->critical ($ e );
170
+ $ this ->logger ->critical ($ e );
157
171
$ this ->messageManager ->addErrorMessage ($ e ->getMessage ());
158
172
$ data = isset ($ product ) ? $ this ->persistMediaData ($ product , $ data ) : $ data ;
159
173
$ this ->getDataPersistor ()->set ('catalog_product ' , $ data );
@@ -242,6 +256,7 @@ protected function copyToStores($data, $productId)
242
256
->setStoreId ($ copyFrom )
243
257
->load ($ productId )
244
258
->setStoreId ($ copyTo )
259
+ ->setCanSaveCustomOptions ($ data ['can_save_custom_options ' ])
245
260
->setCopyFromView (true )
246
261
->save ();
247
262
}
0 commit comments