Skip to content

Commit 3c6c9a5

Browse files
committed
Merge branch 'ACP2E-3236' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-08-29-2024
2 parents b34c0a7 + b2a0ee8 commit 3c6c9a5

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ public function save(ProductInterface $product, $saveOptions = false)
526526
$assignToCategories = false;
527527
$tierPrices = $product->getData('tier_price');
528528
$productDataToChange = $product->getData();
529+
530+
if (!$product->getSku()) {
531+
throw new CouldNotSaveException(
532+
__("The \"%1\" attribute value is empty. Set the attribute and try again.", "sku")
533+
);
534+
}
535+
529536
try {
530537
$existingProduct = $product->getId() ?
531538
$this->getById($product->getId()) :

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,4 +1568,18 @@ public function testSaveExistingWithMediaGalleryEntries(): void
15681568
$this->model->save($this->product);
15691569
$this->assertEquals($expectedResult, $this->initializedProduct->getMediaGallery('images'));
15701570
}
1571+
1572+
/**
1573+
* @return void
1574+
*/
1575+
public function testSaveCouldNotSaveException(): void
1576+
{
1577+
$this->expectException(\Magento\Framework\Exception\CouldNotSaveException::class);
1578+
$productData = [
1579+
'name' => 'Simple Product',
1580+
'price' => 100
1581+
];
1582+
$this->product->setData($productData);
1583+
$this->model->save($this->product);
1584+
}
15711585
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Category,Category
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"
321321
"The "%1" attribute value is empty.","The "%1" attribute value is empty."
322+
"The ""%1"" attribute value is empty. Set the attribute and try again.","The ""%1"" attribute value is empty. Set the attribute and try again."
322323
"SKU length should be %1 characters maximum.","SKU length should be %1 characters maximum."
323324
"Please enter a valid number in this field.","Please enter a valid number in this field."
324325
"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)