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

Commit 02026a7

Browse files
author
Jens Schulze
committed
feat(Product): support product price selection
Closes #225
1 parent ebac224 commit 02026a7

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

src/Request/Products/ProductCreateRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Commercetools\Core\Model\Product\ProductDraft;
1111
use Commercetools\Core\Request\AbstractCreateRequest;
1212
use Commercetools\Core\Model\Product\Product;
13+
use Commercetools\Core\Request\PriceSelectTrait;
1314
use Commercetools\Core\Response\ApiResponseInterface;
1415

1516
/**
@@ -19,6 +20,8 @@
1920
*/
2021
class ProductCreateRequest extends AbstractCreateRequest
2122
{
23+
use PriceSelectTrait;
24+
2225
protected $resultClass = '\Commercetools\Core\Model\Product\Product';
2326
/**
2427
* @param ProductDraft $product

src/Request/Products/ProductDeleteRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Commercetools\Core\Model\Common\Context;
99
use Commercetools\Core\Request\AbstractDeleteRequest;
1010
use Commercetools\Core\Model\Product\Product;
11+
use Commercetools\Core\Request\PriceSelectTrait;
1112
use Commercetools\Core\Response\ApiResponseInterface;
1213

1314
/**
@@ -17,6 +18,8 @@
1718
*/
1819
class ProductDeleteRequest extends AbstractDeleteRequest
1920
{
21+
use PriceSelectTrait;
22+
2023
protected $resultClass = '\Commercetools\Core\Model\Product\Product';
2124

2225
/**

src/Request/Products/ProductUpdateRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Commercetools\Core\Model\Common\Context;
1010
use Commercetools\Core\Request\AbstractUpdateRequest;
1111
use Commercetools\Core\Model\Product\Product;
12+
use Commercetools\Core\Request\PriceSelectTrait;
1213
use Commercetools\Core\Response\ApiResponseInterface;
1314

1415
/**
@@ -18,6 +19,8 @@
1819
*/
1920
class ProductUpdateRequest extends AbstractUpdateRequest
2021
{
22+
use PriceSelectTrait;
23+
2124
protected $resultClass = '\Commercetools\Core\Model\Product\Product';
2225

2326
/**

tests/integration/Product/ProductUpdateRequestTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public function testPrices()
287287
)
288288
)
289289
;
290+
$request->currency('EUR');
290291
$response = $request->executeWithClient($this->getClient());
291292
$result = $request->mapResponse($response);
292293
$this->deleteRequest->setVersion($result->getVersion());
@@ -298,6 +299,13 @@ public function testPrices()
298299
$price->getValue()->getCentAmount(),
299300
$variant->getPrices()->current()->getValue()->getCentAmount()
300301
);
302+
303+
$this->assertEmpty($variant->getPrice()->getCountry());
304+
$this->assertEmpty($variant->getPrice()->getChannel());
305+
$this->assertEmpty($variant->getPrice()->getCustomerGroup());
306+
$this->assertSame('EUR', $variant->getPrice()->getValue()->getCurrencyCode());
307+
$this->assertSame(100, $variant->getPrice()->getValue()->getCentAmount());
308+
301309
$this->assertNotSame($product->getVersion(), $result->getVersion());
302310
$product = $result;
303311

@@ -1168,6 +1176,63 @@ public function testReferenceExpansion()
11681176
array_pop($this->cleanupRequests);
11691177
}
11701178

1179+
public function testPriceSelectCreateUpdateDelete()
1180+
{
1181+
$draft = $this->getDraft('update-reference-expansion');
1182+
$draft->setMasterVariant(
1183+
ProductVariantDraft::of()->setSku('sku' . uniqid())
1184+
->setPrices(
1185+
PriceDraftCollection::of()->add(
1186+
PriceDraft::ofMoney(Money::ofCurrencyAndAmount('EUR', 100))
1187+
)
1188+
)
1189+
);
1190+
1191+
$request = ProductCreateRequest::ofDraft($draft);
1192+
$request->currency('EUR');
1193+
$response = $request->executeWithClient($this->getClient());
1194+
$product = $request->mapResponse($response);
1195+
1196+
$this->cleanupRequests[] = $this->deleteRequest = ProductDeleteRequest::ofIdAndVersion(
1197+
$product->getId(),
1198+
$product->getVersion()
1199+
);
1200+
1201+
$variant = $product->getMasterData()->getStaged()->getMasterVariant();
1202+
$this->assertEmpty($variant->getPrice()->getCountry());
1203+
$this->assertEmpty($variant->getPrice()->getChannel());
1204+
$this->assertEmpty($variant->getPrice()->getCustomerGroup());
1205+
$this->assertSame('EUR', $variant->getPrice()->getValue()->getCurrencyCode());
1206+
$this->assertSame(100, $variant->getPrice()->getValue()->getCentAmount());
1207+
1208+
$request = ProductUpdateRequest::ofIdAndVersion($product->getId(), $product->getVersion());
1209+
$request->currency('EUR');
1210+
$response = $request->executeWithClient($this->getClient());
1211+
$product = $request->mapResponse($response);
1212+
$this->deleteRequest->setVersion($product->getVersion());
1213+
1214+
$variant = $product->getMasterData()->getStaged()->getMasterVariant();
1215+
$this->assertEmpty($variant->getPrice()->getCountry());
1216+
$this->assertEmpty($variant->getPrice()->getChannel());
1217+
$this->assertEmpty($variant->getPrice()->getCustomerGroup());
1218+
$this->assertSame('EUR', $variant->getPrice()->getValue()->getCurrencyCode());
1219+
$this->assertSame(100, $variant->getPrice()->getValue()->getCentAmount());
1220+
1221+
$request = ProductDeleteRequest::ofIdAndVersion($product->getId(), $product->getVersion());
1222+
$request->currency('EUR');
1223+
$response = $request->executeWithClient($this->getClient());
1224+
$product = $request->mapResponse($response);
1225+
1226+
$variant = $product->getMasterData()->getStaged()->getMasterVariant();
1227+
$this->assertEmpty($variant->getPrice()->getCountry());
1228+
$this->assertEmpty($variant->getPrice()->getChannel());
1229+
$this->assertEmpty($variant->getPrice()->getCustomerGroup());
1230+
$this->assertSame('EUR', $variant->getPrice()->getValue()->getCurrencyCode());
1231+
$this->assertSame(100, $variant->getPrice()->getValue()->getCentAmount());
1232+
1233+
array_pop($this->cleanupRequests);
1234+
}
1235+
11711236
/**
11721237
* @return ProductDraft
11731238
*/

0 commit comments

Comments
 (0)