Skip to content

Commit 72f63fd

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-53037' into EPAM-PR-44
2 parents 5479ece + 51cf589 commit 72f63fd

File tree

1 file changed

+22
-0
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product

1 file changed

+22
-0
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function execute()
159159
if ($redirectBack === 'duplicate') {
160160
$product->unsetData('quantity_and_stock_status');
161161
$newProduct = $this->productCopier->copy($product);
162+
$this->checkUniqueAttributes($product);
162163
$this->messageManager->addSuccessMessage(__('You duplicated the product.'));
163164
}
164165
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -343,4 +344,25 @@ private function persistMediaData(ProductInterface $product, array $data)
343344

344345
return $data;
345346
}
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+
}
346368
}

0 commit comments

Comments
 (0)