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

Commit 6209527

Browse files
author
Jens Schulze
committed
Merge branch 'release/v1.7.0'
2 parents 82e0b55 + e8fb14e commit 6209527

File tree

92 files changed

+4230
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4230
-24
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ before_script:
3636
script:
3737
- ant phpcs-ci
3838
- vendor/bin/phpunit --testsuite=unit
39-
- if [ $PHP == '7.0' ] ; then phpunit --testsuite=integration; fi
39+
- if [ $PHP == '7.0' ] ; then vendor/bin/phpunit --testsuite=integration; fi
4040
- ant behat
4141
after_success:
4242
- ./push-docs-to-gh-pages.sh

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
<a name="1.7.0"></a>
2+
# [1.7.0](https://github.com/commercetools/commercetools-php-sdk/compare/v1.6.1...v1.7.0) (2017-03-02)
3+
4+
5+
### Bug Fixes
6+
7+
* **CustomerDraft:** correct type mapping for customer draft dateOfBirth ([1233835](https://github.com/commercetools/commercetools-php-sdk/commit/1233835))
8+
* **State:** add roles to state draft model ([33bb512](https://github.com/commercetools/commercetools-php-sdk/commit/33bb512))
9+
10+
### Features
11+
12+
* **Cart:** support automatic deletion of old carts ([47c89b3](https://github.com/commercetools/commercetools-php-sdk/commit/47c89b3)), closes [#294](https://github.com/commercetools/commercetools-php-sdk/issues/294)
13+
* **Cart:** support tax rounding mode ([1c22189](https://github.com/commercetools/commercetools-php-sdk/commit/1c22189)), closes [#290](https://github.com/commercetools/commercetools-php-sdk/issues/290)
14+
* **Category:** add assets to categories ([5a7716d](https://github.com/commercetools/commercetools-php-sdk/commit/5a7716d)), closes [#285](https://github.com/commercetools/commercetools-php-sdk/issues/285)
15+
* **OAuth:** Client scope can be left empty ([7f1ddec](https://github.com/commercetools/commercetools-php-sdk/commit/7f1ddec)), closes [#291](https://github.com/commercetools/commercetools-php-sdk/issues/291)
16+
* **ShoppingList:** support shopping list ([d8fdf4d](https://github.com/commercetools/commercetools-php-sdk/commit/d8fdf4d)), closes [#287](https://github.com/commercetools/commercetools-php-sdk/issues/287)
17+
18+
19+
120
<a name="1.6.1"></a>
221
## [1.6.1](https://github.com/commercetools/commercetools-php-sdk/compare/v1.6.0...v1.6.1) (2017-02-14)
322

commons/Helper/PriceFinder.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Commons\Helper;
7+
8+
9+
use Commercetools\Core\Model\Channel\ChannelReference;
10+
use Commercetools\Core\Model\Common\Price;
11+
use Commercetools\Core\Model\Common\PriceCollection;
12+
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
13+
14+
class PriceFinder
15+
{
16+
private $currency;
17+
private $country;
18+
private $customerGroup;
19+
private $channel;
20+
21+
public function __construct($currency, $country = null, CustomerGroupReference $customerGroup = null, ChannelReference $channel = null)
22+
{
23+
$this->currency = $currency;
24+
$this->country = $country;
25+
$this->customerGroup = $customerGroup;
26+
$this->channel = $channel;
27+
}
28+
29+
/**
30+
* @param PriceCollection $prices
31+
* @return Price
32+
*/
33+
public function findPrice(PriceCollection $prices)
34+
{
35+
$currency = $this->currency;
36+
$country = $this->country;
37+
$customerGroup = $this->customerGroup;
38+
$channel = $this->channel;
39+
40+
$prices = new \CallbackFilterIterator(
41+
$prices,
42+
function ($price) use ($currency, $country, $customerGroup, $channel) {
43+
if (!$this->priceHasCurrency($price, $currency)) {
44+
return false;
45+
}
46+
if (!$this->priceHasNoDate($price) && !$this->priceHasValidDate($price, new \DateTime())) {
47+
return false;
48+
}
49+
if (is_null($country)) {
50+
if ($this->priceHas($price, 'country')) {
51+
return false;
52+
}
53+
} elseif (!$this->priceHasCountry($price, $country)) {
54+
return false;
55+
}
56+
if (is_null($customerGroup)) {
57+
if ($this->priceHas($price, 'customerGroup')) {
58+
return false;
59+
}
60+
} elseif (!$this->priceHasCustomerGroup($price, $customerGroup)) {
61+
return false;
62+
}
63+
if (is_null($channel)) {
64+
if ($this->priceHas($price, 'channel')) {
65+
return false;
66+
}
67+
} elseif (!$this->priceHasChannel($price, $channel)) {
68+
return false;
69+
}
70+
return true;
71+
}
72+
);
73+
74+
foreach ($prices as $price) {
75+
return $price;
76+
}
77+
return null;
78+
}
79+
80+
/**
81+
* @param $prices
82+
* @param $currency
83+
* @param string $country
84+
* @param CustomerGroupReference $customerGroup
85+
* @param ChannelReference $channel
86+
* @return Price|null
87+
*/
88+
public static function findPriceFor(
89+
$prices,
90+
$currency,
91+
$country = null,
92+
CustomerGroupReference $customerGroup = null,
93+
ChannelReference $channel = null
94+
) {
95+
$priceFinder = new static($currency, $country, $customerGroup, $channel);
96+
97+
return $priceFinder->findPrice($prices);
98+
}
99+
100+
private function priceHasCurrency(Price $price, $currency)
101+
{
102+
return !is_null($price->getValue()) && $price->getValue()->getCurrencyCode() == $currency;
103+
104+
}
105+
106+
private function priceHasCountry(Price $price, $country)
107+
{
108+
return !is_null($price->getCountry()) && $price->getCountry() == $country;
109+
}
110+
111+
private function priceHasCustomerGroup(Price $price, CustomerGroupReference $customerGroup)
112+
{
113+
return !is_null($price->getCustomerGroup()) && $price->getCustomerGroup()->getId() == $customerGroup->getId();
114+
}
115+
116+
private function priceHasChannel(Price $price, ChannelReference $channel)
117+
{
118+
return !is_null($price->getChannel()) && $price->getChannel()->getId() == $channel->getId();
119+
}
120+
121+
private function priceHasValidDate(Price $price, \DateTime $date)
122+
{
123+
$tooEarly = !is_null($price->getValidFrom()) && $price->getValidFrom()->getDateTime() > $date;
124+
$tooLate = !is_null($price->getValidUntil()) && $price->getValidUntil()->getDateTime() < $date;
125+
return !$tooEarly && !$tooLate;
126+
}
127+
128+
private function priceHasNoDate(Price $price)
129+
{
130+
return is_null($price->getValidFrom()) && is_null($price->getValidUntil());
131+
}
132+
133+
private function priceHas(Price $price, $field) {
134+
return !is_null($price->get($field));
135+
}
136+
}

commons/Helper/QueryHelper.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* @author @ct-jensschulze <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Commons\Helper;
7+
8+
9+
use Commercetools\Core\Client;
10+
use Commercetools\Core\Request\QueryAllRequestInterface;
11+
12+
class QueryHelper
13+
{
14+
const DEFAULT_PAGE_SIZE = 500;
15+
16+
public function getAll(Client $client, QueryAllRequestInterface $request)
17+
{
18+
$lastId = null;
19+
$data = ['results' => []];
20+
do {
21+
$request->sort('id')->limit(static::DEFAULT_PAGE_SIZE)->withTotal(false);
22+
if ($lastId != null) {
23+
$request->where('id > "' . $lastId . '"');
24+
}
25+
$response = $client->execute($request);
26+
if ($response->isError() || is_null($response->toObject())) {
27+
break;
28+
}
29+
$results = $response->toArray()['results'];
30+
$data['results'] = array_merge($data['results'], $results);
31+
$lastId = end($results)['id'];
32+
} while (count($results) >= static::DEFAULT_PAGE_SIZE);
33+
34+
$result = $request->mapResult($data, $client->getConfig()->getContext());
35+
36+
return $result;
37+
}
38+
}

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
},
1313
"autoload": {
1414
"psr-4": {
15-
"Commercetools\\Core\\": "src/"
15+
"Commercetools\\Core\\": "src/",
16+
"Commercetools\\Commons\\": "commons/"
1617
}
1718
},
1819
"autoload-dev": {
@@ -52,6 +53,9 @@
5253
"cache/filesystem-adapter": "^0.3.0",
5354
"incenteev/composer-parameter-handler": "^2.1"
5455
},
56+
"replaces": {
57+
"commercetools/commons": "*"
58+
},
5559
"scripts": {
5660
"updateConfig": [
5761
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"

src/AbstractHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
abstract class AbstractHttpClient
1616
{
17-
const VERSION = '1.6.1';
17+
const VERSION = '1.7.0';
1818

1919
/**
2020
* @var AdapterInterface

src/Client/OAuth/Manager.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ public function refreshToken()
106106
{
107107
$scope = $this->getConfig()->getScope();
108108
$grantType = $this->getConfig()->getGrantType();
109-
$data = [Config::SCOPE => $scope, Config::GRANT_TYPE => $grantType];
109+
$data = [Config::GRANT_TYPE => $grantType];
110+
if (!empty($scope)) {
111+
$data[Config::SCOPE] = $scope;
112+
}
110113

111114
switch ($grantType) {
112115
case Config::GRANT_TYPE_PASSWORD:

src/Config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ public function getScope()
268268
*/
269269
public function setScope($scope)
270270
{
271+
if (empty($scope)) {
272+
$scope = [];
273+
}
271274
if (!is_array($scope)) {
272275
$scope = explode(' ', $scope);
273276
}

src/Model/Cart/Cart.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
* @method string getAnonymousId()
6464
* @method Cart setAnonymousId(string $anonymousId = null)
6565
* @method string getLocale()
66+
* @method string getTaxRoundingMode()
67+
* @method Cart setTaxRoundingMode(string $taxRoundingMode = null)
68+
* @method int getDeleteDaysAfterLastModification()
69+
* @method Cart setDeleteDaysAfterLastModification(int $deleteDaysAfterLastModification = null)
6670
* @method CartReference getReference()
6771
*/
6872
class Cart extends Resource
@@ -72,6 +76,9 @@ class Cart extends Resource
7276
const TAX_MODE_PLATFORM = 'Platform';
7377
const TAX_MODE_EXTERNAL = 'External';
7478
const TAX_MODE_DISABLED = 'Disabled';
79+
const TAX_ROUNDING_MODE_HALF_EVEN = 'HalfEven';
80+
const TAX_ROUNDING_MODE_HALF_UP = 'HalfUp';
81+
const TAX_ROUNDING_MODE_HALF_DOWN = 'HalfDown';
7582

7683
public function fieldDefinitions()
7784
{
@@ -105,6 +112,8 @@ public function fieldDefinitions()
105112
'taxMode' => [static::TYPE => 'string'],
106113
'anonymousId' => [static::TYPE => 'string'],
107114
'locale' => [static::TYPE => 'string'],
115+
'taxRoundingMode' => [static::TYPE => 'string'],
116+
'deleteDaysAfterLastModification' => [static::TYPE => 'int']
108117
];
109118
}
110119

src/Model/Cart/CartDraft.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
* @method string getAnonymousId()
4343
* @method CartDraft setAnonymousId(string $anonymousId = null)
4444
* @method string getLocale()
45+
* @method string getTaxRoundingMode()
46+
* @method CartDraft setTaxRoundingMode(string $taxRoundingMode = null)
47+
* @method int getDeleteDaysAfterLastModification()
48+
* @method CartDraft setDeleteDaysAfterLastModification(int $deleteDaysAfterLastModification = null)
4549
*/
4650
class CartDraft extends JsonObject
4751
{
@@ -64,6 +68,8 @@ public function fieldDefinitions()
6468
'taxMode' => [static::TYPE => 'string'],
6569
'anonymousId' => [static::TYPE => 'string'],
6670
'locale' => [static::TYPE => 'string'],
71+
'taxRoundingMode' => [static::TYPE => 'string'],
72+
'deleteDaysAfterLastModification' => [static::TYPE => 'int']
6773
];
6874
}
6975

0 commit comments

Comments
 (0)