File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
app/code/Magento/Catalog/Controller/Adminhtml/Product Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ public function execute()
159
159
if ($ redirectBack === 'duplicate ' ) {
160
160
$ product ->unsetData ('quantity_and_stock_status ' );
161
161
$ newProduct = $ this ->productCopier ->copy ($ product );
162
+ $ this ->checkUniqueAttributes ($ product );
162
163
$ this ->messageManager ->addSuccessMessage (__ ('You duplicated the product. ' ));
163
164
}
164
165
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
@@ -343,4 +344,25 @@ private function persistMediaData(ProductInterface $product, array $data)
343
344
344
345
return $ data ;
345
346
}
347
+
348
+ /**
349
+ * Check unique attributes and add error to message manager
350
+ *
351
+ * @param \Magento\Catalog\Model\Product $product
352
+ */
353
+ private function checkUniqueAttributes (\Magento \Catalog \Model \Product $ product )
354
+ {
355
+ $ uniqueLabels = [];
356
+ foreach ($ product ->getAttributes () as $ attribute ) {
357
+ if ($ attribute ->getIsUnique () && $ attribute ->getIsUserDefined ()
358
+ && $ product ->getData ($ attribute ->getAttributeCode ()) !== null
359
+ ) {
360
+ $ uniqueLabels [] = $ attribute ->getDefaultFrontendLabel ();
361
+ }
362
+ }
363
+ if ($ uniqueLabels ) {
364
+ $ uniqueLabels = implode ('", " ' , $ uniqueLabels );
365
+ $ this ->messageManager ->addErrorMessage (__ ('The value of attribute(s) "%1" must be unique ' , $ uniqueLabels ));
366
+ }
367
+ }
346
368
}
You can’t perform that action at this time.
0 commit comments