Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 9d0b5aa

Browse files
author
Jens Schulze
committed
feat(Product): support scope for product publish
Closes #340
1 parent 6c41b97 commit 9d0b5aa

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/Core/Request/Products/Command/ProductPublishAction.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@
1313
* @link https://dev.commercetools.com/http-api-projects-products.html#publish
1414
* @method string getAction()
1515
* @method ProductPublishAction setAction(string $action = null)
16+
* @method string getScope()
17+
* @method ProductPublishAction setScope(string $scope = null)
1618
*/
1719
class ProductPublishAction extends AbstractAction
1820
{
21+
const ALL = 'All';
22+
const PRICES = 'Prices';
23+
1924
public function fieldDefinitions()
2025
{
2126
return [
2227
'action' => [static::TYPE => 'string'],
28+
'scope' => [static::TYPE => 'string'],
2329
];
2430
}
2531

tests/integration/Product/ProductUpdateRequestTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,52 @@ public function testPublish()
10521052
$this->assertNotSame($product->getVersion(), $result->getVersion());
10531053
}
10541054

1055+
public function testPublishPrices()
1056+
{
1057+
$draft = $this->getDraft('publish-prices');
1058+
$draft
1059+
->setMasterVariant(
1060+
ProductVariantDraft::of()->setSku('sku-' . $this->getTestRun())
1061+
->setPrices(
1062+
PriceDraftCollection::of()
1063+
->add(PriceDraft::ofMoney(Money::ofCurrencyAndAmount('EUR', 100)))
1064+
)
1065+
)->setPublish(true);
1066+
$product = $this->createProduct($draft);
1067+
$request = ProductUpdateRequest::ofIdAndVersion($product->getId(), $product->getVersion())
1068+
->addAction(ProductSetDescriptionAction::of()->setDescription(LocalizedString::ofLangAndText('en', $this->getTestRun())))
1069+
->addAction(
1070+
ProductSetPricesAction::of()->setSku('sku-' . $this->getTestRun())
1071+
->setPrices(PriceDraftCollection::of()
1072+
->add(PriceDraft::ofMoney(Money::ofCurrencyAndAmount('EUR', 200)))
1073+
)
1074+
)
1075+
->addAction(ProductPublishAction::of()->setScope(ProductPublishAction::PRICES))
1076+
;
1077+
$response = $request->executeWithClient($this->getClient());
1078+
$result = $request->mapResponse($response);
1079+
$this->deleteRequest->setVersion($result->getVersion());
1080+
1081+
$this->assertInstanceOf(Product::class, $result);
1082+
$this->assertTrue($result->getMasterData()->getHasStagedChanges());
1083+
$this->assertSame(
1084+
200,
1085+
$result->getMasterData()->getCurrent()->getMasterVariant()->getPrices()->current()->getValue()->getCentAmount()
1086+
);
1087+
$this->assertNotSame($product->getVersion(), $result->getVersion());
1088+
$product = $result;
1089+
1090+
$request = ProductUpdateRequest::ofIdAndVersion($product->getId(), $product->getVersion())
1091+
->addAction(ProductPublishAction::of()->setScope(ProductPublishAction::ALL))
1092+
;
1093+
$response = $request->executeWithClient($this->getClient());
1094+
$result = $request->mapResponse($response);
1095+
$this->deleteRequest->setVersion($result->getVersion());
1096+
1097+
$this->assertInstanceOf(Product::class, $result);
1098+
$this->assertFalse($result->getMasterData()->getHasStagedChanges());
1099+
}
1100+
10551101
public function testTransitionStates()
10561102
{
10571103
$draft = $this->getDraft('publish');

tests/unit/Request/GenericActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public function actionFieldProvider()
354354
],
355355
[
356356
ProductPublishAction::class,
357-
['action']
357+
['action', 'scope']
358358
],
359359
[
360360
ProductRemoveFromCategoryAction::class,

0 commit comments

Comments
 (0)