Skip to content

Commit a4c1472

Browse files
author
Robert He
committed
MAGETWO-64944: Product status is always changing back to "Enabled" after "rest/all/V1/products" REST API call
- fixes status attribute when saving a product
1 parent 23f7456 commit a4c1472

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
539539
$this->resourceModel->getLinkField(),
540540
$existingProduct->getData($this->resourceModel->getLinkField())
541541
);
542+
if (!$product->hasData(Product::STATUS)) {
543+
$product->setStatus($existingProduct->getStatus());
544+
}
542545
} catch (NoSuchEntityException $e) {
543546
$existingProduct = null;
544547
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,4 +1140,34 @@ public function testSpecialPrice()
11401140
$this->assertEquals(0, count(array_intersect($attributeCodes, $missingAttributes)));
11411141
$this->assertEquals(2, count(array_intersect($attributeCodes, $expectedAttribute)));
11421142
}
1143+
1144+
public function testUpdateStatus()
1145+
{
1146+
// Create simple product
1147+
$productData = [
1148+
ProductInterface::SKU => "product_simple_502",
1149+
ProductInterface::NAME => "Product Simple 502",
1150+
ProductInterface::VISIBILITY => 4,
1151+
ProductInterface::TYPE_ID => 'simple',
1152+
ProductInterface::PRICE => 100,
1153+
ProductInterface::STATUS => 0,
1154+
ProductInterface::TYPE_ID => 'simple',
1155+
ProductInterface::ATTRIBUTE_SET_ID => 4,
1156+
];
1157+
1158+
// Save product with status disabled
1159+
$this->saveProduct($productData);
1160+
$response = $this->getProduct($productData[ProductInterface::SKU]);
1161+
$this->assertEquals(0, $response['status']);
1162+
1163+
// Update the product
1164+
$productData[ProductInterface::PRICE] = 200;
1165+
$this->saveProduct($productData);
1166+
$response = $this->getProduct($productData[ProductInterface::SKU]);
1167+
1168+
// Status should still be disabled
1169+
$this->assertEquals(0, $response['status']);
1170+
// Price should be updated
1171+
$this->assertEquals(200, $response['price']);
1172+
}
11431173
}

0 commit comments

Comments
 (0)