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

Commit 7fa6b26

Browse files
author
Jens Schulze
committed
Merge branch 'release/v1.0.0-RC7'
2 parents dbb2276 + a313625 commit 7fa6b26

15 files changed

+162
-47
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
<a name="1.0.0-RC7"></a>
2+
# [1.0.0-RC7](https://github.com/sphereio/commercetools-php-sdk/compare/v1.0.0-RC5...v1.0.0-RC7) (2015-10-19)
3+
4+
5+
### Bug Fixes
6+
7+
* **Cart:** add corrected cart discount fields ([b0bf1b7](https://github.com/sphereio/commercetools-php-sdk/commit/b0bf1b7))
8+
* **LocalizedString:** fix array conversion of locales for LocalizedString ([ea50790](https://github.com/sphereio/commercetools-php-sdk/commit/ea50790))
9+
* **PaymentInfo** correct class path ([a9501fc](https://github.com/sphereio/commercetools-php-sdk/commit/a9501fc))
10+
11+
### Features
12+
13+
* **JsonObject:** recurse toArray method to child objects ([feb3729](https://github.com/sphereio/commercetools-php-sdk/commit/feb3729))
14+
15+
### BREAKING CHANGES
16+
17+
* discountedPrice at LineItems has been removed
18+
19+
The discountedPrice field has been deprecated at the API and therefor was removed from the SDK.
20+
21+
Before:
22+
```
23+
$lineItem->getDiscountedPrice();
24+
$discountedCentAmount = $lineItem->getDiscountedPrice()->getValue()->getCentAmount();
25+
```
26+
27+
After:
28+
29+
```
30+
$lineItem->getDiscountedPricePerQuantity();
31+
$discountedCentAmount = 0;
32+
foreach ($lineItem->getDiscountedPricePerQuantity() as $discountedPricePerQuantity) {
33+
$discountedCentAmount += $discountedPricePerQuantity()->getQuantity() *
34+
$discountedPricePerQuantity->getDiscountedPrice()->getValue()->getCentAmount();
35+
}
36+
```
37+
([b0bf1b7](https://github.com/sphereio/commercetools-php-sdk/commit/b0bf1b7))
38+
139
<a name="1.0.0-RC5"></a>
240
# [1.0.0-RC5](https://github.com/sphereio/commercetools-php-sdk/compare/v1.0.0-RC4...v1.0.0-RC5) (2015-10-07)
341

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# <img src="build/theme/resources/CT_cube_200px.png" width="40" align="center"></img> commercetools PHP SDK
22

3-
> STATUS: Release Candidate 5. We ask you to really use this API thoroughly now, especially the API design and object structure. Thank you very much!
3+
> STATUS: Release Candidate 7. We ask you to really use this API thoroughly now, especially the API design and object structure. Thank you very much!
44
>
55
> See the [Milestone Plan](https://github.com/sphereio/commercetools-php-sdk/milestones?direction=desc&sort=completeness&state=open) for details of what's planned in detail. We love feedback and [Issue reports](https://github.com/sphereio/commercetools-php-sdk/issues?q=is%3Aopen+is%3Aissue+sort%3Acreated-asc)!
66
> Up-to-Date planning status can be found on this [Waffle Board](https://waffle.io/sphereio/commercetools-php-sdk)

src/AbstractHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
abstract class AbstractHttpClient
1616
{
1717

18-
const VERSION = '1.0.0-RC5';
18+
const VERSION = '1.0.0-RC7';
1919

2020
/**
2121
* @var AdapterInterface

src/Model/Cart/CustomLineItem.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
* @method CustomLineItem setTaxRate(TaxRate $taxRate = null)
3535
* @method CustomFieldObject getCustom()
3636
* @method CustomLineItem setCustom(CustomFieldObject $custom = null)
37+
* @method Money getTotalPrice()
38+
* @method CustomLineItem setTotalPrice(Money $totalPrice = null)
39+
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
40+
* @codingStandardsIgnoreStart
41+
* @method CustomLineItem setDiscountedPricePerQuantity(DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null)
42+
* @codingStandardsIgnoreEnd
3743
*/
3844
class CustomLineItem extends JsonObject
3945
{
@@ -49,6 +55,10 @@ public function fieldDefinitions()
4955
'taxCategory' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference'],
5056
'taxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxRate'],
5157
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
58+
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
59+
'discountedPricePerQuantity' => [
60+
static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantityCollection'
61+
],
5262
];
5363
}
5464
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
* @apidoc http://dev.sphere.io/http-api-projects-carts.html#discounted-line-item-price-for-quantity
13+
* @method int getQuantity()
14+
* @method DiscountedPricePerQuantity setQuantity(int $quantity = null)
15+
* @method DiscountedLineItemPrice getDiscountedPrice()
16+
* @method DiscountedPricePerQuantity setDiscountedPrice(DiscountedLineItemPrice $discountedPrice = null)
17+
*/
18+
class DiscountedPricePerQuantity extends JsonObject
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'quantity' => [static::TYPE => 'int'],
24+
'discountedPrice' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedLineItemPrice']
25+
];
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\Collection;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Cart
12+
*
13+
* @method DiscountedPricePerQuantityCollection add(DiscountedPricePerQuantity $element)
14+
* @method DiscountedPricePerQuantity current()
15+
* @method DiscountedPricePerQuantity getAt($offset)
16+
*/
17+
class DiscountedPricePerQuantityCollection extends Collection
18+
{
19+
protected $type = '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantity';
20+
}

src/Model/Cart/LineItem.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
* @method LineItem setDistributionChannel(ChannelReference $distributionChannel = null)
4646
* @method CustomFieldObject getCustom()
4747
* @method LineItem setCustom(CustomFieldObject $custom = null)
48+
* @method Money getTotalPrice()
49+
* @method LineItem setTotalPrice(Money $totalPrice = null)
50+
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
51+
* @codingStandardsIgnoreStart
52+
* @method LineItem setDiscountedPricePerQuantity(DiscountedPricePerQuantityCollection $discountedPricePerQuantity = null)
53+
* @codingStandardsIgnoreEnd
4854
*/
4955
class LineItem extends JsonObject
5056
{
@@ -61,19 +67,12 @@ public function fieldDefinitions()
6167
'state' => [static::TYPE => '\Commercetools\Core\Model\Order\ItemStateCollection'],
6268
'taxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxRate'],
6369
'supplyChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
64-
'discountedPrice' => [static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedLineItemPrice'],
6570
'distributionChannel' => [static::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
6671
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
72+
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
73+
'discountedPricePerQuantity' => [
74+
static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantityCollection'
75+
],
6776
];
6877
}
69-
70-
/**
71-
* @return Money
72-
*/
73-
public function getTotal()
74-
{
75-
$price = $this->getPrice()->getValue();
76-
$amount = $this->getQuantity() * $price->getCentAmount();
77-
return Money::ofCurrencyAndAmount($price->getCurrencyCode(), $amount, $this->getContext());
78-
}
7978
}

src/Model/Common/AbstractJsonDeserializeObject.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function __construct(array $data = [], $context = null)
4646
*/
4747
protected static $interfaces = [];
4848

49+
public function __sleep()
50+
{
51+
return array_diff(array_keys(get_object_vars($this)), ['context']);
52+
}
53+
4954
/**
5055
* @param $type
5156
* @param $interfaceName
@@ -189,6 +194,15 @@ public function toArray()
189194
$data = array_filter($data, function ($value) {
190195
return !is_null($value);
191196
});
197+
$data = array_map(
198+
function ($value) {
199+
if ($value instanceof JsonDeserializeInterface) {
200+
return $value->toArray();
201+
}
202+
return $value;
203+
},
204+
$data
205+
);
192206
return $data;
193207
}
194208

src/Model/Common/LocalizedString.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ public function __toString()
127127
*/
128128
public function toArray()
129129
{
130-
return $this->values;
130+
$values = $this->values;
131+
132+
$data = [];
133+
foreach ($values as $key => $value) {
134+
$data[str_replace('_', '-', $key)] = $value;
135+
}
136+
return $data;
131137
}
132138

133139
/**
134140
* @return array
135141
*/
136142
public function jsonSerialize()
137143
{
138-
$values = $this->toArray();
139-
140-
$data = [];
141-
foreach ($values as $key => $value) {
142-
$data[str_replace('_', '-', $key)] = $value;
143-
}
144-
return $data;
144+
return $this->toArray();
145145
}
146146

147147
/**

src/Model/Order/Order.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Commercetools\Core\Model\CustomField\CustomFieldObject;
1919
use Commercetools\Core\Model\Common\DateTimeDecorator;
2020
use Commercetools\Core\Model\State\StateReference;
21+
use Commercetools\Core\Model\Payment\PaymentInfo;
2122

2223
/**
2324
* @package Commercetools\Core\Model\Order

tests/fixtures/models.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ lineItem:
3838
- taxRate
3939
- supplyChannel
4040
- distributionChannel
41-
- discountedPrice
4241
- custom
42+
- discountedPricePerQuantity
43+
- totalPrice
4344

4445
customLineItem:
4546
domain: cart
@@ -54,6 +55,8 @@ customLineItem:
5455
- taxCategory
5556
- taxRate
5657
- custom
58+
- discountedPricePerQuantity
59+
- totalPrice
5760

5861
taxedPrice:
5962
domain: common

tests/unit/Model/Cart/LineItemTest.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/unit/Model/Common/JsonObjectTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
namespace Commercetools\Core\Model\Type;
88

9-
109
use Commercetools\Core\Model\Common\JsonObject;
1110
use Commercetools\Core\Model\ProductType\AttributeDefinition;
1211
use Commercetools\Core\Model\ProductType\AttributeDefinitionCollection;
13-
use Commercetools\Core\Model\ProductType\ProductType;
1412
use Commercetools\Core\Model\ProductType\ProductTypeDraft;
1513

1614
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Customer;
7+
8+
use Commercetools\Core\Model\CustomerGroup\CustomerGroup;
9+
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
10+
11+
class CustomerTest extends \PHPUnit_Framework_TestCase
12+
{
13+
public function testSerialize()
14+
{
15+
$t = Customer::of()
16+
->setFirstName('John')
17+
->setLastName('Doe')
18+
->setCustomerGroup(
19+
CustomerGroupReference::ofId('id1')->setObj(CustomerGroup::of()->setName('Test'))
20+
);
21+
$t = serialize($t->toArray());
22+
$customer = Customer::fromArray(unserialize($t));
23+
24+
$this->assertSame('John', $customer->getFirstName());
25+
$this->assertSame('Test', $customer->getCustomerGroup()->getObj()->getName());
26+
}
27+
}

tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commercetools-php-sdk-changelog",
3-
"version": "1.0.0-RC5",
3+
"version": "1.0.0-RC7",
44
"description": "commercetools PHP SDK changelog generator package description",
55
"homepage": "https://github.com/sphereio/commercetools-php-sdk",
66
"bugs": "https://github.com/sphereio/commercetools-php-sdk/issues",

0 commit comments

Comments
 (0)