Skip to content

Commit d75d1c3

Browse files
committed
AC-6020:: SQLSTATE[23000]: Integrity constraint violation error when saving product without sku
1 parent 49bd706 commit d75d1c3

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public function validate($object)
5656
);
5757
}
5858

59+
if (strcasecmp($attrCode, 'sku') >= 0) {
60+
throw new LocalizedException(
61+
__('The "%1" attribute value is empty.', $attrCode)
62+
);
63+
}
64+
5965
if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
6066
throw new LocalizedException(
6167
__('SKU length should be %1 characters maximum.', self::SKU_MAX_LENGTH)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminCannotCreateSimpleProductWithEmptySKUTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Admin should not be able to create a product with SKU empty"/>
14+
<title value="Admin should not be able to create a product with SKU empty"/>
15+
<description value="Admin should not be able to create a product with SKU empty"/>
16+
<severity value="AVERAGE"/>
17+
<testCaseId value="AC-6020"/>
18+
<group value="product"/>
19+
<group value="pr_exclude"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
23+
<actionGroup ref="NavigateToEditProductAttributeActionGroup" stepKey="goToEditPage">
24+
<argument name="ProductAttribute" value="sku"/>
25+
</actionGroup>
26+
<selectOption userInput="0" selector="#is_required" stepKey="selectOptionNo"/>
27+
<click stepKey="saveAttribute" selector="#save" />
28+
<waitForPageLoad stepKey="waitForSaveAttribute"/>
29+
</before>
30+
<after>
31+
<actionGroup ref="NavigateToEditProductAttributeActionGroup" stepKey="goToEditPage">
32+
<argument name="ProductAttribute" value="sku"/>
33+
</actionGroup>
34+
<selectOption userInput="1" selector="#is_required" stepKey="selectOptionYes"/>
35+
<click stepKey="saveAttribute" selector="#save" />
36+
<waitForPageLoad stepKey="waitForSaveAttribute" />
37+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
38+
</after>
39+
<actionGroup ref="AdminOpenNewProductFormPageActionGroup" stepKey="goToCreateProduct"/>
40+
<waitForPageLoad stepKey="waitForAdminOpenNewProductFormPageActionGroup" />
41+
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="wait1"/>
42+
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="fillName"/>
43+
<actionGroup ref="FillMainProductFormByStringActionGroup" stepKey="fillSKU">
44+
<argument name="productName" value="{{SimpleProduct.name}}"/>
45+
<argument name="productSku" value=""/>
46+
<argument name="productPrice" value="100"/>
47+
<argument name="productQuantity" value="{{SimpleProduct.quantity}}"/>
48+
<argument name="productStatus" value="{{SimpleProduct.status}}"/>
49+
<argument name="productWeight" value="{{SimpleProduct.weight}}"/>
50+
</actionGroup>
51+
<actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickSave"/>
52+
<waitForPageLoad stepKey="waitForAdminProductFormSaveActionGroup"/>
53+
<see selector="The &quot;sku&quot; attribute value is empty." stepKey="seeErrorMessage"/>
54+
</test>
55+
</tests>

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ Category,Category
318318
"There is no MediaGalleryEntryConverter for given type","There is no MediaGalleryEntryConverter for given type"
319319
"Please enter a number 0 or greater in this field.","Please enter a number 0 or greater in this field."
320320
"The value of attribute ""%1"" must be set","The value of attribute ""%1"" must be set"
321+
"The "%1" attribute value is empty.","The "%1" attribute value is empty."
321322
"SKU length should be %1 characters maximum.","SKU length should be %1 characters maximum."
322323
"Please enter a valid number in this field.","Please enter a valid number in this field."
323324
"We found a duplicate website, tier price, customer group and quantity.","We found a duplicate website, tier price, customer group and quantity."

0 commit comments

Comments
 (0)