Skip to content

Commit c1c7a38

Browse files
committed
Merge branch 'MAGETWO-98621' of https://github.com/magento-tango/magento2ce into pr_2019_03_20
2 parents 2afc904 + 98a01db commit c1c7a38

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,14 +1683,16 @@ public function saveAttribute(DataObject $object, $attributeCode)
16831683
$connection->beginTransaction();
16841684

16851685
try {
1686-
$select = $connection->select()->from($table, 'value_id')->where($where);
1687-
$origValueId = $connection->fetchOne($select);
1686+
$select = $connection->select()->from($table, ['value_id', 'value'])->where($where);
1687+
$origRow = $connection->fetchRow($select);
1688+
$origValueId = $origRow['value_id'] ?? false;
1689+
$origValue = $origRow['value'] ?? null;
16881690

16891691
if ($origValueId === false && $newValue !== null) {
16901692
$this->_insertAttribute($object, $attribute, $newValue);
16911693
} elseif ($origValueId !== false && $newValue !== null) {
16921694
$this->_updateAttribute($object, $attribute, $origValueId, $newValue);
1693-
} elseif ($origValueId !== false && $newValue === null) {
1695+
} elseif ($origValueId !== false && $newValue === null && $origValue !== null) {
16941696
$connection->delete($table, $where);
16951697
}
16961698
$this->_processAttributeValues();

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
class ProductTest extends TestCase
1414
{
15+
/**
16+
* @var ProductRepositoryInterface
17+
*/
18+
private $productRepository;
19+
1520
/**
1621
* @var Product
1722
*/
@@ -29,7 +34,8 @@ protected function setUp()
2934
{
3035
$this->objectManager = Bootstrap::getObjectManager();
3136

32-
$this->model = $this->objectManager->get(Product::class);
37+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
38+
$this->model = $this->objectManager->create(Product::class);
3339
}
3440

3541
/**
@@ -42,11 +48,29 @@ public function testGetAttributeRawValue()
4248
$sku = 'simple';
4349
$attribute = 'name';
4450

45-
/** @var ProductRepositoryInterface $productRepository */
46-
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
47-
$product = $productRepository->get($sku);
48-
51+
$product = $this->productRepository->get($sku);
4952
$actual = $this->model->getAttributeRawValue($product->getId(), $attribute, null);
5053
self::assertEquals($product->getName(), $actual);
5154
}
55+
56+
/**
57+
* @magentoAppArea adminhtml
58+
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
59+
* @magentoAppIsolation enabled
60+
* @magentoConfigFixture default_store catalog/price/scope 1
61+
*/
62+
public function testUpdateStoreSpecificSpecialPrice()
63+
{
64+
/** @var \Magento\Catalog\Model\Product $product */
65+
$product = $this->productRepository->get('simple', true, 1);
66+
$this->assertEquals(5.99, $product->getSpecialPrice());
67+
68+
$product->setSpecialPrice('');
69+
$this->model->save($product);
70+
$product = $this->productRepository->get('simple', false, 1, true);
71+
$this->assertEmpty($product->getSpecialPrice());
72+
73+
$product = $this->productRepository->get('simple', false, 0, true);
74+
$this->assertEquals(5.99, $product->getSpecialPrice());
75+
}
5276
}

0 commit comments

Comments
 (0)