Skip to content

Commit 15a0515

Browse files
committed
MC-30625: 2.4 : When saving a product using the product repository, the price is not saved
1 parent 4898eb4 commit 15a0515

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

app/code/Magento/Catalog/Model/Product/Type.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public function factory($product)
127127

128128
$typeModel = $this->_productTypePool->get($typeModelName);
129129
$typeModel->setConfig($types[$typeId]);
130+
$typeModel->setTypeId($typeId);
131+
130132
return $typeModel;
131133
}
132134

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ protected function _removeNotApplicableAttributes($product)
752752
*/
753753
public function beforeSave($product)
754754
{
755+
if (!$product->getTypeId()) {
756+
$product->setTypeId($this->_typeId);
757+
}
755758
$this->_removeNotApplicableAttributes($product);
756759
$product->canAffectOptions(true);
757760
return $this;

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,4 +814,16 @@ public function testConstructionWithCustomAttributesArrayInData()
814814
$this->assertSame($product->getCustomAttribute('tax_class_id')->getValue(), '3');
815815
$this->assertSame($product->getCustomAttribute('category_ids')->getValue(), '1,2');
816816
}
817+
818+
public function testSetPriceWithoutTypeId()
819+
{
820+
$this->_model->setAttributeSetId(4);
821+
$this->_model->setName('Some name');
822+
$this->_model->setSku('some_sku');
823+
$this->_model->setPrice(9.95);
824+
$this->productRepository->save($this->_model);
825+
826+
$product = $this->productRepository->get('some_sku', false, null, true);
827+
$this->assertEquals(9.95, $product->getPrice());
828+
}
817829
}

0 commit comments

Comments
 (0)