Skip to content

Commit

Permalink
Merge pull request #3949 from magento-epam/EPAM-PR-44
Browse files Browse the repository at this point in the history
- fixed  MAGETWO-51459: CreateCategoryEntityTest and VisualMerchandiser/RemoveProductTest fail when system message about indexers update is displayed
- fixed MAGETWO-53037: Product duplication allows to save non-unique values for product attributes
  • Loading branch information
irenelagno authored Mar 28, 2019
2 parents ee8bd11 + 8dd44d0 commit 08fbdf1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function execute()
if ($redirectBack === 'duplicate') {
$product->unsetData('quantity_and_stock_status');
$newProduct = $this->productCopier->copy($product);
$this->checkUniqueAttributes($product);
$this->messageManager->addSuccessMessage(__('You duplicated the product.'));
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
Expand Down Expand Up @@ -343,4 +344,25 @@ private function persistMediaData(ProductInterface $product, array $data)

return $data;
}

/**
* Check unique attributes and add error to message manager
*
* @param \Magento\Catalog\Model\Product $product
*/
private function checkUniqueAttributes(\Magento\Catalog\Model\Product $product)
{
$uniqueLabels = [];
foreach ($product->getAttributes() as $attribute) {
if ($attribute->getIsUnique() && $attribute->getIsUserDefined()
&& $product->getData($attribute->getAttributeCode()) !== null
) {
$uniqueLabels[] = $attribute->getDefaultFrontendLabel();
}
}
if ($uniqueLabels) {
$uniqueLabels = implode('", "', $uniqueLabels);
$this->messageManager->addErrorMessage(__('The value of attribute(s) "%1" must be unique', $uniqueLabels));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<severity value="CRITICAL"/>
<testCaseId value="MC-10905"/>
<group value="mtf_migrated"/>
<skip>
<issueId value="MC-15474"/>
</skip>
</annotations>

<before>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public function assignCategory($parentCategoryName, $childCategoryName)
*/
public function expandAllCategories()
{
$this->getTemplateBlock()->waitLoader();
$this->_rootElement->find($this->expandAll)->click();
$this->getTemplateBlock()->waitLoader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getSelectSortType()
public function getSortType()
{
$content = $this->_rootElement->find($this->sorter)->getText();
return explode("\n", $content);
return array_values(array_filter(array_map('trim', explode("\n", $content))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForAssignedProducts" />
</variation>
<variation name="CreateCategoryEntityTestVariation5_Anchor_MostOfFields">
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
<data name="description" xsi:type="string">Create anchor subcategory with all fields</data>
<data name="addCategory" xsi:type="string">addSubcategory</data>
<data name="category/data/parent_id/dataset" xsi:type="string">default_category</data>
Expand Down

0 comments on commit 08fbdf1

Please sign in to comment.