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

Commit 024b8fd

Browse files
committed
fix(Cart): fix serialization of cart draft
fix test for cart discount predicates
1 parent 33bb34d commit 024b8fd

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/Core/Model/Common/LocaleTrait.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@ public function setLocale($locale)
1616
return $this;
1717
}
1818

19-
/**
20-
* @return array
21-
*/
22-
abstract public function toArray();
23-
2419
/**
2520
* @return array
2621
*/
2722
public function toJson()
2823
{
29-
$data = $this->toArray();
24+
$data = parent::toJson();
3025
if (isset($data['locale'])) {
3126
$data['locale'] = str_replace('_', '-', $data['locale']);
3227
}

tests/integration/Cart/CartUpdateRequestTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,16 +1219,16 @@ public function testDiscountCodeCustomPredicate()
12191219
AbsoluteCartDiscountValue::of()->setMoney(
12201220
MoneyCollection::of()->add(Money::ofCurrencyAndAmount('EUR', 100))
12211221
),
1222-
'custom(testField = "' . $this->getTestRun() . '")',
1222+
'custom.testField = "' . $this->getTestRun() . '"',
12231223
LineItemsTarget::of()->setPredicate('1=1'),
12241224
'0.9' . trim((string)mt_rand(1, TestHelper::RAND_MAX), '0'),
12251225
true,
12261226
true
12271227
);
12281228
$request = CartDiscountCreateRequest::ofDraft($draft);
12291229
$response = $request->executeWithClient($this->getClient());
1230-
TestHelper::getInstance($this->getClient())->setCartDiscount($request->mapResponse($response));
1231-
1230+
$cartDiscount = $request->mapFromResponse($response);
1231+
TestHelper::getInstance($this->getClient())->setCartDiscount($cartDiscount);
12321232
$discountCode = $this->getDiscountCode();
12331233

12341234
$request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion())
@@ -1241,7 +1241,7 @@ public function testDiscountCodeCustomPredicate()
12411241
$this->assertSame($discountCode->getId(), $cart->getDiscountCodes()->current()->getDiscountCode()->getId());
12421242

12431243
$this->assertSame(
1244-
TestHelper::getInstance($this->getClient())->getCartDiscount()->getId(),
1244+
$cartDiscount->getId(),
12451245
$cart->getLineItems()->current()
12461246
->getDiscountedPricePerQuantity()->current()
12471247
->getDiscountedPrice()->getIncludedDiscounts()->current()

tests/unit/Model/Common/ResourceTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55

66
namespace Commercetools\Core\Model\Common;
77

8+
use Commercetools\Core\Model\Cart\Cart;
9+
use Commercetools\Core\Model\Cart\CartDraft;
10+
use Commercetools\Core\Model\Product\Product;
11+
use Commercetools\Core\Model\Product\ProductDraft;
812
use Commercetools\Core\Model\ProductType\ProductType;
913
use Commercetools\Core\Model\ProductType\ProductTypeReference;
14+
use Commercetools\Core\Model\ShippingMethod\ShippingMethod;
1015

1116
class ResourceTest extends \PHPUnit\Framework\TestCase
1217
{
@@ -50,6 +55,16 @@ public function testGetReference()
5055
);
5156
}
5257

58+
public function testSerializeNestedReference()
59+
{
60+
$method = ShippingMethod::of()->setId('123456');
61+
$product = CartDraft::of()->setShippingMethod($method->getReference());
62+
$this->assertJsonStringEqualsJsonString(
63+
'{ "shippingMethod":{"typeId":"shipping-method", "id":"123456"} }',
64+
json_encode($product)
65+
);
66+
}
67+
5368
public function testGetReferenceWithoutReferenceClass()
5469
{
5570
$obj = $this->getObject();

0 commit comments

Comments
 (0)