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

Commit 78eab58

Browse files
author
Jens Schulze
committed
Merge branch 'release/v1.4.0'
2 parents 3f2d2ed + 6d9bf2d commit 78eab58

File tree

48 files changed

+1559
-99
lines changed

Some content is hidden

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

48 files changed

+1559
-99
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
<a name="1.4.0"></a>
2+
# [1.4.0](https://github.com/sphereio/commercetools-php-sdk/compare/v1.3.1...v1.4.0) (2016-10-05)
3+
4+
### Features
5+
6+
* **Cart:** support change of custom line item quantity and price ([63d78e5](https://github.com/sphereio/commercetools-php-sdk/commit/63d78e5)), closes [#256](https://github.com/sphereio/commercetools-php-sdk/issues/256)
7+
* **Cart:** support external line item total price ([417e78c](https://github.com/sphereio/commercetools-php-sdk/commit/417e78c)), closes [#247](https://github.com/sphereio/commercetools-php-sdk/issues/247)
8+
* **CustomObject:** add constructor using custom object draft ([7482d1b](https://github.com/sphereio/commercetools-php-sdk/commit/7482d1b)), closes [#258](https://github.com/sphereio/commercetools-php-sdk/issues/258)
9+
* **CustomObject:** add reference model for custom objects ([566cf22](https://github.com/sphereio/commercetools-php-sdk/commit/566cf22)), closes [#248](https://github.com/sphereio/commercetools-php-sdk/issues/248)
10+
* **Filter:** add method to create a subtree filter with an array of IDs ([ac487a3](https://github.com/sphereio/commercetools-php-sdk/commit/ac487a3)), closes [#257](https://github.com/sphereio/commercetools-php-sdk/issues/257)
11+
* **Inventory:** add inventory deleted message ([699a8c7](https://github.com/sphereio/commercetools-php-sdk/commit/699a8c7)), closes [#245](https://github.com/sphereio/commercetools-php-sdk/issues/245)
12+
* **Inventory:** support customizable inventory entries ([31f16db](https://github.com/sphereio/commercetools-php-sdk/commit/31f16db)), closes [#246](https://github.com/sphereio/commercetools-php-sdk/issues/246)
13+
* **Logger:** add correlation id to logger as context object ([512536b](https://github.com/sphereio/commercetools-php-sdk/commit/512536b))
14+
* **Product:** query product by slug with single language ([88cd9e2](https://github.com/sphereio/commercetools-php-sdk/commit/88cd9e2)), closes [#250](https://github.com/sphereio/commercetools-php-sdk/issues/250)
15+
* **Product:** support key for product and product variant ([39f356a](https://github.com/sphereio/commercetools-php-sdk/commit/39f356a)), closes [#259](https://github.com/sphereio/commercetools-php-sdk/issues/259)
16+
* **Reference:** resolve correct reference model by typeId ([8f76ec4](https://github.com/sphereio/commercetools-php-sdk/commit/8f76ec4))
17+
18+
19+
120
<a name="1.3.1"></a>
221
## [1.3.1](https://github.com/sphereio/commercetools-php-sdk/compare/v1.3.0...v1.3.1) (2016-08-30)
322

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Clone the develop branch of the repository (we're using the [gitflow](http://nvi
144144
git clone [email protected]:sphereio/commercetools-php-sdk.git
145145
```
146146

147-
Please follow the [PSR-2](http://www.php-fig.org/psr/psr-2/) coding style, ideally via your IDE settings (see below for phpStorm instructions).
147+
Please follow the [PSR-2](http://www.php-fig.org/psr/psr-2/) coding style, ideally via your IDE settings (see below for PhpStorm instructions).
148148

149149
Please make sure that exiting Unit and Integration tests don't fail and fully cover your new code with Unit Tests. You can run all tests locally:
150150

@@ -172,9 +172,9 @@ php -S localhost:8000 -t docroot
172172

173173
Now navigate to [http://localhost:8000](http://localhost:8000) in your browser.
174174

175-
### phpStorm configuration
175+
### PhpStorm configuration
176176

177-
To enable code style checks directly in phpStorm you have to configure the path to the phpcs at Preferences > Languages & Frameworks > PHP > Code Sniffer.
177+
To enable code style checks directly in PhpStorm you have to configure the path to the phpcs at Preferences > Languages & Frameworks > PHP > Code Sniffer.
178178
Now you can enable at Preferences > Editor > Inspections > PHP the "PHP code sniffer validation" with PSR-2 standard. Change the severity if needed.
179179

180180

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"monolog/monolog": "^1.12",
4747
"behat/behat": "^3.0",
4848
"phpunit/phpcov": "*",
49-
"fabpot/php-cs-fixer": "@stable",
49+
"friendsofphp/php-cs-fixer": "@stable",
5050
"symfony/yaml": "*",
5151
"cache/array-adapter": "^0.4.0",
5252
"cache/filesystem-adapter": "^0.3.0",
@@ -60,6 +60,9 @@
6060
"post-install-cmd": "@updateConfig"
6161
},
6262
"extra": {
63+
"branch-alias": {
64+
"dev-develop": "1.4-dev"
65+
},
6366
"incenteev-parameters": [
6467
{
6568
"file": "docroot/myapp.yml",

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.3.1';
17+
const VERSION = '1.4.0';
1818

1919
/**
2020
* @var AdapterInterface

src/Client/Adapter/Guzzle6Adapter.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace Commercetools\Core\Client\Adapter;
77

8+
use Commercetools\Core\Response\AbstractApiResponse;
89
use GuzzleHttp\Client;
910
use GuzzleHttp\Exception\RequestException;
1011
use GuzzleHttp\MessageFormatter;
@@ -16,6 +17,7 @@
1617
use Psr\Log\LoggerInterface;
1718
use Commercetools\Core\Error\Message;
1819
use Commercetools\Core\Error\ApiException;
20+
use Psr\Log\LogLevel;
1921

2022
class Guzzle6Adapter implements AdapterInterface
2123
{
@@ -44,7 +46,48 @@ public function __construct(array $options = [])
4446
public function setLogger(LoggerInterface $logger)
4547
{
4648
$this->logger = $logger;
47-
$this->addHandler(Middleware::log($logger, new MessageFormatter()));
49+
$this->addHandler(self::log($logger, new MessageFormatter()));
50+
}
51+
52+
/**
53+
* Middleware that logs requests, responses, and errors using a message
54+
* formatter.
55+
*
56+
* @param LoggerInterface $logger Logs messages.
57+
* @param MessageFormatter $formatter Formatter used to create message strings.
58+
* @param string $logLevel Level at which to log requests.
59+
*
60+
* @return callable Returns a function that accepts the next handler.
61+
*/
62+
private static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO)
63+
{
64+
return function (callable $handler) use ($logger, $formatter, $logLevel) {
65+
return function ($request, array $options) use ($handler, $logger, $formatter, $logLevel) {
66+
return $handler($request, $options)->then(
67+
function ($response) use ($logger, $request, $formatter, $logLevel) {
68+
$message = $formatter->format($request, $response);
69+
$context[AbstractApiResponse::X_CORRELATION_ID] = $response->getHeader(
70+
AbstractApiResponse::X_CORRELATION_ID
71+
);
72+
$logger->log($logLevel, $message, $context);
73+
return $response;
74+
},
75+
function ($reason) use ($logger, $request, $formatter) {
76+
$response = null;
77+
$context = [];
78+
if ($reason instanceof RequestException) {
79+
$response = $reason->getResponse();
80+
$context[AbstractApiResponse::X_CORRELATION_ID] = $response->getHeader(
81+
AbstractApiResponse::X_CORRELATION_ID
82+
);
83+
}
84+
$message = $formatter->format($request, $response, $reason);
85+
$logger->notice($message, $context);
86+
return \GuzzleHttp\Promise\rejection_for($reason);
87+
}
88+
);
89+
};
90+
};
4891
}
4992

5093
public function addHandler($handler)

src/Error/Message.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Message
2727
const UNKNOWN_METHOD = 'Unknown method: %s';
2828
const UNKNOWN_FIELD = 'Unknown field: "%s" - called: %s(%s)';
2929
const WRONG_TYPE = 'Wrong type for field "%s". Expected %s.';
30+
const WRONG_ARGUMENT_TYPE = 'Wrong type for argument "%s". Expected %s.';
3031
const EXPECTS_PARAMETER = 'Excepts parameter "%s" to be %s, null given.';
3132

3233
const NO_LANGUAGES_PROVIDED = 'No languages provided';

src/Helper/State/Renderer/TransitionRenderer.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ public function render(State $state)
2020
$graph = '';
2121
$color = static::COMMAND_COLOR;
2222

23-
foreach ($state->getTransitions() as $transition) {
24-
/**
25-
* @var State $targetState
26-
*/
27-
$targetState = $transition->getObj();
28-
if ($targetState->getKey() === $state->getKey()) {
29-
$graph .= ' edge[dir="back",style="solid",color="' . $color . '"] state_'
30-
. $state->getKey() . ' -> state_' . $state->getKey() . ';' . PHP_EOL;
31-
} else {
32-
$graph .= ' edge[dir="forward",style="solid",color="' . $color . '"] state_'
33-
. $state->getKey() . ' -> state_' . $targetState->getKey() . ' ;' . PHP_EOL;
23+
if ($state->getTransitions()) {
24+
foreach ($state->getTransitions() as $transition) {
25+
/**
26+
* @var State $targetState
27+
*/
28+
$targetState = $transition->getObj();
29+
if ($targetState->getKey() === $state->getKey()) {
30+
$graph .= ' edge[dir="back",style="solid",color="' . $color . '"] state_'
31+
. $state->getKey() . ' -> state_' . $state->getKey() . ';' . PHP_EOL;
32+
} else {
33+
$graph .= ' edge[dir="forward",style="solid",color="' . $color . '"] state_'
34+
. $state->getKey() . ' -> state_' . $targetState->getKey() . ' ;' . PHP_EOL;
35+
}
3436
}
3537
}
3638

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Model\Cart;
7+
8+
use Commercetools\Core\Model\Common\JsonObject;
9+
use Commercetools\Core\Model\DiscountCode\DiscountCodeReference;
10+
use Commercetools\Core\Model\Common\Money;
11+
12+
/**
13+
* @package Commercetools\Core\Model\Cart
14+
* @link https://dev.commercetools.com/http-api-projects-carts.html#externallineitemtotalprice
15+
* @method Money getPrice()
16+
* @method ExternalLineItemTotalPrice setPrice(Money $price = null)
17+
* @method Money getTotalPrice()
18+
* @method ExternalLineItemTotalPrice setTotalPrice(Money $totalPrice = null)
19+
*/
20+
class ExternalLineItemTotalPrice extends JsonObject
21+
{
22+
public function fieldDefinitions()
23+
{
24+
return [
25+
'price' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
26+
'totalPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\Money']
27+
];
28+
}
29+
}

src/Model/Cart/LineItem.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@
4848
* @method DiscountedPricePerQuantityCollection getDiscountedPricePerQuantity()
4949
* @method TaxedItemPrice getTaxedPrice()
5050
* @method LineItem setTaxedPrice(TaxedItemPrice $taxedPrice = null)
51+
* @method string getPriceMode()
52+
* @method LineItem setPriceMode(string $priceMode = null)
5153
*/
5254
class LineItem extends JsonObject
5355
{
56+
const PRICE_MODE_PLATFORM = 'Platform';
57+
const PRICE_MODE_EXTERNAL_TOTAL = 'ExternalTotal';
58+
5459
public function fieldDefinitions()
5560
{
5661
return [
@@ -71,6 +76,7 @@ public function fieldDefinitions()
7176
'discountedPricePerQuantity' => [
7277
static::TYPE => '\Commercetools\Core\Model\Cart\DiscountedPricePerQuantityCollection'
7378
],
79+
'priceMode' => [static::TYPE => 'string']
7480
];
7581
}
7682

src/Model/Common/Reference.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66

77
namespace Commercetools\Core\Model\Common;
88

9+
use Commercetools\Core\Model\Cart\CartReference;
10+
use Commercetools\Core\Model\CartDiscount\CartDiscountReference;
11+
use Commercetools\Core\Model\Category\CategoryReference;
12+
use Commercetools\Core\Model\Channel\ChannelReference;
13+
use Commercetools\Core\Model\Customer\CustomerReference;
14+
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
15+
use Commercetools\Core\Model\CustomObject\CustomObjectReference;
16+
use Commercetools\Core\Model\DiscountCode\DiscountCodeReference;
17+
use Commercetools\Core\Model\Order\OrderReference;
18+
use Commercetools\Core\Model\Payment\PaymentReference;
19+
use Commercetools\Core\Model\Product\ProductReference;
20+
use Commercetools\Core\Model\ProductDiscount\ProductDiscountReference;
21+
use Commercetools\Core\Model\ProductType\ProductTypeReference;
22+
use Commercetools\Core\Model\ShippingMethod\ShippingMethodReference;
23+
use Commercetools\Core\Model\State\StateReference;
24+
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
25+
use Commercetools\Core\Model\Type\TypeReference;
26+
use Commercetools\Core\Model\Zone\ZoneReference;
27+
928
/**
1029
* @package Commercetools\Core\Model\Common
1130
* @link https://dev.commercetools.com/http-api-types.html#reference
@@ -31,4 +50,49 @@ public function fieldDefinitions()
3150

3251
return $fieldDefinitions;
3352
}
53+
54+
/**
55+
* @param array $data
56+
* @param Context|callable $context
57+
* @return static
58+
*/
59+
public static function fromArray(array $data, $context = null)
60+
{
61+
if (get_called_class() == 'Commercetools\Core\Model\Common\Reference' && isset($data[static::TYPE_ID])) {
62+
$className = static::referenceType($data[static::TYPE_ID]);
63+
if (class_exists($className)) {
64+
return new $className($data, $context);
65+
}
66+
}
67+
return new static($data, $context);
68+
}
69+
70+
protected static function referenceType($typeId)
71+
{
72+
$types = [
73+
CartReference::TYPE_CART => '\Commercetools\Core\Model\Cart\CartReference',
74+
CartDiscountReference::TYPE_CART_DISCOUNT => '\Commercetools\Core\Model\CartDiscount\CartDiscountReference',
75+
CategoryReference::TYPE_CATEGORY => '\Commercetools\Core\Model\Category\CategoryReference',
76+
ChannelReference::TYPE_CHANNEL => '\Commercetools\Core\Model\Channel\ChannelReference',
77+
CustomerReference::TYPE_CUSTOMER => '\Commercetools\Core\Model\Customer\CustomerReference',
78+
CustomObjectReference::TYPE_CUSTOM_OBJECT => '\Commercetools\Core\Model\CustomObject\CustomObjectReference',
79+
CustomerGroupReference::TYPE_CUSTOMER_GROUP =>
80+
'\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference',
81+
DiscountCodeReference::TYPE_DISCOUNT_CODE => '\Commercetools\Core\Model\DiscountCode\DiscountCodeReference',
82+
CustomObjectReference::TYPE_CUSTOM_OBJECT => '\Commercetools\Core\Model\CustomObject\CustomObjectReference',
83+
PaymentReference::TYPE_PAYMENT => '\Commercetools\Core\Model\Payment\PaymentReference',
84+
ProductReference::TYPE_PRODUCT => '\Commercetools\Core\Model\Product\ProductReference',
85+
ProductDiscountReference::TYPE_PRODUCT_DISCOUNT =>
86+
'\Commercetools\Core\Model\ProductDiscount\ProductDiscountReference',
87+
ProductTypeReference::TYPE_PRODUCT_TYPE => '\Commercetools\Core\Model\ProductType\ProductTypeReference',
88+
OrderReference::TYPE_ORDER => '\Commercetools\Core\Model\Order\OrderReference',
89+
ShippingMethodReference::TYPE_SHIPPING_METHOD =>
90+
'\Commercetools\Core\Model\ShippingMethod\ShippingMethodReference',
91+
StateReference::TYPE_STATE => '\Commercetools\Core\Model\State\StateReference',
92+
TaxCategoryReference::TYPE_TAX_CATEGORY => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference',
93+
TypeReference::TYPE_TYPE => '\Commercetools\Core\Model\Type\TypeReference',
94+
ZoneReference::TYPE_ZONE => '\Commercetools\Core\Model\Zone\ZoneReference',
95+
];
96+
return isset($types[$typeId]) ? $types[$typeId] : '\Commercetools\Core\Model\Common\Reference';
97+
}
3498
}

0 commit comments

Comments
 (0)