diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 432bb58c84..67e6a86ead 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1 +1 @@
-* @commercetools/clients-sdk-team
+* @commercetools/clients-team
diff --git a/.github/workflows/add_issues_to_project.yml b/.github/workflows/add_issues_to_project.yml
new file mode 100644
index 0000000000..f82274b53a
--- /dev/null
+++ b/.github/workflows/add_issues_to_project.yml
@@ -0,0 +1,16 @@
+name: Add Issues to project
+on:
+ issues:
+ types:
+ - opened
+jobs:
+ add_issues:
+ uses: commercetools/clients-automation/.github/workflows/workflow_issues_pr_to_project.yml@v1
+ with:
+ node_id: ${{ github.event.issue.node_id }}
+ org: commercetools
+ project: 32
+ repository: ${{ github.event.repository.name }}
+ login: ${{ github.event.issue.user.login }}
+ secrets:
+ token: ${{ secrets.PROJECT_TOKEN }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 099e53ad30..67073ec08c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -90,6 +90,7 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
+ - "8.1"
dependencies:
- lowest
@@ -165,22 +166,22 @@ jobs:
php7.4-composer-highest-
- name: Install highest dependencies with composer
+ run: composer update --no-ansi --no-interaction --no-progress --no-suggest
+
+ - name: Run integration tests with phpunit for push
if: github.event_name != 'pull_request'
env:
COMMERCETOOLS_CLIENT_ID: ${{ secrets.COMMERCETOOLS_CLIENT_ID }}
COMMERCETOOLS_CLIENT_SECRET: ${{ secrets.COMMERCETOOLS_CLIENT_SECRET }}
COMMERCETOOLS_PROJECT: ${{ secrets.COMMERCETOOLS_PROJECT }}
- run: composer update --no-ansi --no-interaction --no-progress --no-suggest
+ run: vendor/bin/phpunit --coverage-clover=coverage.xml
- - name: Install highest dependencies with composer for PR
+ - name: Run integration tests with phpunit for PR
if: github.event_name == 'pull_request'
env:
COMMERCETOOLS_CLIENT_ID: ${{ secrets.PR_COMMERCETOOLS_CLIENT_ID }}
COMMERCETOOLS_CLIENT_SECRET: ${{ secrets.PR_COMMERCETOOLS_CLIENT_SECRET }}
COMMERCETOOLS_PROJECT: ${{ secrets.PR_COMMERCETOOLS_PROJECT }}
- run: composer update --no-ansi --no-interaction --no-progress --no-suggest
-
- - name: Run integration tests with phpunit
run: vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Send code coverage report to Codecov.io
@@ -208,10 +209,6 @@ jobs:
ini-values: assert.exception=1, zend.assertions=1, apc.enabled=1, apc.enable_cli=1
- name: Install dependencies with composer
- env:
- COMMERCETOOLS_CLIENT_ID: ${{ secrets.COMMERCETOOLS_CLIENT_ID }}
- COMMERCETOOLS_CLIENT_SECRET: ${{ secrets.COMMERCETOOLS_CLIENT_SECRET }}
- COMMERCETOOLS_PROJECT: ${{ secrets.COMMERCETOOLS_PROJECT }}
run: composer install --no-ansi --no-interaction --no-progress --no-suggest --no-dev
- name: Retrieve branch name
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 86da16aa05..4020ba724c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,33 @@
+# [2.17.0](https://github.com/commercetools/commercetools-php-sdk/compare/v2.16.0...v2.17.0) (2022-02-07)
+
+
+### Features
+
+* **Cart:** add key in Cart ([d3f24c4](https://github.com/commercetools/commercetools-php-sdk/commit/d3f24c4b419d363fbcea10cb7f44903025d1c5c9))
+* **Cart:** add new field productkey ([ccd77b8](https://github.com/commercetools/commercetools-php-sdk/commit/ccd77b88d03f77e117521db6f9ce8ee78c740cfb))
+* **Cart:** add test for replicate cart in store ([ec6390d](https://github.com/commercetools/commercetools-php-sdk/commit/ec6390d3235ebf8df9a7b57fd8e80638918e59c5))
+* **Cart:** introduce more small features ([ba45fc5](https://github.com/commercetools/commercetools-php-sdk/commit/ba45fc54d3df1e5e39f296ff37866663d02442bc))
+* **Cart:** support new update action setLineItemSupplyChannel ([87887cb](https://github.com/commercetools/commercetools-php-sdk/commit/87887cb1e05bdc769ae1a652f7d014ee479b98ea))
+* **Customer:** add anonymousCart field ([4c45b41](https://github.com/commercetools/commercetools-php-sdk/commit/4c45b419573de216e34cb11b251364224b1d8f9c))
+* **Delivery:** add field param ([c7ad278](https://github.com/commercetools/commercetools-php-sdk/commit/c7ad278fc2dba0ac513fdbcc3a6166ef86463c85))
+* **Error:** add querytimeout error ([ec13853](https://github.com/commercetools/commercetools-php-sdk/commit/ec1385355be85bd9901215bd0515d9de04d70f87))
+* **Error:** add querytimeout error ([153cc0b](https://github.com/commercetools/commercetools-php-sdk/commit/153cc0bdd3eee9d0adff330aeefb176f4a6c0e7d))
+* **Head:** support Head method for products ([6a02a6b](https://github.com/commercetools/commercetools-php-sdk/commit/6a02a6be34237f46dd2424750f6e08941fd1e06e))
+* **Message:** add field in InventoryEntryQuantitySetMessage ([7008f32](https://github.com/commercetools/commercetools-php-sdk/commit/7008f32ae9b83c8c50b2378a59a3d68ff3f9d873))
+* **Message:** add new class as useProvidedIdentifiers for ContainerAndKey ([3d332fd](https://github.com/commercetools/commercetools-php-sdk/commit/3d332fd5dff35396920a67a7f6c3fb8ea5a76cb9))
+* **Message:** add new message for products ([1e6e5ad](https://github.com/commercetools/commercetools-php-sdk/commit/1e6e5add27a4018b7469e586c518cba21f627680))
+* **Message:** support oldState to OrderStateTransitionMessage and support store messages ([b56c7ed](https://github.com/commercetools/commercetools-php-sdk/commit/b56c7ed830661a7d6b81818f55926d8100576013))
+* **Order:** support new update actions setReturnItemCustom as for order as for order edit ([d2e3879](https://github.com/commercetools/commercetools-php-sdk/commit/d2e38793890fc018908280c2d63537b50bfdbca9))
+* **Order:** support setReturnInfoAction and related message ([b34aa6b](https://github.com/commercetools/commercetools-php-sdk/commit/b34aa6bfef43a311d64419b015b6d5ff54764941))
+* **Order:** support update actions for Order and Order Edit to SetParcelCustom ([0124793](https://github.com/commercetools/commercetools-php-sdk/commit/0124793e950f793346bcdca7b238d2ca63c555c6))
+* **Project:** add new actions and add customer message ([e97e521](https://github.com/commercetools/commercetools-php-sdk/commit/e97e521be1d8739f0291f5246441f02fe4f68fe4))
+* **Project:** fix failed test ([b8357d0](https://github.com/commercetools/commercetools-php-sdk/commit/b8357d02643e980ddab735eb0bb2050b1117e408))
+* **ShipingMethod:** add custom field and related action in shipping method ([5a9a3f9](https://github.com/commercetools/commercetools-php-sdk/commit/5a9a3f972781f25a744b599462834cc83ef603b8))
+* **ShippingMethod:** support localizedName and related action ([50dbb24](https://github.com/commercetools/commercetools-php-sdk/commit/50dbb24e08d2553fbd09b73065e36c89b5c4ddd8))
+* **UserAgent:** modify user agent ([aa7f055](https://github.com/commercetools/commercetools-php-sdk/commit/aa7f05537bfecd792d2feeb6cbb41d06991c010f))
+
+
+
# [2.16.0](https://github.com/commercetools/commercetools-php-sdk/compare/v2.15.0...v2.16.0) (2021-08-02)
diff --git a/README.md b/README.md
index 79d15a1df3..c4396f1dd0 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,13 @@
# commercetools PHP SDK
+:warning: **This commercetools PHP SDK is in its Active Support mode currently, and is planned to be deprecated, please note the following dates.
+
+| Active Support | Maintenance Support | End of Life |
+| --------------------- | --------------------- | --------------------- |
+| `28th February, 2022` | `31st August 2022.` | `1st September 2022.` |
+
+We recommend to use our [PHP SDK V2](https://docs.commercetools.com/sdk/php-sdk#php-sdk-v2).
+
[![Build Status](https://img.shields.io/travis/com/commercetools/commercetools-php-sdk/master.svg?style=flat-square)](https://travis-ci.com/commercetools/commercetools-php-sdk) [![Scrutinizer](https://img.shields.io/scrutinizer/g/commercetools/commercetools-php-sdk.svg?style=flat-square)](https://scrutinizer-ci.com/g/commercetools/commercetools-php-sdk/) [![Scrutinizer](https://img.shields.io/scrutinizer/coverage/g/commercetools/commercetools-php-sdk.svg?style=flat-square)](https://scrutinizer-ci.com/g/commercetools/commercetools-php-sdk/) [![Packagist](https://img.shields.io/packagist/v/commercetools/php-sdk.svg?style=flat-square)](https://packagist.org/packages/commercetools/php-sdk) [![Packagist](https://img.shields.io/packagist/dm/commercetools/php-sdk.svg?style=flat-square)](https://packagist.org/packages/commercetools/php-sdk)
The PHP SDK allows developers to build applications on the commercetools platform (technically speaking against our REST API) using PHP native interfaces, models and helpers instead of manually using the HTTP and JSON API.
@@ -252,6 +260,64 @@ $middlewares = [
$config = Config::of()->setClientOptions(['middlewares' => $middlewares])
```
+#### Timeouts
+
+The clients are configured to timeout by default after 60 seconds. This can be changed by setting the client options in the Config instance
+
+```php
+$config = Config::of()->setClientOptions([
+ 'defaults' => [
+ 'timeout' => 10
+ ]
+])
+```
+
+Another option is to specify the timeout per request
+
+```php
+$request = ProductProjectionSearchRequest::of();
+$response = $client->execute($request, null, ['timeout' => 10]);
+```
+
+#### Retrying
+
+As a request can error in multiple ways it's possible to add a retry middleware to the client config. E.g.: Retrying in case of service unavailable errors
+
+```php
+$config = Config::of()->setClientOptions([
+ 'defaults' => [
+ 'timeout' => 10
+ ]
+])
+$maxRetries = 3;
+$clientOptions = [
+ 'middlewares' => [
+ 'retry' => Middleware::retry(
+ function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) use ($maxRetries) {
+ if ($response instanceof ResponseInterface && $response->getStatusCode() < 500) {
+ return false;
+ }
+ if ($retries > $maxRetries) {
+ return false;
+ }
+ if ($error instanceof ServiceUnavailableException) {
+ return true;
+ }
+ if ($error instanceof ServerException && $error->getCode() == 503) {
+ return true;
+ }
+ if ($response instanceof ResponseInterface && $response->getStatusCode() == 503) {
+ return true;
+ }
+ return false;
+ },
+ [RetryMiddleware::class, 'exponentialDelay']
+ )
+ ]
+];
+$config->setClientOptions($clientOptions);
+```
+
### Using the phar distribution
Since version 1.6 the SDK is also released as a PHAR. You can find them in the [releases section](https://github.com/commercetools/commercetools-php-sdk/releases) at Github.
diff --git a/composer.json b/composer.json
index b20ddbd88a..7ff2ccd092 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "commercetools/php-sdk",
"license": "MIT",
"type": "project",
- "description": "The commercetools PHP SDK \n The official PHP Interface to the commercetools eCommerce API",
+ "description": "This SDK is announced to be deprecated latest by 31 August 2022, please follow more details on SDK deprecation plan https://docs.commercetools.com/api/releases/2021-08-31-announced-long-term-support-plan-for-commercetools-sdks. We recommend you to use our new SDK here https://docs.commercetools.com/sdk/php-sdk#php-sdk-v2.",
"homepage": "https://github.com/commercetools/commercetools-php-sdk",
"support": {
"email": "support@commercetools.com",
@@ -31,10 +31,10 @@
},
"require": {
"php": ">=5.6",
- "psr/log": "^1.0",
+ "psr/log": "^1.0 || ^2.0",
"guzzlehttp/guzzle": "^7.0 || ^6.0 || ^5.3.3 ",
"guzzlehttp/psr7": "^1.7 || ^2.0",
- "psr/cache": "^1.0 || ^2.0",
+ "psr/cache": "^1.0 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0",
"cache/apcu-adapter": "^1.0 || ^0.3 || ^0.2",
"paragonie/random_compat": "^2.0 || ^1.0 || ^9.99",
@@ -42,13 +42,13 @@
},
"require-dev": {
"guzzlehttp/guzzle": "^7.0 || ^6.0",
- "phpunit/phpunit": "^9.0",
+ "phpunit/phpunit": "9.5.10",
"phpspec/prophecy-phpunit": "^2.0",
- "symplify/easy-coding-standard-prefixed": "8.3.48 || 9.2.23",
+ "symplify/easy-coding-standard": "10.0.2",
"doctrine/cache": "^1.6 || ^2.0",
"monolog/monolog": "^1.12 || ^2.0",
- "symfony/yaml": "^4.0 || ^3.4.38",
- "symfony/stopwatch": "^4.0 || ^3.4.38",
+ "symfony/yaml": "^4.0 || ^3.4.38 || ^5.0",
+ "symfony/stopwatch": "^4.0 || ^3.4.38 || ^5.0",
"cache/adapter-common": "^1.0",
"cache/apcu-adapter": "^1.0",
"cache/array-adapter": "^1.0",
diff --git a/package.json b/package.json
index 78e6743fde..c339c10d78 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "commercetools-php-sdk-changelog",
- "version": "2.16.0",
+ "version": "2.17.0",
"description": "commercetools PHP SDK changelog generator package description",
"homepage": "https://github.com/commercetools/commercetools-php-sdk",
"bugs": "https://github.com/commercetools/commercetools-php-sdk/issues",
diff --git a/renovate.json b/renovate.json
index bac3c8b16c..9c0a969687 100644
--- a/renovate.json
+++ b/renovate.json
@@ -22,5 +22,5 @@
"labels": [
"Type: Maintenance"
],
- "ignoreDeps": []
+ "ignoreDeps": ["symplify/easy-coding-standard-prefixed"]
}
diff --git a/src/Core/AbstractHttpClient.php b/src/Core/AbstractHttpClient.php
index 5ee0f2b10e..ffaafcc31d 100644
--- a/src/Core/AbstractHttpClient.php
+++ b/src/Core/AbstractHttpClient.php
@@ -14,7 +14,7 @@
*/
abstract class AbstractHttpClient
{
- const VERSION = '2.16.0';
+ const VERSION = '2.17.0';
/**
* @var AdapterInterface
diff --git a/src/Core/Builder/Request/CartRequestBuilder.php b/src/Core/Builder/Request/CartRequestBuilder.php
index 195347d280..3296106904 100644
--- a/src/Core/Builder/Request/CartRequestBuilder.php
+++ b/src/Core/Builder/Request/CartRequestBuilder.php
@@ -4,12 +4,15 @@
use Commercetools\Core\Request\Carts\CartByCustomerIdGetRequest;
use Commercetools\Core\Request\Carts\CartByIdGetRequest;
+use Commercetools\Core\Request\Carts\CartByKeyGetRequest;
use Commercetools\Core\Request\Carts\CartCreateRequest;
use Commercetools\Core\Model\Cart\CartDraft;
-use Commercetools\Core\Request\Carts\CartDeleteRequest;
+use Commercetools\Core\Request\Carts\CartDeleteByKeyRequest;
use Commercetools\Core\Model\Cart\Cart;
+use Commercetools\Core\Request\Carts\CartDeleteRequest;
use Commercetools\Core\Request\Carts\CartQueryRequest;
use Commercetools\Core\Request\Carts\CartReplicateRequest;
+use Commercetools\Core\Request\Carts\CartUpdateByKeyRequest;
use Commercetools\Core\Request\Carts\CartUpdateRequest;
class CartRequestBuilder
@@ -37,6 +40,17 @@ public function getById($id)
return $request;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/carts#get-a-cart-by-key
+ * @param string $key
+ * @return CartByKeyGetRequest
+ */
+ public function getByKey($key)
+ {
+ $request = CartByKeyGetRequest::ofKey($key);
+ return $request;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-carts.html#create-cart
* @param CartDraft $cartDraft
@@ -48,6 +62,17 @@ public function create(CartDraft $cartDraft)
return $request;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/carts#delete-a-cart-by-key
+ * @param Cart $cart
+ * @return CartDeleteByKeyRequest
+ */
+ public function deleteByKey(Cart $cart)
+ {
+ $request = CartDeleteByKeyRequest::ofKeyAndVersion($cart->getKey(), $cart->getVersion());
+ return $request;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-carts.html#delete-cart
* @param Cart $cart
@@ -81,6 +106,17 @@ public function replicate($cartId)
return $request;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/carts#update-a-cart-by-key
+ * @param Cart $cart
+ * @return CartUpdateByKeyRequest
+ */
+ public function updateByKey(Cart $cart)
+ {
+ $request = CartUpdateByKeyRequest::ofKeyAndVersion($cart->getKey(), $cart->getVersion());
+ return $request;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-carts.html#update-cart
* @param Cart $cart
diff --git a/src/Core/Builder/Request/CustomerRequestBuilder.php b/src/Core/Builder/Request/CustomerRequestBuilder.php
index 9c02763462..bb22899389 100644
--- a/src/Core/Builder/Request/CustomerRequestBuilder.php
+++ b/src/Core/Builder/Request/CustomerRequestBuilder.php
@@ -14,6 +14,7 @@
use Commercetools\Core\Request\Customers\CustomerEmailConfirmRequest;
use Commercetools\Core\Request\Customers\CustomerEmailTokenRequest;
use Commercetools\Core\Request\Customers\CustomerLoginRequest;
+use Commercetools\Core\Model\Cart\CartReference;
use Commercetools\Core\Request\Customers\CustomerPasswordChangeRequest;
use Commercetools\Core\Request\Customers\CustomerPasswordResetRequest;
use Commercetools\Core\Request\Customers\CustomerPasswordTokenRequest;
@@ -129,16 +130,16 @@ public function createEmailVerificationToken(Customer $customer, $ttlMinutes)
* @param string $email
* @param string $password
* @param bool $updateProductData
- * @param string $anonymousCartId
+ * @param CartReference|string $anonymousCart
* @return CustomerLoginRequest
*/
- public function login($email, $password, $updateProductData = false, $anonymousCartId = null)
+ public function login($email, $password, $updateProductData = false, $anonymousCart = null)
{
$request = CustomerLoginRequest::ofEmailPasswordAndUpdateProductData(
$email,
$password,
$updateProductData,
- $anonymousCartId
+ $anonymousCart
);
return $request;
}
diff --git a/src/Core/Builder/Request/OrderRequestBuilder.php b/src/Core/Builder/Request/OrderRequestBuilder.php
index 8421b828e9..6e9e7e4dd2 100644
--- a/src/Core/Builder/Request/OrderRequestBuilder.php
+++ b/src/Core/Builder/Request/OrderRequestBuilder.php
@@ -6,6 +6,7 @@
use Commercetools\Core\Request\Orders\OrderByOrderNumberGetRequest;
use Commercetools\Core\Request\Orders\OrderCreateFromCartRequest;
use Commercetools\Core\Model\Cart\Cart;
+use Commercetools\Core\Model\Cart\CartReference;
use Commercetools\Core\Request\Orders\OrderDeleteByOrderNumberRequest;
use Commercetools\Core\Model\Order\Order;
use Commercetools\Core\Request\Orders\OrderDeleteRequest;
@@ -47,7 +48,7 @@ public function getByOrderNumber($orderNumber)
*/
public function createFromCart(Cart $cart)
{
- $request = OrderCreateFromCartRequest::ofCartIdAndVersion($cart->getId(), $cart->getVersion());
+ $request = OrderCreateFromCartRequest::ofCartAndVersion(CartReference::ofId($cart->getId()), $cart->getVersion());
return $request;
}
diff --git a/src/Core/Builder/Request/ProductRequestBuilder.php b/src/Core/Builder/Request/ProductRequestBuilder.php
index bc252457b1..102e7ceb05 100644
--- a/src/Core/Builder/Request/ProductRequestBuilder.php
+++ b/src/Core/Builder/Request/ProductRequestBuilder.php
@@ -3,12 +3,15 @@
namespace Commercetools\Core\Builder\Request;
use Commercetools\Core\Request\Products\ProductByIdGetRequest;
+use Commercetools\Core\Request\Products\ProductByIdHeadRequest;
use Commercetools\Core\Request\Products\ProductByKeyGetRequest;
+use Commercetools\Core\Request\Products\ProductByKeyHeadRequest;
use Commercetools\Core\Request\Products\ProductCreateRequest;
use Commercetools\Core\Model\Product\ProductDraft;
use Commercetools\Core\Request\Products\ProductDeleteByKeyRequest;
use Commercetools\Core\Model\Product\Product;
use Commercetools\Core\Request\Products\ProductDeleteRequest;
+use Commercetools\Core\Request\Products\ProductHeadRequest;
use Commercetools\Core\Request\Products\ProductImageUploadRequest;
use Psr\Http\Message\UploadedFileInterface;
use Commercetools\Core\Request\Products\ProductQueryRequest;
@@ -29,6 +32,17 @@ public function getById($id)
return $request;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/products#by-id
+ * @param string $id
+ * @return ProductByIdHeadRequest
+ */
+ public function getByIdHead($id)
+ {
+ $request = ProductByIdHeadRequest::ofId($id);
+ return $request;
+ }
+
/**
*
* @param string $key
@@ -40,6 +54,17 @@ public function getByKey($key)
return $request;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/products#by-key
+ * @param string $key
+ * @return ProductByKeyHeadRequest
+ */
+ public function getByKeyHead($key)
+ {
+ $request = ProductByKeyHeadRequest::ofKey($key);
+ return $request;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-products.html#create-a-product
* @param ProductDraft $product
@@ -73,6 +98,17 @@ public function delete(Product $product)
return $request;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/products#by-query-predicate
+ *
+ * @return ProductHeadRequest
+ */
+ public function head()
+ {
+ $request = ProductHeadRequest::of();
+ return $request;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-products.html#upload-a-product-image
* @param string $id
diff --git a/src/Core/Builder/Update/ActionBuilder.php b/src/Core/Builder/Update/ActionBuilder.php
index 6ae3c1a9a7..fe8dc423a0 100644
--- a/src/Core/Builder/Update/ActionBuilder.php
+++ b/src/Core/Builder/Update/ActionBuilder.php
@@ -84,6 +84,14 @@ public function inventory()
return new InventoryActionBuilder();
}
+ /**
+ * @return MeActionBuilder
+ */
+ public function me()
+ {
+ return new MeActionBuilder();
+ }
+
/**
* @return OrderEditsActionBuilder
*/
diff --git a/src/Core/Builder/Update/CartsActionBuilder.php b/src/Core/Builder/Update/CartsActionBuilder.php
index 50d4ee84a6..355aab68b5 100644
--- a/src/Core/Builder/Update/CartsActionBuilder.php
+++ b/src/Core/Builder/Update/CartsActionBuilder.php
@@ -44,10 +44,13 @@
use Commercetools\Core\Request\Carts\Command\CartSetDeleteDaysAfterLastModificationAction;
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomFieldAction;
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomTypeAction;
+use Commercetools\Core\Request\Carts\Command\CartSetKeyAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction;
+use Commercetools\Core\Request\Carts\Command\CartSetLineItemDistributionChannelAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemShippingDetailsAction;
+use Commercetools\Core\Request\Carts\Command\CartSetLineItemSupplyChannelAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxRateAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction;
@@ -506,6 +509,17 @@ public function setItemShippingAddressCustomType($action = null)
return $this;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/carts#set-key-
+ * @param CartSetKeyAction|callable $action
+ * @return $this
+ */
+ public function setKey($action = null)
+ {
+ $this->addAction($this->resolveAction(CartSetKeyAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-customfield
* @param CartSetLineItemCustomFieldAction|callable $action
@@ -528,6 +542,17 @@ public function setLineItemCustomType($action = null)
return $this;
}
+ /**
+ *
+ * @param CartSetLineItemDistributionChannelAction|callable $action
+ * @return $this
+ */
+ public function setLineItemDistributionChannel($action = null)
+ {
+ $this->addAction($this->resolveAction(CartSetLineItemDistributionChannelAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
* @param CartSetLineItemPriceAction|callable $action
@@ -550,6 +575,17 @@ public function setLineItemShippingDetails($action = null)
return $this;
}
+ /**
+ *
+ * @param CartSetLineItemSupplyChannelAction|callable $action
+ * @return $this
+ */
+ public function setLineItemSupplyChannel($action = null)
+ {
+ $this->addAction($this->resolveAction(CartSetLineItemSupplyChannelAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxamount
* @param CartSetLineItemTaxAmountAction|callable $action
diff --git a/src/Core/Builder/Update/MeActionBuilder.php b/src/Core/Builder/Update/MeActionBuilder.php
new file mode 100644
index 0000000000..397b617190
--- /dev/null
+++ b/src/Core/Builder/Update/MeActionBuilder.php
@@ -0,0 +1,94 @@
+addAction($this->resolveAction(MyCartAddLineItemAction::class, $action));
+ return $this;
+ }
+
+ /**
+ * @return MeActionBuilder
+ */
+ public static function of()
+ {
+ return new self();
+ }
+
+ /**
+ * @param $class
+ * @param $action
+ * @return AbstractAction
+ * @throws InvalidArgumentException
+ */
+ private function resolveAction($class, $action = null)
+ {
+ if (is_null($action) || is_callable($action)) {
+ $callback = $action;
+ $emptyAction = $class::of();
+ $action = $this->callback($emptyAction, $callback);
+ }
+ if ($action instanceof $class) {
+ return $action;
+ }
+ throw new InvalidArgumentException(
+ sprintf('Expected method to be called with or callable to return %s', $class)
+ );
+ }
+
+ /**
+ * @param $action
+ * @param callable $callback
+ * @return AbstractAction
+ */
+ private function callback($action, callable $callback = null)
+ {
+ if (!is_null($callback)) {
+ $action = $callback($action);
+ }
+ return $action;
+ }
+
+ /**
+ * @param AbstractAction $action
+ * @return $this;
+ */
+ public function addAction(AbstractAction $action)
+ {
+ $this->actions[] = $action;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getActions()
+ {
+ return $this->actions;
+ }
+
+
+ /**
+ * @param array $actions
+ * @return $this
+ */
+ public function setActions(array $actions)
+ {
+ $this->actions = $actions;
+ return $this;
+ }
+}
diff --git a/src/Core/Builder/Update/OrdersActionBuilder.php b/src/Core/Builder/Update/OrdersActionBuilder.php
index ab4c6e0463..9a0ca5c280 100644
--- a/src/Core/Builder/Update/OrdersActionBuilder.php
+++ b/src/Core/Builder/Update/OrdersActionBuilder.php
@@ -39,9 +39,14 @@
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemShippingDetailsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetLocaleAction;
use Commercetools\Core\Request\Orders\Command\OrderSetOrderNumberAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetParcelCustomFieldAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetParcelCustomTypeAction;
use Commercetools\Core\Request\Orders\Command\OrderSetParcelItemsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetParcelMeasurementsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetParcelTrackingDataAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetReturnInfoAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetReturnItemCustomFieldAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetReturnItemCustomTypeAction;
use Commercetools\Core\Request\Orders\Command\OrderSetReturnPaymentStateAction;
use Commercetools\Core\Request\Orders\Command\OrderSetReturnShipmentStateAction;
use Commercetools\Core\Request\Orders\Command\OrderSetShippingAddress;
@@ -443,6 +448,28 @@ public function setOrderNumber($action = null)
return $this;
}
+ /**
+ *
+ * @param OrderSetParcelCustomFieldAction|callable $action
+ * @return $this
+ */
+ public function setParcelCustomField($action = null)
+ {
+ $this->addAction($this->resolveAction(OrderSetParcelCustomFieldAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param OrderSetParcelCustomTypeAction|callable $action
+ * @return $this
+ */
+ public function setParcelCustomType($action = null)
+ {
+ $this->addAction($this->resolveAction(OrderSetParcelCustomTypeAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-items
* @param OrderSetParcelItemsAction|callable $action
@@ -476,6 +503,39 @@ public function setParcelTrackingData($action = null)
return $this;
}
+ /**
+ * @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-items
+ * @param OrderSetReturnInfoAction|callable $action
+ * @return $this
+ */
+ public function setReturnInfo($action = null)
+ {
+ $this->addAction($this->resolveAction(OrderSetReturnInfoAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param OrderSetReturnItemCustomFieldAction|callable $action
+ * @return $this
+ */
+ public function setReturnItemCustomField($action = null)
+ {
+ $this->addAction($this->resolveAction(OrderSetReturnItemCustomFieldAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param OrderSetReturnItemCustomTypeAction|callable $action
+ * @return $this
+ */
+ public function setReturnItemCustomType($action = null)
+ {
+ $this->addAction($this->resolveAction(OrderSetReturnItemCustomTypeAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-orders.html#set-returnpaymentstate
* @param OrderSetReturnPaymentStateAction|callable $action
diff --git a/src/Core/Builder/Update/PaymentsActionBuilder.php b/src/Core/Builder/Update/PaymentsActionBuilder.php
index 5f277d4a63..f522a1b97a 100644
--- a/src/Core/Builder/Update/PaymentsActionBuilder.php
+++ b/src/Core/Builder/Update/PaymentsActionBuilder.php
@@ -25,6 +25,8 @@
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceCodeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceTextAction;
+use Commercetools\Core\Request\Payments\Command\PaymentSetTransactionCustomFieldAction;
+use Commercetools\Core\Request\Payments\Command\PaymentSetTransactionCustomTypeAction;
use Commercetools\Core\Request\Payments\Command\PaymentTransitionStateAction;
class PaymentsActionBuilder
@@ -262,6 +264,28 @@ public function setStatusInterfaceText($action = null)
return $this;
}
+ /**
+ *
+ * @param PaymentSetTransactionCustomFieldAction|callable $action
+ * @return $this
+ */
+ public function setTransactionCustomField($action = null)
+ {
+ $this->addAction($this->resolveAction(PaymentSetTransactionCustomFieldAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param PaymentSetTransactionCustomTypeAction|callable $action
+ * @return $this
+ */
+ public function setTransactionCustomType($action = null)
+ {
+ $this->addAction($this->resolveAction(PaymentSetTransactionCustomTypeAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-payments.html#transition-state
* @param PaymentTransitionStateAction|callable $action
diff --git a/src/Core/Builder/Update/ProjectActionBuilder.php b/src/Core/Builder/Update/ProjectActionBuilder.php
index 182f296f03..3c90bd89c6 100644
--- a/src/Core/Builder/Update/ProjectActionBuilder.php
+++ b/src/Core/Builder/Update/ProjectActionBuilder.php
@@ -11,6 +11,8 @@
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction;
+use Commercetools\Core\Request\Project\Command\ProjectChangeProductSearchIndexingEnabledAction;
+use Commercetools\Core\Request\Project\Command\ProjectChangeShoppingListsConfigurationAction;
use Commercetools\Core\Request\Project\Command\ProjectSetExternalOAuthAction;
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
@@ -95,6 +97,28 @@ public function changeName($action = null)
return $this;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/project#change-product-search-indexing-enabled
+ * @param ProjectChangeProductSearchIndexingEnabledAction|callable $action
+ * @return $this
+ */
+ public function changeProductSearchIndexingEnabled($action = null)
+ {
+ $this->addAction($this->resolveAction(ProjectChangeProductSearchIndexingEnabledAction::class, $action));
+ return $this;
+ }
+
+ /**
+ * @link https://docs.commercetools.com/http-api-projects-project.html#change-shopping-lists-configuration
+ * @param ProjectChangeShoppingListsConfigurationAction|callable $action
+ * @return $this
+ */
+ public function changeShoppingListsConfiguration($action = null)
+ {
+ $this->addAction($this->resolveAction(ProjectChangeShoppingListsConfigurationAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-project.html#set-externaloauth
* @param ProjectSetExternalOAuthAction|callable $action
diff --git a/src/Core/Builder/Update/ShippingMethodsActionBuilder.php b/src/Core/Builder/Update/ShippingMethodsActionBuilder.php
index cfd0ff0f50..2295e5a1f7 100644
--- a/src/Core/Builder/Update/ShippingMethodsActionBuilder.php
+++ b/src/Core/Builder/Update/ShippingMethodsActionBuilder.php
@@ -11,9 +11,12 @@
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodChangeTaxCategoryAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodRemoveShippingRateAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodRemoveZoneAction;
+use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetCustomFieldAction;
+use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetCustomTypeAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetDescriptionAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetKeyAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetLocalizedDescriptionAction;
+use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetLocalizedNameAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetPredicateAction;
class ShippingMethodsActionBuilder
@@ -97,6 +100,28 @@ public function removeZone($action = null)
return $this;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/shippingMethods#set-customfield
+ * @param ShippingMethodSetCustomFieldAction|callable $action
+ * @return $this
+ */
+ public function setCustomField($action = null)
+ {
+ $this->addAction($this->resolveAction(ShippingMethodSetCustomFieldAction::class, $action));
+ return $this;
+ }
+
+ /**
+ * @link https://docs.commercetools.com/api/projects/shippingMethods#set-customtype
+ * @param ShippingMethodSetCustomTypeAction|callable $action
+ * @return $this
+ */
+ public function setCustomType($action = null)
+ {
+ $this->addAction($this->resolveAction(ShippingMethodSetCustomTypeAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#set-description
* @param ShippingMethodSetDescriptionAction|callable $action
@@ -130,6 +155,17 @@ public function setLocalizedDescription($action = null)
return $this;
}
+ /**
+ * @link https://docs.commercetools.com/api/projects/shippingMethods#set-localized-name
+ * @param ShippingMethodSetLocalizedNameAction|callable $action
+ * @return $this
+ */
+ public function setLocalizedName($action = null)
+ {
+ $this->addAction($this->resolveAction(ShippingMethodSetLocalizedNameAction::class, $action));
+ return $this;
+ }
+
/**
* @link https://docs.commercetools.com/http-api-projects-shippingMethods.html#set-predicate
* @param ShippingMethodSetPredicateAction|callable $action
diff --git a/src/Core/Builder/Update/StagedOrderActionBuilder.php b/src/Core/Builder/Update/StagedOrderActionBuilder.php
index 57c7d9df17..ae93fe756e 100644
--- a/src/Core/Builder/Update/StagedOrderActionBuilder.php
+++ b/src/Core/Builder/Update/StagedOrderActionBuilder.php
@@ -54,6 +54,7 @@
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetItemShippingAddressCustomTypeAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemCustomFieldAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemCustomTypeAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemDistributionChannelAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemPriceAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemShippingDetailsAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemTaxAmountAction;
@@ -62,9 +63,14 @@
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLocaleAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetOrderNumberAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetOrderTotalTaxAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelCustomFieldAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelCustomTypeAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelItemsAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelMeasurementsAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelTrackingDataAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnInfoAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnItemCustomFieldAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnItemCustomTypeAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnPaymentStateAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnShipmentStateAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingAddressAction;
@@ -638,6 +644,17 @@ public function setLineItemCustomType($action = null)
return $this;
}
+ /**
+ *
+ * @param StagedOrderSetLineItemDistributionChannelAction|callable $action
+ * @return $this
+ */
+ public function setLineItemDistributionChannel($action = null)
+ {
+ $this->addAction($this->resolveAction(StagedOrderSetLineItemDistributionChannelAction::class, $action));
+ return $this;
+ }
+
/**
*
* @param StagedOrderSetLineItemPriceAction|callable $action
@@ -726,6 +743,28 @@ public function setOrderTotalTax($action = null)
return $this;
}
+ /**
+ *
+ * @param StagedOrderSetParcelCustomFieldAction|callable $action
+ * @return $this
+ */
+ public function setParcelCustomField($action = null)
+ {
+ $this->addAction($this->resolveAction(StagedOrderSetParcelCustomFieldAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param StagedOrderSetParcelCustomTypeAction|callable $action
+ * @return $this
+ */
+ public function setParcelCustomType($action = null)
+ {
+ $this->addAction($this->resolveAction(StagedOrderSetParcelCustomTypeAction::class, $action));
+ return $this;
+ }
+
/**
*
* @param StagedOrderSetParcelItemsAction|callable $action
@@ -759,6 +798,39 @@ public function setParcelTrackingData($action = null)
return $this;
}
+ /**
+ *
+ * @param StagedOrderSetReturnInfoAction|callable $action
+ * @return $this
+ */
+ public function setReturnInfo($action = null)
+ {
+ $this->addAction($this->resolveAction(StagedOrderSetReturnInfoAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param StagedOrderSetReturnItemCustomFieldAction|callable $action
+ * @return $this
+ */
+ public function setReturnItemCustomField($action = null)
+ {
+ $this->addAction($this->resolveAction(StagedOrderSetReturnItemCustomFieldAction::class, $action));
+ return $this;
+ }
+
+ /**
+ *
+ * @param StagedOrderSetReturnItemCustomTypeAction|callable $action
+ * @return $this
+ */
+ public function setReturnItemCustomType($action = null)
+ {
+ $this->addAction($this->resolveAction(StagedOrderSetReturnItemCustomTypeAction::class, $action));
+ return $this;
+ }
+
/**
*
* @param StagedOrderSetReturnPaymentStateAction|callable $action
diff --git a/src/Core/Client/ClientFactory.php b/src/Core/Client/ClientFactory.php
index fcede700ec..e903425c70 100644
--- a/src/Core/Client/ClientFactory.php
+++ b/src/Core/Client/ClientFactory.php
@@ -163,6 +163,63 @@
* $config = Config::of()->setClientOptions(['middlewares' => $middlewares])
* ```
*
+ * ### Timeouts
+ *
+ * The clients are configured to timeout by default after 60 seconds. This can be changed by setting the client options in the Config instance
+ *
+ * ```php
+ * $config = Config::of()->setClientOptions([
+ * 'defaults' => [
+ * 'timeout' => 10
+ * ]
+ * ])
+ * ```
+ *
+ * Another option is to specify the timeout per request
+ *
+ * ```php
+ * $request = ProductProjectionSearchRequest::of();
+ * $response = $client->execute($request, null, ['timeout' => 10]);
+ * ```
+ *
+ * ### Retrying
+ *
+ * As a request can error in multiple ways it's possible to add a retry middleware to the client config. E.g.: Retrying in case of service unavailable errors
+ *
+ * ```php
+ * $config = Config::of()->setClientOptions([
+ * 'defaults' => [
+ * 'timeout' => 10
+ * ]
+ * ])
+ * $maxRetries = 3;
+ * $clientOptions = [
+ * 'middlewares' => [
+ * 'retry' => Middleware::retry(
+ * function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) use ($maxRetries) {
+ * if ($response instanceof ResponseInterface && $response->getStatusCode() < 500) {
+ * return false;
+ * }
+ * if ($retries > $maxRetries) {
+ * return false;
+ * }
+ * if ($error instanceof ServiceUnavailableException) {
+ * return true;
+ * }
+ * if ($error instanceof ServerException && $error->getCode() == 503) {
+ * return true;
+ * }
+ * if ($response instanceof ResponseInterface && $response->getStatusCode() == 503) {
+ * return true;
+ * }
+ * return false;
+ * },
+ * [RetryMiddleware::class, 'exponentialDelay']
+ * )
+ * ]
+ * ];
+ * $config->setClientOptions($clientOptions);
+ * ```
* @package Commercetools\Core\Client
*/
class ClientFactory
diff --git a/src/Core/Client/HttpMethod.php b/src/Core/Client/HttpMethod.php
index e8733e70c2..d5d0055cbd 100644
--- a/src/Core/Client/HttpMethod.php
+++ b/src/Core/Client/HttpMethod.php
@@ -14,4 +14,5 @@ class HttpMethod
const GET = 'GET';
const POST = 'POST';
const DELETE = 'DELETE';
+ const HEAD = 'HEAD';
}
diff --git a/src/Core/Client/UserAgentProvider.php b/src/Core/Client/UserAgentProvider.php
index 1c8c9a87a6..be82a29198 100644
--- a/src/Core/Client/UserAgentProvider.php
+++ b/src/Core/Client/UserAgentProvider.php
@@ -9,6 +9,8 @@ class UserAgentProvider
{
private $userAgent;
+ const USER_AGENT = 'commercetools-sdk-php-v1/';
+
/**
* UserAgentProvider constructor.
* @param string $userAgent
@@ -16,7 +18,7 @@ class UserAgentProvider
public function __construct($userAgent = null)
{
if (is_null($userAgent)) {
- $userAgent = 'commercetools-php-sdk/' . Client::VERSION;
+ $userAgent = self::USER_AGENT . Client::VERSION;
$userAgent .= ' (' . $this->getAdapterInfo();
if (extension_loaded('curl') && function_exists('curl_version')) {
diff --git a/src/Core/Error/MissingRoleOnChannelError.php b/src/Core/Error/MissingRoleOnChannelError.php
new file mode 100644
index 0000000000..e130e41e35
--- /dev/null
+++ b/src/Core/Error/MissingRoleOnChannelError.php
@@ -0,0 +1,32 @@
+ ChannelReference::class];
+ $definitions['missingRole'] = [static::TYPE => ChannelRole::class];
+
+ return $definitions;
+ }
+}
diff --git a/src/Core/Error/ProjectNotConfiguredForLanguagesError.php b/src/Core/Error/ProjectNotConfiguredForLanguagesError.php
new file mode 100644
index 0000000000..e448fde67a
--- /dev/null
+++ b/src/Core/Error/ProjectNotConfiguredForLanguagesError.php
@@ -0,0 +1,26 @@
+ 'array'];
+
+ return $definitions;
+ }
+}
diff --git a/src/Core/Error/QueryTimedOutError.php b/src/Core/Error/QueryTimedOutError.php
new file mode 100644
index 0000000000..8228e146b5
--- /dev/null
+++ b/src/Core/Error/QueryTimedOutError.php
@@ -0,0 +1,24 @@
+getClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
@@ -112,7 +113,7 @@ protected function getCollectionObjects(\RegexIterator $phpFiles)
$collectionObjects = [];
foreach ($phpFiles as $phpFile) {
$class = $this->getClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
@@ -132,7 +133,7 @@ protected function getRequestObjects(\RegexIterator $phpFiles)
$requestObjects = [];
foreach ($phpFiles as $phpFile) {
$class = $this->getClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
@@ -152,7 +153,7 @@ protected function getRequestDomainObjects(\RegexIterator $phpFiles)
$requestObjects = [];
foreach ($phpFiles as $phpFile) {
$class = $this->getClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
@@ -164,10 +165,10 @@ protected function getRequestDomainObjects(\RegexIterator $phpFiles)
) {
$namespaceParts = explode("\\", $class->getNamespaceName());
$domain = $namespaceParts[count($namespaceParts) - 1];
- if (strpos($class, 'ProductProjection') > 0) {
+ if ($class != null && strpos($class, 'ProductProjection') > 0) {
$domain = 'ProductProjections';
}
- if (strpos($class, 'ProductsSuggest') > 0) {
+ if ($class != null && strpos($class, 'ProductsSuggest') > 0) {
$domain = 'ProductProjections';
}
$requestObjects[$domain][] = $class->getName();
@@ -183,7 +184,7 @@ protected function getUpdateObjects(\RegexIterator $phpFiles)
$actions = [];
foreach ($phpFiles as $phpFile) {
$class = $this->getClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
@@ -607,8 +608,9 @@ function ($link) {
break;
case 'createFromCart':
$uses[] = 'use ' . Cart::class . ';';
+ $uses[] = 'use ' . CartReference::class . ';';
$methodParams[] = [self::PARAM_TYPE => 'Cart', self::PARAM_NAME => '$cart'];
- $factoryCall = 'ofCartIdAndVersion($cart->getId(), $cart->getVersion());';
+ $factoryCall = 'ofCartAndVersion(CartReference::ofId($cart->getId()), $cart->getVersion());';
break;
case 'emailToken':
$methodName = 'createEmailVerificationToken';
@@ -622,6 +624,7 @@ function ($link) {
$factoryCall = 'ofToken($tokenValue);';
break;
case 'login':
+ $uses[] = 'use ' . CartReference::class . ';';
$methodParams[] = [self::PARAM_DOC_TYPE => 'string', self::PARAM_NAME => '$email'];
$methodParams[] = [self::PARAM_DOC_TYPE => 'string', self::PARAM_NAME => '$password'];
$methodParams[] = [
@@ -630,15 +633,15 @@ function ($link) {
self::PARAM_DEFAULT => 'false'
];
$methodParams[] = [
- self::PARAM_DOC_TYPE => 'string',
- self::PARAM_NAME => '$anonymousCartId',
+ self::PARAM_DOC_TYPE => 'CartReference|string',
+ self::PARAM_NAME => '$anonymousCart',
self::PARAM_DEFAULT => 'null'
];
$factoryCall = 'ofEmailPasswordAndUpdateProductData(
$email,
$password,
$updateProductData,
- $anonymousCartId
+ $anonymousCart
);';
break;
case 'passwordChange':
@@ -826,6 +829,12 @@ function ($link) {
$methodParams[] = [self::PARAM_DOC_TYPE => 'string', self::PARAM_NAME => '$' . $param];
$factoryCall = 'of' . ucfirst($param) . '($' . $param . ');';
break;
+ case preg_match('/^by([a-zA-Z]+)Head$/', $methodName, $matches) === 1:
+ $param = lcfirst($matches[1]);
+ $methodName = 'getBy' . ucfirst($param) . 'Head';
+ $methodParams[] = [self::PARAM_DOC_TYPE => 'string', self::PARAM_NAME => '$' . $param];
+ $factoryCall = 'of' . ucfirst($param) . '($' . $param . ');';
+ break;
default:
$factoryCall = 'of();';
}
diff --git a/src/Core/Model/Cart/Cart.php b/src/Core/Model/Cart/Cart.php
index 8349af12b7..ccb9d2f20d 100644
--- a/src/Core/Model/Cart/Cart.php
+++ b/src/Core/Model/Cart/Cart.php
@@ -89,6 +89,8 @@
* @method Cart setCreatedBy(CreatedBy $createdBy = null)
* @method LastModifiedBy getLastModifiedBy()
* @method Cart setLastModifiedBy(LastModifiedBy $lastModifiedBy = null)
+ * @method string getKey()
+ * @method Cart setKey(string $key = null)
* @method CartReference getReference()
*/
class Cart extends Resource
@@ -113,6 +115,7 @@ public function fieldDefinitions()
{
return [
'id' => [static::TYPE => 'string'],
+ 'key' => [static::TYPE => 'string'],
'version' => [static::TYPE => 'int'],
'createdAt' => [
static::TYPE => DateTime::class,
diff --git a/src/Core/Model/Cart/CartDraft.php b/src/Core/Model/Cart/CartDraft.php
index 18f5903585..7fc05be5a1 100644
--- a/src/Core/Model/Cart/CartDraft.php
+++ b/src/Core/Model/Cart/CartDraft.php
@@ -64,6 +64,10 @@
* @method CartDraft setItemShippingAddresses(AddressCollection $itemShippingAddresses = null)
* @method StoreReference getStore()
* @method CartDraft setStore(StoreReference $store = null)
+ * @method array getDiscountCodes()
+ * @method CartDraft setDiscountCodes(array $discountCodes = null)
+ * @method string getKey()
+ * @method CartDraft setKey(string $key = null)
*/
class CartDraft extends JsonObject
{
@@ -73,6 +77,7 @@ public function fieldDefinitions()
{
return [
'currency' => [static::TYPE => 'string'],
+ 'key' => [static::TYPE => 'string'],
'customerId' => [static::TYPE => 'string'],
'customerEmail' => [static::TYPE => 'string'],
'country' => [static::TYPE => 'string'],
@@ -95,6 +100,7 @@ public function fieldDefinitions()
'shippingRateInput' => [static::TYPE => ShippingRateInputDraft::class],
'itemShippingAddresses' => [static::TYPE => AddressCollection::class],
'store' => [static::TYPE => StoreReference::class],
+ 'discountCodes' => [static::TYPE => 'array'],
];
}
diff --git a/src/Core/Model/Cart/LineItem.php b/src/Core/Model/Cart/LineItem.php
index 42acbd3413..1057073946 100644
--- a/src/Core/Model/Cart/LineItem.php
+++ b/src/Core/Model/Cart/LineItem.php
@@ -16,6 +16,7 @@
use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\Common\TaxedItemPrice;
use Commercetools\Core\Model\ProductType\ProductTypeReference;
+use DateTime;
/**
* @package Commercetools\Core\Model\Cart
@@ -57,6 +58,12 @@
* @method LineItem setLineItemMode(string $lineItemMode = null)
* @method ItemShippingDetails getShippingDetails()
* @method LineItem setShippingDetails(ItemShippingDetails $shippingDetails = null)
+ * @method DateTime getAddedAt()
+ * @method LineItem setAddedAt(DateTime $addedAt = null)
+ * @method DateTime getLastModifiedAt()
+ * @method LineItem setLastModifiedAt(DateTime $lastModifiedAt = null)
+ * @method string getProductKey()
+ * @method LineItem setProductKey(string $productKey = null)
*/
class LineItem extends JsonObject
{
@@ -72,12 +79,14 @@ public function fieldDefinitions()
return [
'id' => [static::TYPE => 'string'],
'productId' => [static::TYPE => 'string'],
+ 'productKey' => [static::TYPE => 'string'],
'name' => [static::TYPE => LocalizedString::class],
'productSlug' => [static::TYPE => LocalizedString::class],
'variant' => [static::TYPE => ProductVariant::class],
'price' => [static::TYPE => Price::class],
'taxedPrice' => [static::TYPE => TaxedItemPrice::class],
'quantity' => [static::TYPE => 'int'],
+ 'addedAt' => [static::TYPE => DateTime::class],
'state' => [static::TYPE => ItemStateCollection::class],
'taxRate' => [static::TYPE => TaxRate::class],
'supplyChannel' => [static::TYPE => ChannelReference::class],
@@ -91,6 +100,7 @@ public function fieldDefinitions()
'lineItemMode' => [static::TYPE => 'string'],
'productType' => [static::TYPE => ProductTypeReference::class],
'shippingDetails' => [static::TYPE => ItemShippingDetails::class],
+ 'lastModifiedAt' => [static::TYPE => DateTime::class],
];
}
diff --git a/src/Core/Model/Cart/LineItemDraft.php b/src/Core/Model/Cart/LineItemDraft.php
index a4280d2b69..65cc56032b 100644
--- a/src/Core/Model/Cart/LineItemDraft.php
+++ b/src/Core/Model/Cart/LineItemDraft.php
@@ -8,15 +8,10 @@
use Commercetools\Core\Model\Channel\ChannelReference;
use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\JsonObject;
-use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Money;
-use Commercetools\Core\Model\Common\Price;
-use Commercetools\Core\Model\Order\ItemState;
-use Commercetools\Core\Model\Order\ItemStateCollection;
-use Commercetools\Core\Model\Product\ProductVariant;
-use Commercetools\Core\Model\TaxCategory\TaxRate;
use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
+use DateTime;
/**
* @package Commercetools\Core\Model\Cart
@@ -43,6 +38,8 @@
* @method LineItemDraft setSku(string $sku = null)
* @method ItemShippingDetailsDraft getShippingDetails()
* @method LineItemDraft setShippingDetails(ItemShippingDetailsDraft $shippingDetails = null)
+ * @method DateTime getAddedAt()
+ * @method LineItemDraft setAddedAt(DateTime $addedAt = null)
*/
class LineItemDraft extends JsonObject
{
@@ -60,6 +57,7 @@ public function fieldDefinitions()
'custom' => [static::TYPE => CustomFieldObject::class],
'sku' => [static::TYPE => 'string'],
'shippingDetails' => [static::TYPE => ItemShippingDetailsDraft::class],
+ 'addedAt' => [static::TYPE => DateTime::class],
];
}
diff --git a/src/Core/Model/Cart/MyLineItemDraft.php b/src/Core/Model/Cart/MyLineItemDraft.php
index 84b5b1cd35..137e4fa035 100644
--- a/src/Core/Model/Cart/MyLineItemDraft.php
+++ b/src/Core/Model/Cart/MyLineItemDraft.php
@@ -8,15 +8,8 @@
use Commercetools\Core\Model\Channel\ChannelReference;
use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\JsonObject;
-use Commercetools\Core\Model\Common\LocalizedString;
-use Commercetools\Core\Model\Common\Money;
-use Commercetools\Core\Model\Common\Price;
-use Commercetools\Core\Model\Order\ItemState;
-use Commercetools\Core\Model\Order\ItemStateCollection;
-use Commercetools\Core\Model\Product\ProductVariant;
-use Commercetools\Core\Model\TaxCategory\TaxRate;
use Commercetools\Core\Model\CustomField\CustomFieldObject;
-use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
+use DateTime;
/**
* @package Commercetools\Core\Model\Cart
@@ -37,6 +30,8 @@
* @method MyLineItemDraft setShippingDetails(ItemShippingDetailsDraft $shippingDetails = null)
* @method string getSku()
* @method MyLineItemDraft setSku(string $sku = null)
+ * @method DateTime getAddedAt()
+ * @method MyLineItemDraft setAddedAt(DateTime $addedAt = null)
*/
class MyLineItemDraft extends JsonObject
{
@@ -51,6 +46,7 @@ public function fieldDefinitions()
'custom' => [static::TYPE => CustomFieldObject::class],
'shippingDetails' => [static::TYPE => ItemShippingDetailsDraft::class],
'sku' => [static::TYPE => 'string'],
+ 'addedAt' => [static::TYPE => DateTime::class],
];
}
diff --git a/src/Core/Model/Common/AbstractJsonDeserializeObject.php b/src/Core/Model/Common/AbstractJsonDeserializeObject.php
index 813b0bc4a1..eb8f26cb25 100644
--- a/src/Core/Model/Common/AbstractJsonDeserializeObject.php
+++ b/src/Core/Model/Common/AbstractJsonDeserializeObject.php
@@ -173,6 +173,7 @@ protected function getRaw($field, $default = null)
return isset($this->rawData[$field])? $this->rawData[$field]: $default;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.4.0)
* Specify data which should be serialized to JSON
diff --git a/src/Core/Model/Common/Collection.php b/src/Core/Model/Common/Collection.php
index 8dbd75cab3..fcadd11d2c 100644
--- a/src/Core/Model/Common/Collection.php
+++ b/src/Core/Model/Common/Collection.php
@@ -225,6 +225,7 @@ public function setAt($offset, $object)
return $this;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.1.0)
* Count elements of an object
@@ -244,6 +245,7 @@ public function count()
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Return the current element
@@ -258,6 +260,7 @@ public function current()
return null;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Move forward to next element
@@ -269,6 +272,7 @@ public function next()
$this->pos++;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Return the key of the current element
@@ -283,6 +287,7 @@ public function key()
return null;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Checks if current position is valid
@@ -298,6 +303,7 @@ public function valid()
return false;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Rewind the Iterator to the first element
@@ -309,6 +315,7 @@ public function rewind()
$this->pos = 0;
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Whether a offset exists
@@ -326,6 +333,7 @@ public function offsetExists($offset)
return isset($this->rawData[$offset]) || isset($this->typeData[$offset]);
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Offset to retrieve
@@ -340,6 +348,7 @@ public function offsetGet($offset)
return $this->getAt($offset);
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Offset to set
@@ -357,6 +366,7 @@ public function offsetSet($offset, $value)
$this->setAt($offset, $value);
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Offset to unset
diff --git a/src/Core/Model/Common/ContainerAndKey.php b/src/Core/Model/Common/ContainerAndKey.php
new file mode 100644
index 0000000000..c33f4a21de
--- /dev/null
+++ b/src/Core/Model/Common/ContainerAndKey.php
@@ -0,0 +1,22 @@
+ [self::TYPE => 'string'],
+ 'key' => [self::TYPE => 'string'],
+ ];
+ }
+}
diff --git a/src/Core/Model/Common/Context.php b/src/Core/Model/Common/Context.php
index 1d3f6ad797..e1d4aac35a 100644
--- a/src/Core/Model/Common/Context.php
+++ b/src/Core/Model/Common/Context.php
@@ -198,6 +198,7 @@ public static function of()
return new static();
}
+ #[\ReturnTypeWillChange]
/**
* @inheritDoc
*/
@@ -206,6 +207,7 @@ public function offsetExists($offset)
return isset($this->$offset);
}
+ #[\ReturnTypeWillChange]
/**
* @inheritDoc
*/
@@ -219,6 +221,7 @@ public function offsetGet($offset)
return null;
}
+ #[\ReturnTypeWillChange]
/**
* @inheritDoc
*/
@@ -231,6 +234,7 @@ public function offsetSet($offset, $value)
}
}
+ #[\ReturnTypeWillChange]
/**
* @inheritDoc
*/
diff --git a/src/Core/Model/Common/DateTimeDecorator.php b/src/Core/Model/Common/DateTimeDecorator.php
index 8973f24877..6d35d171e1 100644
--- a/src/Core/Model/Common/DateTimeDecorator.php
+++ b/src/Core/Model/Common/DateTimeDecorator.php
@@ -56,6 +56,7 @@ public function getUtcDateTime()
return $dateTime;
}
+ #[\ReturnTypeWillChange]
/**
* @return string
*/
diff --git a/src/Core/Model/Common/LocalizedString.php b/src/Core/Model/Common/LocalizedString.php
index 36d87c2451..46fb60b6d6 100644
--- a/src/Core/Model/Common/LocalizedString.php
+++ b/src/Core/Model/Common/LocalizedString.php
@@ -136,6 +136,7 @@ public function toArray()
return $data;
}
+ #[\ReturnTypeWillChange]
/**
* @return array
*/
diff --git a/src/Core/Model/Customer/CustomerDraft.php b/src/Core/Model/Customer/CustomerDraft.php
index 31fa40f420..ae7f92b17d 100644
--- a/src/Core/Model/Customer/CustomerDraft.php
+++ b/src/Core/Model/Customer/CustomerDraft.php
@@ -6,10 +6,12 @@
namespace Commercetools\Core\Model\Customer;
+use Commercetools\Core\Model\Cart\CartReference;
use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use Commercetools\Core\Model\Common\LocaleTrait;
+use Commercetools\Core\Model\Common\ResourceIdentifier;
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
use Commercetools\Core\Model\Common\AddressCollection;
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
@@ -69,6 +71,8 @@
* @method CustomerDraft setAnonymousId(string $anonymousId = null)
* @method StoreReferenceCollection getStores()
* @method CustomerDraft setStores(StoreReferenceCollection $stores = null)
+ * @method CartReference getAnonymousCart()
+ * @method CustomerDraft setAnonymousCart(CartReference $anonymousCart = null)
*/
class CustomerDraft extends JsonObject
{
@@ -105,6 +109,7 @@ public function fieldDefinitions()
'key' => [static::TYPE => 'string'],
'anonymousId' => [static::TYPE => 'string'],
'stores' => [static::TYPE => StoreReferenceCollection::class],
+ 'anonymousCart' => [static::TYPE => CartReference::class],
];
}
diff --git a/src/Core/Model/Message/CategorySlugChangedMessage.php b/src/Core/Model/Message/CategorySlugChangedMessage.php
index 0c537de612..5545177261 100644
--- a/src/Core/Model/Message/CategorySlugChangedMessage.php
+++ b/src/Core/Model/Message/CategorySlugChangedMessage.php
@@ -36,6 +36,8 @@
* phpcs:disable
* @method CategorySlugChangedMessage setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
* phpcs:enable
+ * @method LocalizedString getOldSlug()
+ * @method CategorySlugChangedMessage setOldSlug(LocalizedString $oldSlug = null)
*/
class CategorySlugChangedMessage extends Message
{
@@ -45,6 +47,7 @@ public function fieldDefinitions()
{
$definitions = parent::fieldDefinitions();
$definitions['slug'] = [static::TYPE => LocalizedString::class];
+ $definitions['oldSlug'] = [static::TYPE => LocalizedString::class];
return $definitions;
}
diff --git a/src/Core/Model/Message/CustomerDeletedMessage.php b/src/Core/Model/Message/CustomerDeletedMessage.php
new file mode 100644
index 0000000000..5542f5e1ad
--- /dev/null
+++ b/src/Core/Model/Message/CustomerDeletedMessage.php
@@ -0,0 +1,46 @@
+
+ */
+
+namespace Commercetools\Core\Model\Message;
+
+use Commercetools\Core\Model\Common\Address;
+use Commercetools\Core\Model\Common\DateTimeDecorator;
+use DateTime;
+use Commercetools\Core\Model\Common\Reference;
+use phpDocumentor\Reflection\Types\Boolean;
+
+/**
+ * @package Commercetools\Core\Model\Message
+ * @link https://docs.commercetools.com/api/message-types#customerpasswordupdatedmessage
+ * @method string getId()
+ * @method CustomerPasswordUpdatedMessage setId(string $id = null)
+ * @method int getVersion()
+ * @method CustomerPasswordUpdatedMessage setVersion(int $version = null)
+ * @method DateTimeDecorator getCreatedAt()
+ * @method CustomerPasswordUpdatedMessage setCreatedAt(DateTime $createdAt = null)
+ * @method DateTimeDecorator getLastModifiedAt()
+ * @method CustomerPasswordUpdatedMessage setLastModifiedAt(DateTime $lastModifiedAt = null)
+ * @method int getSequenceNumber()
+ * @method CustomerPasswordUpdatedMessage setSequenceNumber(int $sequenceNumber = null)
+ * @method Reference getResource()
+ * @method CustomerPasswordUpdatedMessage setResource(Reference $resource = null)
+ * @method int getResourceVersion()
+ * @method CustomerPasswordUpdatedMessage setResourceVersion(int $resourceVersion = null)
+ * @method string getType()
+ * @method CustomerPasswordUpdatedMessage setType(string $type = null)
+ * @method UserProvidedIdentifiers getResourceUserProvidedIdentifiers()
+ * phpcs:disable
+ * @method CustomerPasswordUpdatedMessage setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
+ * phpcs:enable
+ * @method bool getReset()
+ * @method CustomerPasswordUpdatedMessage setReset(bool $reset = null)
+ */
+class CustomerPasswordUpdatedMessage extends Message
+{
+ const MESSAGE_TYPE = 'CustomerPasswordUpdated';
+
+ public function fieldDefinitions()
+ {
+ $definitions = parent::fieldDefinitions();
+ $definitions['reset'] = [static::TYPE => 'bool'];
+
+ return $definitions;
+ }
+}
diff --git a/src/Core/Model/Message/InventoryEntryQuantitySetMessage.php b/src/Core/Model/Message/InventoryEntryQuantitySetMessage.php
index 8f5c360045..6bbff638e5 100644
--- a/src/Core/Model/Message/InventoryEntryQuantitySetMessage.php
+++ b/src/Core/Model/Message/InventoryEntryQuantitySetMessage.php
@@ -3,6 +3,7 @@
namespace Commercetools\Core\Model\Message;
+use Commercetools\Core\Model\Channel\ChannelReference;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use DateTime;
use Commercetools\Core\Model\Common\Reference;
@@ -38,6 +39,8 @@
* @method InventoryEntryQuantitySetMessage setOldAvailableQuantity(int $oldAvailableQuantity = null)
* @method int getNewAvailableQuantity()
* @method InventoryEntryQuantitySetMessage setNewAvailableQuantity(int $newAvailableQuantity = null)
+ * @method ChannelReference getSupplyChannel()
+ * @method InventoryEntryQuantitySetMessage setSupplyChannel(ChannelReference $supplyChannel = null)
*/
class InventoryEntryQuantitySetMessage extends Message
{
@@ -50,6 +53,7 @@ public function fieldDefinitions()
$definitions['newQuantityOnStock'] = [static::TYPE => 'int'];
$definitions['oldAvailableQuantity'] = [static::TYPE => 'int'];
$definitions['newAvailableQuantity'] = [static::TYPE => 'int'];
+ $definitions['supplyChannel'] = [static::TYPE => ChannelReference::class];
return $definitions;
}
diff --git a/src/Core/Model/Message/OrderLineItemDistributionChannelSetMessage.php b/src/Core/Model/Message/OrderLineItemDistributionChannelSetMessage.php
new file mode 100644
index 0000000000..35ff264968
--- /dev/null
+++ b/src/Core/Model/Message/OrderLineItemDistributionChannelSetMessage.php
@@ -0,0 +1,52 @@
+ 'string'];
+ $definitions['distributionChannel'] = [static::TYPE => ChannelReference::class];
+
+ return $definitions;
+ }
+}
diff --git a/src/Core/Model/Message/OrderReturnInfoSetMessage.php b/src/Core/Model/Message/OrderReturnInfoSetMessage.php
new file mode 100644
index 0000000000..7083380022
--- /dev/null
+++ b/src/Core/Model/Message/OrderReturnInfoSetMessage.php
@@ -0,0 +1,49 @@
+ ReturnInfoCollection::class];
+
+ return $definitions;
+ }
+}
diff --git a/src/Core/Model/Message/OrderStateTransitionMessage.php b/src/Core/Model/Message/OrderStateTransitionMessage.php
index ef2ac0288c..6edd9dc812 100644
--- a/src/Core/Model/Message/OrderStateTransitionMessage.php
+++ b/src/Core/Model/Message/OrderStateTransitionMessage.php
@@ -27,6 +27,8 @@
* @method OrderStateTransitionMessage setType(string $type = null)
* @method StateReference getState()
* @method OrderStateTransitionMessage setState(StateReference $state = null)
+ * @method StateReference getOldState()
+ * @method OrderStateTransitionMessage setOldState(StateReference $state = null)
* @method int getVersion()
* @method OrderStateTransitionMessage setVersion(int $version = null)
* @method DateTimeDecorator getLastModifiedAt()
diff --git a/src/Core/Model/Message/ProductSlugChangedMessage.php b/src/Core/Model/Message/ProductSlugChangedMessage.php
index 73a27f370e..6b5a8dc219 100644
--- a/src/Core/Model/Message/ProductSlugChangedMessage.php
+++ b/src/Core/Model/Message/ProductSlugChangedMessage.php
@@ -36,6 +36,8 @@
* phpcs:disable
* @method ProductSlugChangedMessage setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
* phpcs:enable
+ * @method LocalizedString getOldSlug()
+ * @method ProductSlugChangedMessage setOldSlug(LocalizedString $oldSlug = null)
*/
class ProductSlugChangedMessage extends Message
{
@@ -45,6 +47,7 @@ public function fieldDefinitions()
{
$definitions = parent::fieldDefinitions();
$definitions['slug'] = [static::TYPE => LocalizedString::class];
+ $definitions['oldSlug'] = [static::TYPE => LocalizedString::class];
return $definitions;
}
diff --git a/src/Core/Model/Message/ProductVariantAddedMessage.php b/src/Core/Model/Message/ProductVariantAddedMessage.php
new file mode 100644
index 0000000000..2e5f8a29f6
--- /dev/null
+++ b/src/Core/Model/Message/ProductVariantAddedMessage.php
@@ -0,0 +1,55 @@
+
+ */
+
+namespace Commercetools\Core\Model\Message;
+
+use Commercetools\Core\Model\Product\ProductVariant;
+use Commercetools\Core\Model\Common\DateTimeDecorator;
+use DateTime;
+use Commercetools\Core\Model\Common\Reference;
+
+/**
+ * @package Commercetools\Core\Model\Message
+ * @link https://docs.commercetools.com/http-api-projects-messages.html#productvariantadded-message
+ * @method string getId()
+ * @method ProductVariantAddedMessage setId(string $id = null)
+ * @method int getVersion()
+ * @method ProductVariantAddedMessage setVersion(int $version = null)
+ * @method DateTimeDecorator getCreatedAt()
+ * @method ProductVariantAddedMessage setCreatedAt(DateTime $createdAt = null)
+ * @method DateTimeDecorator getLastModifiedAt()
+ * @method ProductVariantAddedMessage setLastModifiedAt(DateTime $lastModifiedAt = null)
+ * @method int getSequenceNumber()
+ * @method ProductVariantAddedMessage setSequenceNumber(int $sequenceNumber = null)
+ * @method Reference getResource()
+ * @method ProductVariantAddedMessage setResource(Reference $resource = null)
+ * @method int getResourceVersion()
+ * @method ProductVariantAddedMessage setResourceVersion(int $resourceVersion = null)
+ * @method string getType()
+ * @method ProductVariantAddedMessage setType(string $type = null)
+ * @method array getRemovedImageUrls()
+ * @method ProductVariantAddedMessage setRemovedImageUrls(array $removedImageUrls = null)
+ * @method ProductVariant getVariant()
+ * @method ProductVariantAddedMessage setVariant(ProductVariant $variant = null)
+ * @method UserProvidedIdentifiers getResourceUserProvidedIdentifiers()
+ * phpcs:disable
+ * @method ProductVariantAddedMessage setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
+ * phpcs:enable
+ * @method bool getStaged()
+ * @method ProductVariantAddedMessage setStaged(bool $staged = null)
+ */
+class ProductVariantAddedMessage extends Message
+{
+ const MESSAGE_TYPE = 'ProductVariantAdded';
+
+ public function fieldDefinitions()
+ {
+ $definitions = parent::fieldDefinitions();
+ $definitions['variant'] = [static::TYPE => ProductVariant::class];
+ $definitions['staged'] = [static::TYPE => 'bool'];
+
+ return $definitions;
+ }
+}
diff --git a/src/Core/Model/Message/StoreCreatedMessage.php b/src/Core/Model/Message/StoreCreatedMessage.php
new file mode 100644
index 0000000000..c9ee62d601
--- /dev/null
+++ b/src/Core/Model/Message/StoreCreatedMessage.php
@@ -0,0 +1,61 @@
+ [static::TYPE => 'string'],
+ 'languages' => [static::TYPE => 'array'],
+ 'distributionChannels' => [static::TYPE => 'array'],
+ 'supplyChannels' => [static::TYPE => 'array'],
+ 'custom' => [static::TYPE => CustomFieldObject::class],
+ ]
+ );
+ }
+}
diff --git a/src/Core/Model/Message/StoreDeletedMessage.php b/src/Core/Model/Message/StoreDeletedMessage.php
new file mode 100644
index 0000000000..cf9b022c27
--- /dev/null
+++ b/src/Core/Model/Message/StoreDeletedMessage.php
@@ -0,0 +1,46 @@
+ [self::TYPE => 'string'],
'sku' => [self::TYPE => 'string'],
'slug' => [self::TYPE => LocalizedString::class],
+ 'containerAndKey' => [self::TYPE => ContainerAndKey::class]
];
}
}
diff --git a/src/Core/Model/Order/Parcel.php b/src/Core/Model/Order/Parcel.php
index 2cdd568881..da5db31712 100644
--- a/src/Core/Model/Order/Parcel.php
+++ b/src/Core/Model/Order/Parcel.php
@@ -7,6 +7,7 @@
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
+use Commercetools\Core\Model\CustomField\CustomFieldObject;
use DateTime;
/**
@@ -22,6 +23,8 @@
* @method Parcel setTrackingData(TrackingData $trackingData = null)
* @method DeliveryItemCollection getItems()
* @method Parcel setItems(DeliveryItemCollection $items = null)
+ * @method CustomFieldObject getCustom()
+ * @method Parcel setCustom(CustomFieldObject $custom = null)
*/
class Parcel extends JsonObject
{
@@ -36,6 +39,7 @@ public function fieldDefinitions()
'measurements' => [static::TYPE => ParcelMeasurements::class],
'trackingData' => [static::TYPE => TrackingData::class],
'items' => [static::TYPE => DeliveryItemCollection::class],
+ 'custom' => [static::TYPE => CustomFieldObject::class],
];
}
}
diff --git a/src/Core/Model/Order/ReturnItem.php b/src/Core/Model/Order/ReturnItem.php
index bf9e8ec549..0869aee4b9 100644
--- a/src/Core/Model/Order/ReturnItem.php
+++ b/src/Core/Model/Order/ReturnItem.php
@@ -7,6 +7,7 @@
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
+use Commercetools\Core\Model\CustomField\CustomFieldObject;
use DateTime;
/**
@@ -33,6 +34,8 @@
* @method ReturnItem setType(string $type = null)
* @method string getCustomLineItemId()
* @method ReturnItem setCustomLineItemId(string $customLineItemId = null)
+ * @method CustomFieldObject getCustom()
+ * @method ReturnItem setCustom(CustomFieldObject $custom = null)
*/
class ReturnItem extends JsonObject
{
@@ -50,6 +53,7 @@ public function fieldDefinitions()
'comment' => [static::TYPE => 'string'],
'shipmentState' => [static::TYPE => 'string'],
'paymentState' => [static::TYPE => 'string'],
+ 'custom' => [static::TYPE => CustomFieldObject::class],
'lastModifiedAt' => [
static::TYPE => DateTime::class,
static::DECORATOR => DateTimeDecorator::class
diff --git a/src/Core/Model/Payment/Transaction.php b/src/Core/Model/Payment/Transaction.php
index 18ac3b7826..95b617ca40 100644
--- a/src/Core/Model/Payment/Transaction.php
+++ b/src/Core/Model/Payment/Transaction.php
@@ -8,6 +8,7 @@
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use Commercetools\Core\Model\Common\Money;
+use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\State\StateReference;
use DateTime;
@@ -26,6 +27,8 @@
* @method Transaction setId(string $id = null)
* @method string getState()
* @method Transaction setState(string $state = null)
+ * @method CustomFieldObject getCustom()
+ * @method Transaction setCustom(CustomFieldObject $custom = null)
*/
class Transaction extends JsonObject
{
@@ -47,6 +50,7 @@ public function fieldDefinitions()
'type' => [static::TYPE => 'string'],
'amount' => [static::TYPE => Money::class],
'interactionId' => [static::TYPE => 'string'],
+ 'custom' => [static::TYPE => CustomFieldObject::class],
];
}
}
diff --git a/src/Core/Model/Project/Project.php b/src/Core/Model/Project/Project.php
index 756495bb0f..e7c16ef4cf 100644
--- a/src/Core/Model/Project/Project.php
+++ b/src/Core/Model/Project/Project.php
@@ -14,6 +14,7 @@
/**
* @package Commercetools\Core\Model\Project
* @link https://docs.commercetools.com/http-api-projects-project.html#project
+ *
* @method string getKey()
* @method Project setKey(string $key = null)
* @method string getName()
@@ -38,6 +39,10 @@
* @method Project setExternalOAuth(ExternalOAuth $externalOAuth = null)
* @method CartsConfiguration getCarts()
* @method Project setCarts(CartsConfiguration $carts = null)
+ * @method ShoppingListsConfiguration getShoppingLists()
+ * @method Project setShoppingLists(ShoppingListsConfiguration $shoppingLists = null)
+ * @method SearchIndexingConfiguration getSearchIndexing()
+ * @method Project setSearchIndexing(SearchIndexingConfiguration $searchIndexing = null)
*/
class Project extends JsonObject
{
@@ -61,7 +66,9 @@ public function fieldDefinitions()
'messages' => [static::TYPE => MessagesConfiguration::class],
'shippingRateInputType' => [static::TYPE => ShippingRateInputType::class],
'externalOAuth' => [static::TYPE => ExternalOAuth::class],
- 'carts' => [static::TYPE => CartsConfiguration::class]
+ 'carts' => [static::TYPE => CartsConfiguration::class],
+ 'shoppingLists' => [static::TYPE => ShoppingListsConfiguration::class],
+ 'searchIndexing' => [static::TYPE => SearchIndexingConfiguration::class]
];
}
}
diff --git a/src/Core/Model/Project/SearchIndexingConfiguration.php b/src/Core/Model/Project/SearchIndexingConfiguration.php
new file mode 100644
index 0000000000..274014d6b1
--- /dev/null
+++ b/src/Core/Model/Project/SearchIndexingConfiguration.php
@@ -0,0 +1,22 @@
+ [static::TYPE => SearchIndexingConfigurationValues::class]
+ ];
+ }
+}
diff --git a/src/Core/Model/Project/SearchIndexingConfigurationValues.php b/src/Core/Model/Project/SearchIndexingConfigurationValues.php
new file mode 100644
index 0000000000..2e416a1f8e
--- /dev/null
+++ b/src/Core/Model/Project/SearchIndexingConfigurationValues.php
@@ -0,0 +1,33 @@
+ [static::TYPE => 'string'],
+ 'lastModifiedAt' => [
+ static::TYPE => DateTime::class,
+ static::DECORATOR => DateTimeDecorator::class
+ ],
+ 'lastModifiedBy' => [static::TYPE => LastModifiedBy::class],
+ ];
+ }
+}
diff --git a/src/Core/Model/Project/ShoppingListsConfiguration.php b/src/Core/Model/Project/ShoppingListsConfiguration.php
new file mode 100644
index 0000000000..59d1d490d1
--- /dev/null
+++ b/src/Core/Model/Project/ShoppingListsConfiguration.php
@@ -0,0 +1,22 @@
+ [static::TYPE => 'int'],
+ ];
+ }
+}
diff --git a/src/Core/Model/ShippingMethod/ShippingMethod.php b/src/Core/Model/ShippingMethod/ShippingMethod.php
index 188b0f9a22..0584df10d3 100644
--- a/src/Core/Model/ShippingMethod/ShippingMethod.php
+++ b/src/Core/Model/ShippingMethod/ShippingMethod.php
@@ -7,6 +7,7 @@
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Resource;
+use Commercetools\Core\Model\CustomField\CustomFieldObject;
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
use Commercetools\Core\Model\Common\DateTimeDecorator;
use DateTime;
@@ -38,6 +39,10 @@
* @method ShippingMethod setPredicate(string $predicate = null)
* @method LocalizedString getLocalizedDescription()
* @method ShippingMethod setLocalizedDescription(LocalizedString $localizedDescription = null)
+ * @method LocalizedString getLocalizedName()
+ * @method ShippingMethod setLocalizedName(LocalizedString $localizedName = null)
+ * @method CustomFieldObject getCustom()
+ * @method ShippingMethod setCustom(CustomFieldObject $custom = null)
* @method ShippingMethodReference getReference()
*/
class ShippingMethod extends Resource
@@ -56,6 +61,7 @@ public function fieldDefinitions()
static::DECORATOR => DateTimeDecorator::class
],
'name' => [static::TYPE => 'string'],
+ 'localizedName' => [static::TYPE => LocalizedString::class],
'localizedDescription' => [static::TYPE => LocalizedString::class],
'description' => [static::TYPE => 'string'],
'taxCategory' => [static::TYPE => TaxCategoryReference::class],
@@ -63,6 +69,7 @@ public function fieldDefinitions()
'isDefault' => [static::TYPE => 'bool'],
'key' => [static::TYPE => 'string'],
'predicate' => [static::TYPE => 'string'],
+ 'custom' => [static::TYPE => CustomFieldObject::class],
];
}
}
diff --git a/src/Core/Model/ShippingMethod/ShippingMethodDraft.php b/src/Core/Model/ShippingMethod/ShippingMethodDraft.php
index 54e35581b8..431be127ee 100644
--- a/src/Core/Model/ShippingMethod/ShippingMethodDraft.php
+++ b/src/Core/Model/ShippingMethod/ShippingMethodDraft.php
@@ -8,6 +8,7 @@
use Commercetools\Core\Model\Common\Context;
use Commercetools\Core\Model\Common\JsonObject;
use Commercetools\Core\Model\Common\LocalizedString;
+use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
/**
@@ -29,6 +30,10 @@
* @method ShippingMethodDraft setPredicate(string $predicate = null)
* @method LocalizedString getLocalizedDescription()
* @method ShippingMethodDraft setLocalizedDescription(LocalizedString $localizedDescription = null)
+ * @method LocalizedString getLocalizedName()
+ * @method ShippingMethodDraft setLocalizedName(LocalizedString $localizedName = null)
+ * @method CustomFieldObjectDraft getCustom()
+ * @method ShippingMethodDraft setCustom(CustomFieldObjectDraft $custom = null)
*/
class ShippingMethodDraft extends JsonObject
{
@@ -36,6 +41,7 @@ public function fieldDefinitions()
{
return [
'name' => [static::TYPE => 'string'],
+ 'localizedName' => [static::TYPE => LocalizedString::class],
'localizedDescription' => [static::TYPE => LocalizedString::class],
'description' => [static::TYPE => 'string'],
'taxCategory' => [static::TYPE => TaxCategoryReference::class],
@@ -43,6 +49,7 @@ public function fieldDefinitions()
'isDefault' => [static::TYPE => 'bool'],
'key' => [static::TYPE => 'string'],
'predicate' => [static::TYPE => 'string'],
+ 'custom' => [static::TYPE => CustomFieldObjectDraft::class],
];
}
diff --git a/src/Core/Model/Subscription/ResourceDeletedDelivery.php b/src/Core/Model/Subscription/ResourceDeletedDelivery.php
index c87b7b5ebf..c9af3979ee 100644
--- a/src/Core/Model/Subscription/ResourceDeletedDelivery.php
+++ b/src/Core/Model/Subscription/ResourceDeletedDelivery.php
@@ -26,6 +26,8 @@
* phpcs:disable
* @method ResourceDeletedDelivery setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
* phpcs:enable
+ * @method bool getDataErasure()
+ * @method ResourceDeletedDelivery setDataErasure(bool $dataErasure = null)
*/
class ResourceDeletedDelivery extends Delivery
{
@@ -34,6 +36,7 @@ public function fieldDefinitions()
$definition = parent::fieldDefinitions();
$definition['version'] = [static::TYPE => 'int'];
$definition['modifiedAt'] = [static::TYPE => DateTime::class, static::DECORATOR => DateTimeDecorator::class ];
+ $definition['dataErasure'] = [static::TYPE => 'bool'];
return $definition;
}
diff --git a/src/Core/Request/AbstractByIdHeadRequest.php b/src/Core/Request/AbstractByIdHeadRequest.php
new file mode 100644
index 0000000000..02be3ce7aa
--- /dev/null
+++ b/src/Core/Request/AbstractByIdHeadRequest.php
@@ -0,0 +1,83 @@
+setId($id);
+ }
+
+ /**
+ * @return string
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * @param string $id
+ * @return $this
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ * @internal
+ */
+ protected function getPath()
+ {
+ return (string)$this->getEndpoint() . '/' . $this->getId() . $this->getParamString();
+ }
+
+ /**
+ * @return HttpRequest
+ * @internal
+ */
+ public function httpRequest()
+ {
+ return new HttpRequest(HttpMethod::HEAD, $this->getPath());
+ }
+
+ /**
+ * @param ResponseInterface $response
+ * @return ResourceResponse
+ * @internal
+ */
+ public function buildResponse(ResponseInterface $response)
+ {
+ return new ResourceResponse($response, $this, $this->getContext());
+ }
+}
diff --git a/src/Core/Request/AbstractByKeyHeadRequest.php b/src/Core/Request/AbstractByKeyHeadRequest.php
new file mode 100644
index 0000000000..b8121a56f8
--- /dev/null
+++ b/src/Core/Request/AbstractByKeyHeadRequest.php
@@ -0,0 +1,39 @@
+getId();
+ }
+
+ /**
+ * @param string $key
+ * @return $this
+ */
+ public function setKey($key)
+ {
+ return $this->setId($key);
+ }
+
+ /**
+ * @return string
+ * @internal
+ */
+ protected function getPath()
+ {
+ return (string)$this->getEndpoint() . '/key=' . $this->getKey() . $this->getParamString();
+ }
+}
diff --git a/src/Core/Request/AbstractHeadRequest.php b/src/Core/Request/AbstractHeadRequest.php
new file mode 100644
index 0000000000..88c5e9e550
--- /dev/null
+++ b/src/Core/Request/AbstractHeadRequest.php
@@ -0,0 +1,57 @@
+getEndpoint() . $this->getParamString();
+ }
+
+ /**
+ * @return HttpRequest
+ * @internal
+ */
+ public function httpRequest()
+ {
+ return new HttpRequest(HttpMethod::HEAD, $this->getPath());
+ }
+
+ /**
+ * @param ResponseInterface $response
+ * @return ResourceResponse
+ * @internal
+ */
+ public function buildResponse(ResponseInterface $response)
+ {
+ return new ResourceResponse($response, $this, $this->getContext());
+ }
+}
diff --git a/src/Core/Request/Carts/CartByKeyGetRequest.php b/src/Core/Request/Carts/CartByKeyGetRequest.php
new file mode 100644
index 0000000000..e621ea837e
--- /dev/null
+++ b/src/Core/Request/Carts/CartByKeyGetRequest.php
@@ -0,0 +1,44 @@
+ [static::TYPE => 'string'],
+ 'key' => [static::TYPE => 'string'],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setKey');
+ }
+}
diff --git a/src/Core/Request/Carts/Command/CartSetLineItemDistributionChannelAction.php b/src/Core/Request/Carts/Command/CartSetLineItemDistributionChannelAction.php
new file mode 100644
index 0000000000..7694dfc4a3
--- /dev/null
+++ b/src/Core/Request/Carts/Command/CartSetLineItemDistributionChannelAction.php
@@ -0,0 +1,53 @@
+ [static::TYPE => 'string'],
+ 'lineItemId' => [static::TYPE => 'string'],
+ 'distributionChannel' => [static::TYPE => ChannelReference::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setLineItemDistributionChannel');
+ }
+
+ /**
+ * @param String $itemLineId
+ * @param ResourceIdentifier|ChannelReference $distributionChannel
+ * @param Context|callable $context
+ * @return CartSetLineItemDistributionChannelAction
+ */
+ public static function ofItemLineIdAndDistributionChannel($itemLineId, ChannelReference $distributionChannel, $context = null)
+ {
+ return static::of($context)->setLineItemId($itemLineId)->setDistributionChannel($distributionChannel);
+ }
+}
diff --git a/src/Core/Request/Carts/Command/CartSetLineItemSupplyChannelAction.php b/src/Core/Request/Carts/Command/CartSetLineItemSupplyChannelAction.php
new file mode 100644
index 0000000000..697d02637c
--- /dev/null
+++ b/src/Core/Request/Carts/Command/CartSetLineItemSupplyChannelAction.php
@@ -0,0 +1,51 @@
+ [static::TYPE => 'string'],
+ 'lineItemId' => [static::TYPE => 'string'],
+ 'supplyChannel' => [static::TYPE => ChannelReference::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setLineItemSupplyChannel');
+ }
+
+ /**
+ * @param String $itemLineId
+ * @param ResourceIdentifier|ChannelReference $supplyChannel
+ * @param Context|callable $context
+ * @return CartSetLineItemSupplyChannelAction
+ */
+ public static function ofItemLineIdAndSupplyChannel($itemLineId, ChannelReference $supplyChannel, $context = null)
+ {
+ return static::of($context)->setLineItemId($itemLineId)->setSupplyChannel($supplyChannel);
+ }
+}
diff --git a/src/Core/Request/Customers/CustomerLoginRequest.php b/src/Core/Request/Customers/CustomerLoginRequest.php
index 97ef5d22ad..9be39d1f81 100644
--- a/src/Core/Request/Customers/CustomerLoginRequest.php
+++ b/src/Core/Request/Customers/CustomerLoginRequest.php
@@ -6,6 +6,10 @@
namespace Commercetools\Core\Request\Customers;
+use Commercetools\Core\Model\Cart\Cart;
+use Commercetools\Core\Model\Cart\CartReference;
+use Commercetools\Core\Model\Common\ResourceIdentifier;
+use Commercetools\Core\Model\Customer\CustomerDraft;
use Psr\Http\Message\ResponseInterface;
use Commercetools\Core\Client\HttpMethod;
use Commercetools\Core\Client\JsonRequest;
@@ -26,6 +30,7 @@ class CustomerLoginRequest extends AbstractApiRequest
{
const EMAIL = 'email';
const PASSWORD = 'password';
+ const ANONYMOUS_CART = 'anonymousCart';
const ANONYMOUS_CART_ID = 'anonymousCartId';
const ANONYMOUS_CART_SIGN_IN_MODE = 'anonymousCartSignInMode';
const SIGN_IN_MODE_MERGE = 'MergeWithExistingCustomerCart';
@@ -43,6 +48,12 @@ class CustomerLoginRequest extends AbstractApiRequest
protected $password;
/**
+ * @var CartReference
+ */
+ protected $anonymousCart;
+
+ /**
+ * @deprecated use $anonymousCart instead
* @var string
*/
protected $anonymousCartId;
@@ -59,15 +70,19 @@ class CustomerLoginRequest extends AbstractApiRequest
/**
* @param string $email
* @param string $password
- * @param string $anonymousCartId
+ * @param CartReference|string|null $anonymousCart
* @param Context $context
*/
- public function __construct($email, $password, $anonymousCartId = null, Context $context = null)
+ public function __construct($email, $password, $anonymousCart = null, Context $context = null)
{
parent::__construct(LoginEndpoint::endpoint(), $context);
$this->email = $email;
$this->password = $password;
- $this->anonymousCartId = $anonymousCartId;
+ if ($anonymousCart instanceof CartReference) {
+ $this->anonymousCart = $anonymousCart;
+ } elseif ($anonymousCart !== null) {
+ $this->anonymousCart = CartReference::ofId($anonymousCart);
+ }
}
/**
@@ -109,20 +124,25 @@ public function setPassword($password)
}
/**
+ * @deprecated use $getAnonymousCart instead
* @return string
*/
public function getAnonymousCartId()
{
- return $this->anonymousCartId;
+ if ($this->anonymousCart == null) {
+ return null;
+ }
+ return $this->anonymousCart->getId();
}
/**
+ * @deprecated use $setAnonymousCart instead
* @param string $anonymousCartId
* @return $this
*/
public function setAnonymousCartId($anonymousCartId)
{
- $this->anonymousCartId = $anonymousCartId;
+ $this->anonymousCart = CartReference::ofId($anonymousCartId);
return $this;
}
@@ -164,23 +184,42 @@ public function setUpdateProductData($updateProductData)
return $this;
}
+ /**
+ * @return CartReference
+ */
+ public function getAnonymousCart()
+ {
+ return $this->anonymousCart;
+ }
+
+ /**
+ * @param CartReference $anonymousCart
+ * @return $this
+ */
+ public function setAnonymousCart($anonymousCart)
+ {
+ $this->anonymousCart = $anonymousCart;
+
+ return $this;
+ }
+
/**
* @param string $email
* @param string $password
- * @param string $anonymousCartId
+ * @param CartReference|string $anonymousCart
* @param Context $context
* @return static
*/
- public static function ofEmailAndPassword($email, $password, $anonymousCartId = null, Context $context = null)
+ public static function ofEmailAndPassword($email, $password, $anonymousCart = null, Context $context = null)
{
- return new static($email, $password, $anonymousCartId, $context);
+ return new static($email, $password, $anonymousCart, $context);
}
/**
* @param string $email
* @param string $password
* @param bool $updateProductData
- * @param string $anonymousCartId
+ * @param CartReference|string $anonymousCart
* @param Context $context
* @return static
*/
@@ -188,10 +227,10 @@ public static function ofEmailPasswordAndUpdateProductData(
$email,
$password,
$updateProductData,
- $anonymousCartId = null,
+ $anonymousCart = null,
Context $context = null
) {
- $request = new static($email, $password, $anonymousCartId, $context);
+ $request = new static($email, $password, $anonymousCart, $context);
$request->setUpdateProductData($updateProductData);
return $request;
@@ -210,6 +249,9 @@ public function httpRequest()
if (!is_null($this->anonymousCartId)) {
$payload[static::ANONYMOUS_CART_ID] = $this->anonymousCartId;
}
+ if (!is_null($this->anonymousCart)) {
+ $payload[static::ANONYMOUS_CART] = $this->anonymousCart;
+ }
if (!is_null($this->anonymousCartSignInMode)) {
$payload[static::ANONYMOUS_CART_SIGN_IN_MODE] = $this->anonymousCartSignInMode;
}
diff --git a/src/Core/Request/InStores/InStoreRequests.php b/src/Core/Request/InStores/InStoreRequests.php
index 472d0d2d1b..0e813336d0 100644
--- a/src/Core/Request/InStores/InStoreRequests.php
+++ b/src/Core/Request/InStores/InStoreRequests.php
@@ -7,10 +7,13 @@
use Commercetools\Core\Request\Carts\CartByCustomerIdGetRequest;
use Commercetools\Core\Request\Carts\CartByIdGetRequest;
+use Commercetools\Core\Request\Carts\CartByKeyGetRequest;
use Commercetools\Core\Request\Carts\CartCreateRequest;
+use Commercetools\Core\Request\Carts\CartDeleteByKeyRequest;
use Commercetools\Core\Request\Carts\CartDeleteRequest;
use Commercetools\Core\Request\Carts\CartQueryRequest;
use Commercetools\Core\Request\Carts\CartReplicateRequest;
+use Commercetools\Core\Request\Carts\CartUpdateByKeyRequest;
use Commercetools\Core\Request\Carts\CartUpdateRequest;
use Commercetools\Core\Request\Customers\CustomerByEmailTokenGetRequest;
use Commercetools\Core\Request\Customers\CustomerByIdGetRequest;
@@ -21,6 +24,7 @@
use Commercetools\Core\Request\Customers\CustomerEmailConfirmRequest;
use Commercetools\Core\Request\Customers\CustomerEmailTokenRequest;
use Commercetools\Core\Request\Customers\CustomerLoginRequest;
+use Commercetools\Core\Request\Customers\CustomerPasswordChangeRequest;
use Commercetools\Core\Request\Customers\CustomerPasswordResetRequest;
use Commercetools\Core\Request\Customers\CustomerPasswordTokenRequest;
use Commercetools\Core\Request\Customers\CustomerQueryRequest;
@@ -65,11 +69,14 @@ class InStoreRequests
{
private $requests = [
CartByIdGetRequest::class => 1,
+ CartByKeyGetRequest::class => 1,
CartByCustomerIdGetRequest::class => 1,
CartQueryRequest::class => 1,
CartCreateRequest::class => 1,
CartUpdateRequest::class => 1,
+ CartUpdateByKeyRequest::class => 1,
CartDeleteRequest::class => 1,
+ CartDeleteByKeyRequest::class => 1,
CartReplicateRequest::class => 1,
MeCartByIdRequest::class => 1,
MeActiveCartRequest::class => 1,
@@ -102,6 +109,7 @@ class InStoreRequests
CustomerEmailConfirmRequest::class => 1,
CustomerUpdateRequest::class => 1,
CustomerUpdateByKeyRequest::class => 1,
+ CustomerPasswordChangeRequest::class => 1,
ShippingMethodByCartIdGetRequest::class => 1,
ShoppingListByKeyGetRequest::class => 1,
ShoppingListByIdGetRequest::class => 1,
diff --git a/src/Core/Request/Me/Command/MyCartAddLineItemAction.php b/src/Core/Request/Me/Command/MyCartAddLineItemAction.php
new file mode 100644
index 0000000000..a9bc8d3049
--- /dev/null
+++ b/src/Core/Request/Me/Command/MyCartAddLineItemAction.php
@@ -0,0 +1,87 @@
+ [static::TYPE => 'string'],
+ 'productId' => [static::TYPE => 'string'],
+ 'variantId' => [static::TYPE => 'int'],
+ 'sku' => [static::TYPE => 'string'],
+ 'quantity' => [static::TYPE => 'int'],
+ 'supplyChannel' => [static::TYPE => ChannelReference::class],
+ 'distributionChannel' => [static::TYPE => ChannelReference::class],
+ 'custom' => [static::TYPE => CustomFieldObjectDraft::class],
+ 'externalTaxRate' => [static::TYPE => ExternalTaxRateDraft::class],
+ 'externalPrice' => [static::TYPE => Money::class],
+ 'externalTotalPrice' => [static::TYPE => ExternalLineItemTotalPrice::class],
+ 'shippingDetails' => [static::TYPE => ItemShippingDetailsDraft::class],
+ 'addedAt' => [static::TYPE => DateTime::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('addLineItem');
+ }
+
+ /**
+ * @param string $productId
+ * @param int $variantId
+ * @param Context|callable $context
+ * @param int $quantity
+ * @return MyCartAddLineItemAction
+ */
+ public static function ofProductIdVariantIdAndQuantity($productId, $variantId, $quantity, $context = null)
+ {
+ return static::of($context)->setProductId($productId)->setVariantId($variantId)->setQuantity($quantity);
+ }
+}
diff --git a/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderAddLineItemAction.php b/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderAddLineItemAction.php
index a02a56eaf4..954e03519a 100644
--- a/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderAddLineItemAction.php
+++ b/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderAddLineItemAction.php
@@ -12,6 +12,7 @@
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Cart\ExternalLineItemTotalPrice;
use Commercetools\Core\Model\Cart\ItemShippingDetailsDraft;
+use DateTime;
/**
* @package Commercetools\Core\Request\OrderEdits\StagedOrder\Command
@@ -40,6 +41,8 @@
* @method StagedOrderAddLineItemAction setExternalTotalPrice(ExternalLineItemTotalPrice $externalTotalPrice = null)
* @method ItemShippingDetailsDraft getShippingDetails()
* @method StagedOrderAddLineItemAction setShippingDetails(ItemShippingDetailsDraft $shippingDetails = null)
+ * @method DateTime getAddedAt()
+ * @method StagedOrderAddLineItemAction setAddedAt(DateTime $addedAt = null)
*/
class StagedOrderAddLineItemAction extends CartAddLineItemAction implements StagedOrderUpdateAction
{
diff --git a/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderSetLineItemDistributionChannelAction.php b/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderSetLineItemDistributionChannelAction.php
new file mode 100644
index 0000000000..9261546350
--- /dev/null
+++ b/src/Core/Request/OrderEdits/StagedOrder/Command/StagedOrderSetLineItemDistributionChannelAction.php
@@ -0,0 +1,23 @@
+ [static::TYPE => 'string'],
+ 'name' => [static::TYPE => 'string'],
+ 'parcelId' => [static::TYPE => 'string'],
+ 'value' => [static::TYPE => null],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setParcelCustomField');
+ }
+
+ /**
+ * @param string $parcelId
+ * @param string $name
+ * @param Context|callable $context
+ * @return static
+ */
+ public static function ofParcelIdAndName($parcelId, $name, $context = null)
+ {
+ return static::of($context)->setParcelId($parcelId)->setName($name);
+ }
+}
diff --git a/src/Core/Request/Orders/Command/OrderSetParcelCustomTypeAction.php b/src/Core/Request/Orders/Command/OrderSetParcelCustomTypeAction.php
new file mode 100644
index 0000000000..1234c1259e
--- /dev/null
+++ b/src/Core/Request/Orders/Command/OrderSetParcelCustomTypeAction.php
@@ -0,0 +1,43 @@
+ [static::TYPE => 'string'],
+ 'type' => [static::TYPE => TypeReference::class],
+ 'parcelId' => [static::TYPE => 'string'],
+ 'fields' => [static::TYPE => FieldContainer::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setParcelCustomType');
+ }
+}
diff --git a/src/Core/Request/Orders/Command/OrderSetReturnInfoAction.php b/src/Core/Request/Orders/Command/OrderSetReturnInfoAction.php
new file mode 100644
index 0000000000..1420a974a9
--- /dev/null
+++ b/src/Core/Request/Orders/Command/OrderSetReturnInfoAction.php
@@ -0,0 +1,40 @@
+ [static::TYPE => 'string'],
+ 'items' => [static::TYPE => ReturnInfoCollection::class]
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setReturnInfo');
+ }
+}
diff --git a/src/Core/Request/Orders/Command/OrderSetReturnItemCustomFieldAction.php b/src/Core/Request/Orders/Command/OrderSetReturnItemCustomFieldAction.php
new file mode 100644
index 0000000000..38cbb9c807
--- /dev/null
+++ b/src/Core/Request/Orders/Command/OrderSetReturnItemCustomFieldAction.php
@@ -0,0 +1,54 @@
+ [static::TYPE => 'string'],
+ 'name' => [static::TYPE => 'string'],
+ 'returnItemId' => [static::TYPE => 'string'],
+ 'value' => [static::TYPE => null],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setReturnItemCustomField');
+ }
+
+ /**
+ * @param string $returnItemId
+ * @param string $name
+ * @param Context|callable $context
+ * @return static
+ */
+ public static function ofReturnItemIdAndName($returnItemId, $name, $context = null)
+ {
+ return static::of($context)->setReturnItemId($returnItemId)->setName($name);
+ }
+}
diff --git a/src/Core/Request/Orders/Command/OrderSetReturnItemCustomTypeAction.php b/src/Core/Request/Orders/Command/OrderSetReturnItemCustomTypeAction.php
new file mode 100644
index 0000000000..fe9a6b4ca0
--- /dev/null
+++ b/src/Core/Request/Orders/Command/OrderSetReturnItemCustomTypeAction.php
@@ -0,0 +1,43 @@
+ [static::TYPE => 'string'],
+ 'type' => [static::TYPE => TypeReference::class],
+ 'returnItemId' => [static::TYPE => 'string'],
+ 'fields' => [static::TYPE => FieldContainer::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setReturnItemCustomType');
+ }
+}
diff --git a/src/Core/Request/Orders/OrderCreateFromCartRequest.php b/src/Core/Request/Orders/OrderCreateFromCartRequest.php
index 197fafc1e3..ff3a80cb8c 100644
--- a/src/Core/Request/Orders/OrderCreateFromCartRequest.php
+++ b/src/Core/Request/Orders/OrderCreateFromCartRequest.php
@@ -5,6 +5,7 @@
namespace Commercetools\Core\Request\Orders;
+use Commercetools\Core\Model\Cart\CartReference;
use Commercetools\Core\Model\State\StateReference;
use Commercetools\Core\Request\InStores\InStoreRequestDecorator;
use Commercetools\Core\Request\InStores\InStoreTrait;
@@ -31,6 +32,7 @@ class OrderCreateFromCartRequest extends AbstractApiRequest
use InStoreTrait;
const ID = 'id';
+ const CART = 'cart';
const VERSION = 'version';
const ORDER_NUMBER = 'orderNumber';
const PAYMENT_STATE = 'paymentState';
@@ -38,7 +40,14 @@ class OrderCreateFromCartRequest extends AbstractApiRequest
const STATE = 'state';
const SHIPMENT_STATE = 'shipmentState';
+ /**
+ * @deprecated use $cart instead
+ */
protected $cartId;
+ /**
+ * @var CartReference
+ */
+ protected $cart;
protected $version;
protected $orderNumber;
protected $paymentState;
@@ -49,20 +58,60 @@ class OrderCreateFromCartRequest extends AbstractApiRequest
protected $resultClass = Order::class;
/**
+ * @param CartReference|string $cart
+ * @param int $version
+ * @param Context $context
+ */
+ public function __construct($cart, $version = null, Context $context = null)
+ {
+ parent::__construct(OrdersEndpoint::endpoint(), $context);
+
+ if ($cart instanceof CartReference) {
+ $this->setCart($cart)->setVersion($version);
+ } else {
+ $this->setCart(CartReference::ofId($cart))->setVersion($version);
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function getCart()
+ {
+ return $this->cart;
+ }
+
+ /**
+ * @param CartReference $cart
+ * @return $this
+ */
+ public function setCart($cart)
+ {
+ $this->cart = $cart;
+
+ return $this;
+ }
+
+ /**
+ * @deprecated use getCart instead
* @return string
*/
public function getCartId()
{
- return $this->cartId;
+ if ($this->cart == null) {
+ return null;
+ }
+ return $this->cart->getId();
}
/**
+ * @deprecated use setCart instead
* @param string $cartId
* @return $this
*/
public function setCartId($cartId)
{
- $this->cartId = $cartId;
+ $this->cart = CartReference::ofId($cartId);
return $this;
}
@@ -182,25 +231,26 @@ public function setShipmentState($shipmentState)
}
/**
+ * @deprecated use ofCartAndVersion instead
* @param string $cartId
* @param int $version
* @param Context $context
+ * @return static
*/
- public function __construct($cartId, $version, Context $context = null)
+ public static function ofCartIdAndVersion($cartId, $version, Context $context = null)
{
- parent::__construct(OrdersEndpoint::endpoint(), $context);
- $this->setCartId($cartId)->setVersion($version);
+ return new static($cartId, $version, $context);
}
/**
- * @param string $cartId
+ * @param CartReference|string $cart
* @param int $version
* @param Context $context
* @return static
*/
- public static function ofCartIdAndVersion($cartId, $version, Context $context = null)
+ public static function ofCartAndVersion($cart, $version, Context $context = null)
{
- return new static($cartId, $version, $context);
+ return new static($cart, $version, $context);
}
/**
@@ -220,7 +270,7 @@ public function buildResponse(ResponseInterface $response)
public function httpRequest()
{
$payload = [
- static::ID => $this->getCartId(),
+ static::CART => $this->getCart(),
static::VERSION => $this->getVersion(),
];
if (!is_null($this->paymentState)) {
diff --git a/src/Core/Request/Payments/Command/PaymentSetTransactionCustomFieldAction.php b/src/Core/Request/Payments/Command/PaymentSetTransactionCustomFieldAction.php
new file mode 100644
index 0000000000..1e74a95db2
--- /dev/null
+++ b/src/Core/Request/Payments/Command/PaymentSetTransactionCustomFieldAction.php
@@ -0,0 +1,52 @@
+ [static::TYPE => 'string'],
+ 'name' => [static::TYPE => 'string'],
+ 'transactionId' => [static::TYPE => 'string'],
+ 'value' => [static::TYPE => null],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setTransactionCustomField');
+ }
+
+ /**
+ * @param string $transactionId
+ * @param string $name
+ * @param Context|callable $context
+ * @return static
+ */
+ public static function ofTransactionIdAndName($transactionId, $name, $context = null)
+ {
+ return static::of($context)->setTransactionId($transactionId)->setName($name);
+ }
+}
diff --git a/src/Core/Request/Payments/Command/PaymentSetTransactionCustomTypeAction.php b/src/Core/Request/Payments/Command/PaymentSetTransactionCustomTypeAction.php
new file mode 100644
index 0000000000..e108375d5a
--- /dev/null
+++ b/src/Core/Request/Payments/Command/PaymentSetTransactionCustomTypeAction.php
@@ -0,0 +1,77 @@
+ [static::TYPE => 'string'],
+ 'type' => [static::TYPE => TypeReference::class],
+ 'transactionId' => [static::TYPE => 'string'],
+ 'fields' => [static::TYPE => FieldContainer::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setTransactionCustomType');
+ }
+
+ /**
+ * @param string $typeKey
+ * @param string $transactionId
+ * @param Context|callable $context
+ * @return static
+ */
+ public static function ofTypeKeyAndTransactionId($typeKey, $transactionId, $context = null)
+ {
+ return static::ofTypeKey($typeKey, $context)->setTransactionId($transactionId);
+ }
+
+
+ /**
+ * @param string $typeId
+ * @param string $transactionId
+ * @param Context|callable $context
+ * @return static
+ */
+ public static function ofTypeIdAndTransactionId($typeId, $transactionId, $context = null)
+ {
+ return static::ofTypeId($typeId, $context)->setTransactionId($transactionId);
+ }
+
+ /**
+ * @param TypeReference $type
+ * @param string $transactionId
+ * @param Context|callable $context
+ * @return static
+ */
+ public static function ofTypeAndTransactionId(TypeReference $type, $transactionId, $context = null)
+ {
+ return static::ofType($type, $context)->setTransactionId($transactionId);
+ }
+}
diff --git a/src/Core/Request/Products/ProductByIdHeadRequest.php b/src/Core/Request/Products/ProductByIdHeadRequest.php
new file mode 100644
index 0000000000..1f4ca79729
--- /dev/null
+++ b/src/Core/Request/Products/ProductByIdHeadRequest.php
@@ -0,0 +1,42 @@
+ [static::TYPE => 'string'],
+ 'enabled' => [static::TYPE => 'bool'],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('changeProductSearchIndexingEnabled');
+ }
+
+ /**
+ * @param boolean $enabled
+ * @param Context|callable $context
+ * @return ProjectChangeProductSearchIndexingEnabledAction
+ */
+ public static function ofEnabled($enabled, $context = null)
+ {
+ return static::of($context)->setEnabled($enabled);
+ }
+}
diff --git a/src/Core/Request/Project/Command/ProjectChangeShoppingListsConfigurationAction.php b/src/Core/Request/Project/Command/ProjectChangeShoppingListsConfigurationAction.php
new file mode 100644
index 0000000000..63e3583bfe
--- /dev/null
+++ b/src/Core/Request/Project/Command/ProjectChangeShoppingListsConfigurationAction.php
@@ -0,0 +1,48 @@
+ [static::TYPE => 'string'],
+ 'shoppingListsConfiguration' => [static::TYPE => ShoppingListsConfiguration::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('changeShoppingListsConfiguration');
+ }
+
+ /**
+ * @param ShoppingListsConfiguration $shoppingListsConfiguration
+ * @param Context|callable $context
+ * @return ProjectChangeShoppingListsConfigurationAction
+ */
+ public static function ofShoppingListsConfiguration(ShoppingListsConfiguration $shoppingListsConfiguration, $context = null)
+ {
+ return static::of($context)->setShoppingListsConfiguration($shoppingListsConfiguration);
+ }
+}
diff --git a/src/Core/Request/ShippingMethods/Command/ShippingMethodSetCustomFieldAction.php b/src/Core/Request/ShippingMethods/Command/ShippingMethodSetCustomFieldAction.php
new file mode 100644
index 0000000000..8074524654
--- /dev/null
+++ b/src/Core/Request/ShippingMethods/Command/ShippingMethodSetCustomFieldAction.php
@@ -0,0 +1,24 @@
+
+ */
+
+namespace Commercetools\Core\Request\ShippingMethods\Command;
+
+use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction;
+
+/**
+ * @package Commercetools\Core\Request\ShippingMethods\Command
+ * @link https://docs.commercetools.com/api/projects/shippingMethods#set-customfield
+ * @method string getAction()
+ * @method ShippingMethodSetCustomFieldAction setAction(string $action = null)
+ * @method string getCustomField()
+ * @method ShippingMethodSetCustomFieldAction setCustomField(string $predicate = null)
+ * @method string getName()
+ * @method ShippingMethodSetCustomFieldAction setName(string $name = null)
+ * @method mixed getValue()
+ * @method ShippingMethodSetCustomFieldAction setValue($value = null)
+ */
+class ShippingMethodSetCustomFieldAction extends SetCustomFieldAction
+{
+}
diff --git a/src/Core/Request/ShippingMethods/Command/ShippingMethodSetCustomTypeAction.php b/src/Core/Request/ShippingMethods/Command/ShippingMethodSetCustomTypeAction.php
new file mode 100644
index 0000000000..d8cce9693d
--- /dev/null
+++ b/src/Core/Request/ShippingMethods/Command/ShippingMethodSetCustomTypeAction.php
@@ -0,0 +1,26 @@
+
+ */
+
+namespace Commercetools\Core\Request\ShippingMethods\Command;
+
+use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction;
+use Commercetools\Core\Model\Type\TypeReference;
+use Commercetools\Core\Model\CustomField\FieldContainer;
+
+/**
+ * @package Commercetools\Core\Request\ShippingMethods\Command
+ * @link https://docs.commercetools.com/api/projects/shippingMethods#set-customtype
+ * @method string getAction()
+ * @method ShippingMethodSetCustomTypeAction setAction(string $action = null)
+ * @method string getCustomType()
+ * @method ShippingMethodSetCustomTypeAction setCustomType(string $predicate = null)
+ * @method TypeReference getType()
+ * @method ShippingMethodSetCustomTypeAction setType(TypeReference $type = null)
+ * @method FieldContainer getFields()
+ * @method ShippingMethodSetCustomTypeAction setFields(FieldContainer $fields = null)
+ */
+class ShippingMethodSetCustomTypeAction extends SetCustomTypeAction
+{
+}
diff --git a/src/Core/Request/ShippingMethods/Command/ShippingMethodSetLocalizedNameAction.php b/src/Core/Request/ShippingMethods/Command/ShippingMethodSetLocalizedNameAction.php
new file mode 100644
index 0000000000..85d26720f9
--- /dev/null
+++ b/src/Core/Request/ShippingMethods/Command/ShippingMethodSetLocalizedNameAction.php
@@ -0,0 +1,36 @@
+ [static::TYPE => 'string'],
+ 'localizedName' => [static::TYPE => LocalizedString::class],
+ ];
+ }
+
+ /**
+ * @param array $data
+ * @param Context|callable $context
+ */
+ public function __construct(array $data = [], $context = null)
+ {
+ parent::__construct($data, $context);
+ $this->setAction('setLocalizedName');
+ }
+}
diff --git a/src/Core/Response/PagedQueryResponse.php b/src/Core/Response/PagedQueryResponse.php
index f4f4382a81..8ee306ac1f 100644
--- a/src/Core/Response/PagedQueryResponse.php
+++ b/src/Core/Response/PagedQueryResponse.php
@@ -84,6 +84,7 @@ public function getResults()
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Retrieve an external iterator
@@ -97,6 +98,7 @@ public function getIterator()
return new \ArrayIterator($this->results);
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Whether a offset exists
@@ -115,6 +117,7 @@ public function offsetExists($offset)
return isset($results[$offset]);
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Offset to retrieve
@@ -130,6 +133,7 @@ public function offsetGet($offset)
return $results[$offset];
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Offset to set
@@ -152,6 +156,7 @@ public function offsetSet($offset, $value)
}
}
+ #[\ReturnTypeWillChange]
/**
* (PHP 5 >= 5.0.0)
* Offset to unset
diff --git a/tests/integration/ApiTestCase.php b/tests/integration/ApiTestCase.php
index 9c1cffe6fe..326ff4e9c0 100644
--- a/tests/integration/ApiTestCase.php
+++ b/tests/integration/ApiTestCase.php
@@ -36,6 +36,7 @@
use Commercetools\Core\Request\AbstractDeleteRequest;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Middleware;
+use GuzzleHttp\RetryMiddleware;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Monolog\Handler\ErrorLogHandler;
@@ -233,24 +234,27 @@ public function getApiClient($scope = 'manage_project')
'verify' => $this->getVerifySSL(),
'timeout' => '15',
'middlewares' => [
- 'retry' => Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) use ($maxRetries) {
- if ($response instanceof ResponseInterface && $response->getStatusCode() < 500) {
+ 'retry' => Middleware::retry(
+ function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) use ($maxRetries) {
+ if ($response instanceof ResponseInterface && $response->getStatusCode() < 500) {
+ return false;
+ }
+ if ($retries > $maxRetries) {
+ return false;
+ }
+ if ($error instanceof ServiceUnavailableException) {
+ return true;
+ }
+ if ($error instanceof ServerException && $error->getCode() == 503) {
+ return true;
+ }
+ if ($response instanceof ResponseInterface && $response->getStatusCode() == 503) {
+ return true;
+ }
return false;
- }
- if ($retries > $maxRetries) {
- return false;
- }
- if ($error instanceof ServiceUnavailableException) {
- return true;
- }
- if ($error instanceof ServerException && $error->getCode() == 503) {
- return true;
- }
- if ($response instanceof ResponseInterface && $response->getStatusCode() == 503) {
- return true;
- }
- return false;
- })
+ },
+ [RetryMiddleware::class, 'exponentialDelay']
+ )
]
];
$enableProfiler = getenv('PHP_SDK_PROFILE');
@@ -678,17 +682,19 @@ protected function eventually(callable $eventuallyFunction, $maxRetries = 30)
protected function exceptionEventually(callable $eventuallyFunction, $maxRetries = 30)
{
$retries = 0;
+ $e = null;
do {
$retries++;
try {
$eventuallyFunction();
- } catch (\Exception $e) {
sleep(1);
+ } catch (\Exception $exception) {
+ $e = $exception;
}
} while ($e == null && $retries <= $maxRetries);
if (is_null($e)) {
- throw new EventuallyException("Timeout eventually block", $e->getCode(), $e);
+ throw new EventuallyException("Timeout eventually block");
}
throw $e;
}
diff --git a/tests/integration/Cart/CartCreateRequestTest.php b/tests/integration/Cart/CartCreateRequestTest.php
index 859a123192..4a0b41b415 100644
--- a/tests/integration/Cart/CartCreateRequestTest.php
+++ b/tests/integration/Cart/CartCreateRequestTest.php
@@ -8,13 +8,19 @@
use Commercetools\Core\Builder\Request\RequestBuilder;
use Commercetools\Core\Fixtures\FixtureException;
use Commercetools\Core\IntegrationTests\ApiTestCase;
+use Commercetools\Core\IntegrationTests\DiscountCode\DiscountCodeFixture;
use Commercetools\Core\IntegrationTests\Product\ProductFixture;
use Commercetools\Core\IntegrationTests\Store\StoreFixture;
use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Core\Model\Cart\CartDraft;
use Commercetools\Core\Model\Cart\CartState;
+use Commercetools\Core\Model\CartDiscount\CartDiscount;
+use Commercetools\Core\Model\CartDiscount\CartDiscountReferenceCollection;
+use Commercetools\Core\Model\DiscountCode\DiscountCode;
+use Commercetools\Core\Model\DiscountCode\DiscountCodeDraft;
use Commercetools\Core\Model\Product\Product;
use Commercetools\Core\Model\Store\Store;
+use Commercetools\Core\Model\Store\StoreReference;
use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction;
use Commercetools\Core\Request\InStores\InStoreRequestDecorator;
@@ -73,6 +79,25 @@ function (Cart $cart) use ($client, $originType, $successful) {
);
}
+ public function testCreateWithDiscount()
+ {
+ $client = $this->getApiClient();
+ DiscountCodeFixture::withActiveDiscountCode(
+ $client,
+ function (DiscountCode $discountCode) use ($client) {
+ CartFixture::withDraftCart(
+ $client,
+ function (CartDraft $draft) use ($discountCode) {
+ return $draft->setCountry("DE")->setCurrency("EUR")->setDiscountCodes([$discountCode->getCode()]);
+ },
+ function (Cart $cart) use ($client, $discountCode) {
+ $this->assertSame($discountCode->getId(), $cart->getDiscountCodes()->current()->getDiscountCode()->getId());
+ }
+ );
+ }
+ );
+ }
+
public function testCreateReplicaCartFromCart()
{
$client = $this->getApiClient();
@@ -103,6 +128,8 @@ function (Cart $cart) use ($client, $product) {
$replicaCart = $request->mapFromResponse($response);
$this->assertNotEmpty($replicaCart->getLineItems());
+ $this->assertNotEmpty($replicaCart->getLineItems()->current()->getLastModifiedAt());
+ $this->assertNotEmpty($replicaCart->getLineItems()->current()->getAddedAt());
$cartLineItem = $cart->getLineItems()->current()->getProductId();
$replicaCartLineItem = $replicaCart->getLineItems()->current()->getProductId();
@@ -118,6 +145,81 @@ function (Cart $cart) use ($client, $product) {
);
}
+ public function testCreateReplicaFromCartInStore()
+ {
+ $client = $this->getApiClient();
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client) {
+ ProductFixture::withPublishedProduct(
+ $client,
+ function (Product $product) use ($client, $store) {
+ CartFixture::withUpdateableDraftCart(
+ $client,
+ function (CartDraft $cartDraft) use ($store) {
+ return $cartDraft->setStore(StoreReference::ofKey($store->getKey()));
+ },
+ function (Cart $cart) use ($client, $store, $product) {
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest(
+ $store->getKey(),
+ RequestBuilder::of()->carts()->getById($cart->getId())
+ );
+ $response = $this->execute($client, $request);
+ $cartInStore = $request->mapFromResponse($response);
+
+ $variant = $product->getMasterData()->getCurrent()->getMasterVariant();
+
+ $request = RequestBuilder::of()->carts()->update($cartInStore)
+ ->addAction(
+ CartAddLineItemAction::ofProductIdVariantIdAndQuantity(
+ $product->getId(),
+ $variant->getId(),
+ 1
+ )
+ );
+ $response = $this->execute($client, $request);
+ $cartWithProduct = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Cart::class, $cartWithProduct);
+
+ $request = RequestBuilder::of()->carts()->replicate($cartWithProduct->getId());
+ $response = $this->execute($client, $request);
+ $replicaCart = $request->mapFromResponse($response);
+
+ $this->assertNotEmpty($replicaCart->getLineItems());
+ $this->assertNotEmpty($replicaCart->getLineItems()->current()->getLastModifiedAt());
+ $this->assertNotEmpty($replicaCart->getLineItems()->current()->getAddedAt());
+
+ $cartRequest = RequestBuilder::of()->carts()->delete($cartWithProduct);
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest($store->getKey(), $cartRequest);
+ $response = $request->executeWithClient($this->getClient());
+ $request->mapResponse($response);
+
+ $cartRequest = RequestBuilder::of()->carts()->delete($replicaCart);
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest($store->getKey(), $cartRequest);
+ $response = $request->executeWithClient($this->getClient());
+ $result = $request->mapResponse($response);
+
+ $this->assertInstanceOf(Cart::class, $result);
+ $this->assertSame($replicaCart->getId(), $result->getId());
+
+ $cartLineItem = $cartWithProduct->getLineItems()->current()->getProductId();
+ $replicaCartLineItem = $replicaCart->getLineItems()->current()->getProductId();
+
+ $this->assertSame($cartLineItem, $replicaCartLineItem);
+ $this->assertNotSame($cartWithProduct->getId(), $replicaCart->getId());
+ $this->assertSame(CartState::ACTIVE, $replicaCart->getCartState());
+
+ return $replicaCart;
+ }
+ );
+ }
+ );
+ }
+ );
+ }
+
public function testCreateCartInStore()
{
$client = $this->getApiClient();
diff --git a/tests/integration/Cart/CartFixture.php b/tests/integration/Cart/CartFixture.php
index 6df0e074b6..af356313c9 100644
--- a/tests/integration/Cart/CartFixture.php
+++ b/tests/integration/Cart/CartFixture.php
@@ -46,7 +46,8 @@ final public static function customerCartDraftFunction(Customer $customer, Shipp
->setShippingAddress($customer->getDefaultShippingAddress())
->setBillingAddress($customer->getDefaultBillingAddress())
->setCustomerEmail($customer->getEmail())
- ->setShippingMethod($shippingMethod->getReference());
+ ->setShippingMethod($shippingMethod->getReference())
+ ->setKey(self::uniqueCartString());
return $draft;
}
diff --git a/tests/integration/Cart/CartQueryRequestTest.php b/tests/integration/Cart/CartQueryRequestTest.php
index cda132a1f4..51d1057dd8 100644
--- a/tests/integration/Cart/CartQueryRequestTest.php
+++ b/tests/integration/Cart/CartQueryRequestTest.php
@@ -35,6 +35,23 @@ function (Cart $cart) use ($client) {
);
}
+ public function testGetByKey()
+ {
+ $client = $this->getApiClient();
+
+ CartFixture::withCustomerCart(
+ $client,
+ function (Cart $cart) use ($client) {
+ $request = RequestBuilder::of()->carts()->getByKey($cart->getKey());
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Cart::class, $result);
+ $this->assertSame($cart->getKey(), $result->getKey());
+ }
+ );
+ }
+
public function testQuery()
{
$client = $this->getApiClient();
@@ -104,6 +121,39 @@ function (Cart $cart) use ($client, $store) {
);
}
+ public function testGetByKeyInStore()
+ {
+ $client = $this->getApiClient();
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client) {
+ CartFixture::withDraftCustomerCart(
+ $client,
+ function (CartDraft $cartDraft) use ($store) {
+ return $cartDraft->setStore(StoreReference::ofKey($store->getKey()));
+ },
+ function (Cart $cart) use ($client, $store) {
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest(
+ $store->getKey(),
+ RequestBuilder::of()->carts()->getByKey($cart->getKey())
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Cart::class, $result);
+ $this->assertSame($cart->getCountry(), $result->getCountry());
+ $this->assertSame(
+ 'in-store/key=' . $store->getKey() . '/carts/key='. $result->getKey(),
+ (string)$request->httpRequest()->getUri()
+ );
+ $this->assertSame($store->getKey(), $result->getStore()->getKey());
+ }
+ );
+ }
+ );
+ }
+
public function testQueryInStore()
{
$client = $this->getApiClient();
@@ -164,4 +214,29 @@ function (Cart $cart) use ($client, $store) {
}
);
}
+
+ public function testGetByKeyNotInStore()
+ {
+ $this->expectException(FixtureException::class);
+ $this->expectExceptionCode(404);
+
+ $client = $this->getApiClient();
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client) {
+ CartFixture::withCustomerCart(
+ $client,
+ function (Cart $cart) use ($client, $store) {
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest(
+ $store->getKey(),
+ RequestBuilder::of()->carts()->getByKey($cart->getKey())
+ );
+ $response = $this->execute($client, $request);
+ $request->mapFromResponse($response);
+ }
+ );
+ }
+ );
+ }
}
diff --git a/tests/integration/Cart/CartUpdateRequestTest.php b/tests/integration/Cart/CartUpdateRequestTest.php
index e820f63b40..558e89bf74 100644
--- a/tests/integration/Cart/CartUpdateRequestTest.php
+++ b/tests/integration/Cart/CartUpdateRequestTest.php
@@ -9,6 +9,7 @@
use Commercetools\Core\Fixtures\FixtureException;
use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\IntegrationTests\CartDiscount\CartDiscountFixture;
+use Commercetools\Core\IntegrationTests\Channel\ChannelFixture;
use Commercetools\Core\IntegrationTests\Customer\CustomerFixture;
use Commercetools\Core\IntegrationTests\CustomerGroup\CustomerGroupFixture;
use Commercetools\Core\IntegrationTests\DiscountCode\DiscountCodeFixture;
@@ -43,6 +44,9 @@
use Commercetools\Core\Model\CartDiscount\MultiBuyCustomLineItemsTarget;
use Commercetools\Core\Model\CartDiscount\MultiBuyLineItemsTarget;
use Commercetools\Core\Model\CartDiscount\RelativeCartDiscountValue;
+use Commercetools\Core\Model\Channel\Channel;
+use Commercetools\Core\Model\Channel\ChannelDraft;
+use Commercetools\Core\Model\Channel\ChannelRole;
use Commercetools\Core\Model\Common\Address;
use Commercetools\Core\Model\Common\AddressCollection;
use Commercetools\Core\Model\Common\LocalizedString;
@@ -109,10 +113,13 @@
use Commercetools\Core\Request\Carts\Command\CartSetDeleteDaysAfterLastModificationAction;
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomFieldAction;
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomTypeAction;
+use Commercetools\Core\Request\Carts\Command\CartSetKeyAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction;
+use Commercetools\Core\Request\Carts\Command\CartSetLineItemDistributionChannelAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemShippingDetailsAction;
+use Commercetools\Core\Request\Carts\Command\CartSetLineItemSupplyChannelAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction;
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction;
use Commercetools\Core\Request\Carts\Command\CartSetLocaleAction;
@@ -236,6 +243,7 @@ function (Cart $cart) use ($client, $product) {
$cart = $request->mapFromResponse($response);
$this->assertSame(2, $cart->getLineItems()->current()->getQuantity());
+ $this->assertNotEmpty($cart->getLineItems()->current()->getLastModifiedAt());
$request = RequestBuilder::of()->carts()->update($cart)
->addAction(
@@ -601,6 +609,26 @@ function (Cart $cart) use ($client, $product, $variant) {
);
}
+ public function testSetKey()
+ {
+ $client = $this->getApiClient();
+
+ CartFixture::withUpdateableCart(
+ $client,
+ function (Cart $cart) use ($client) {
+ $key = CartFixture::uniqueCartString();
+ $request = RequestBuilder::of()->carts()->update($cart)
+ ->addAction(
+ CartSetKeyAction::of()->setKey($key)
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertSame($key, $result->getKey());
+ }
+ );
+ }
+
public function testExternalLineItemPriceQuantityChange()
{
$client = $this->getApiClient();
@@ -931,6 +959,32 @@ function (Cart $cart) use ($client) {
);
}
+ public function testCustomerEmailUpdateByKey()
+ {
+ $client = $this->getApiClient();
+ $key = CartFixture::uniqueCartString();
+
+ CartFixture::withUpdateableDraftCart(
+ $client,
+ function (CartDraft $cartDraft) use ($key) {
+ return $cartDraft->setKey($key);
+ },
+ function (Cart $cart) use ($client, $key) {
+ $email = 'test-' . CartFixture::uniqueCartString() . '@example.com';
+
+ $request = RequestBuilder::of()->carts()->updateByKey($cart)
+ ->addAction(CartSetCustomerEmailAction::of()->setEmail($email));
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertSame($email, $result->getCustomerEmail());
+ $this->assertSame($key, $result->getKey());
+
+ return $result;
+ }
+ );
+ }
+
public function testShippingAddress()
{
$client = $this->getApiClient();
@@ -1633,8 +1687,7 @@ function (Cart $cart) use ($client, $type, $product) {
$request = RequestBuilder::of()->carts()->update($cart)
->addAction(
- CartSetLineItemCustomFieldAction::ofName('testField')
- ->setLineItemId($cart->getLineItems()->current()->getId())
+ CartSetLineItemCustomFieldAction::ofLineItemIdAndName($cart->getLineItems()->current()->getId(), 'testField')
->setValue($value)
);
$response = $this->execute($client, $request);
@@ -2530,6 +2583,8 @@ function (Cart $cart) use ($client, $product, $cartDiscount) {
$this->assertCount(2, $cart->getLineItems());
$this->assertSame(100, $cart->getTotalPrice()->getCentAmount());
+ $this->assertNotEmpty($cart->getLineItems()->current()->getLastModifiedAt());
+ $this->assertNotEmpty($cart->getLineItems()->current()->getAddedAt());
$giftLineItemIncluded = false;
foreach ($cart->getLineItems() as $lineItem) {
@@ -2871,6 +2926,8 @@ function (Cart $cart) use ($client, $product, $variant) {
$result->getLineItems()->current()->getShippingDetails()
->getTargets()->current()->getQuantity()
);
+ $this->assertNotEmpty($cart->getLineItems()->current()->getLastModifiedAt());
+ $this->assertNotEmpty($cart->getLineItems()->current()->getAddedAt());
return $result;
}
@@ -3164,4 +3221,156 @@ function (Cart $cart) use ($client, $store) {
}
);
}
+
+ public function testUpdateAndDeleteByKeyForCartInStore()
+ {
+ $client = $this->getApiClient();
+ $key = CartFixture::uniqueCartString();
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client, $key) {
+ CartFixture::withUpdateableDraftCart(
+ $client,
+ function (CartDraft $draft) use ($store, $key) {
+ return $draft->setStore(StoreReference::ofKey($store->getKey()))->setKey($key);
+ },
+ function (Cart $cart) use ($client, $store, $key) {
+ $this->assertSame($key, $cart->getKey());
+
+ $email = 'test-' . CartFixture::uniqueCartString() . '@example.com';
+
+ $request = RequestBuilder::of()->carts()->update($cart)
+ ->addAction(CartSetCustomerEmailAction::of()->setEmail($email))
+ ->inStore($store->getKey());
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Cart::class, $result);
+ $this->assertSame($cart->getId(), $result->getId());
+ $this->assertSame($email, $result->getCustomerEmail());
+ $this->assertSame(
+ 'in-store/key=' . $store->getKey() . '/carts/' . $result->getId(),
+ (string)$request->httpRequest()->getUri()
+ );
+ $this->assertSame($store->getKey(), $result->getStore()->getKey());
+
+ $cartRequest = RequestBuilder::of()->carts()->deleteByKey($result);
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest($store->getKey(), $cartRequest);
+ $response = $request->executeWithClient($this->getClient());
+ $result = $request->mapResponse($response);
+
+ $this->assertInstanceOf(Cart::class, $result);
+ $this->assertSame($cart->getKey(), $result->getKey());
+
+ return $result;
+ }
+ );
+ }
+ );
+ }
+
+ public function testCartSetLineItemDistributionChannel()
+ {
+ $client = $this->getApiClient();
+
+ ProductFixture::withPublishedProduct(
+ $client,
+ function (Product $product) use ($client) {
+ $variant = $product->getMasterData()->getCurrent()->getMasterVariant();
+
+ ChannelFixture::withDraftChannel(
+ $client,
+ function (ChannelDraft $draft) {
+ return $draft->setRoles([ChannelRole::PRODUCT_DISTRIBUTION]);
+ },
+ function (Channel $channel) use ($client, $product, $variant) {
+ CartFixture::withUpdateableCart(
+ $client,
+ function (Cart $cart) use ($client, $product, $channel, $variant) {
+ $request = RequestBuilder::of()->carts()->update($cart)
+ ->addAction(
+ CartAddLineItemAction::ofProductIdVariantIdAndQuantity(
+ $product->getId(),
+ $variant->getId(),
+ 1
+ )
+ );
+ $response = $this->execute($client, $request);
+ $cart = $request->mapFromResponse($response);
+
+ $this->assertSame($product->getId(), $cart->getLineItems()->current()->getProductId());
+
+ $request = RequestBuilder::of()->carts()->update($cart)
+ ->addAction(
+ CartSetLineItemDistributionChannelAction::ofItemLineIdAndDistributionChannel(
+ $cart->getLineItems()->current()->getId(),
+ $channel->getReference()
+ )
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertSame($channel->getReference()->getId(), $result->getLineItems()->current()->getDistributionChannel()->getId());
+
+ return $result;
+ }
+ );
+ }
+ );
+ }
+ );
+ }
+
+ public function testCartSetLineItemSupplyChannel()
+ {
+ $client = $this->getApiClient();
+
+ ProductFixture::withPublishedProduct(
+ $client,
+ function (Product $product) use ($client) {
+ $variant = $product->getMasterData()->getCurrent()->getMasterVariant();
+
+ ChannelFixture::withDraftChannel(
+ $client,
+ function (ChannelDraft $draft) {
+ return $draft->setRoles([ChannelRole::INVENTORY_SUPPLY]);
+ },
+ function (Channel $channel) use ($client, $product, $variant) {
+ CartFixture::withUpdateableCart(
+ $client,
+ function (Cart $cart) use ($client, $product, $channel, $variant) {
+ $request = RequestBuilder::of()->carts()->update($cart)
+ ->addAction(
+ CartAddLineItemAction::ofProductIdVariantIdAndQuantity(
+ $product->getId(),
+ $variant->getId(),
+ 1
+ )
+ );
+ $response = $this->execute($client, $request);
+ $cart = $request->mapFromResponse($response);
+
+ $this->assertSame($product->getId(), $cart->getLineItems()->current()->getProductId());
+
+ $request = RequestBuilder::of()->carts()->update($cart)
+ ->addAction(
+ CartSetLineItemSupplyChannelAction::ofItemLineIdAndSupplyChannel(
+ $cart->getLineItems()->current()->getId(),
+ $channel->getReference()
+ )
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertSame($channel->getReference()->getId(), $result->getLineItems()->current()->getSupplyChannel()->getId());
+
+ return $result;
+ }
+ );
+ }
+ );
+ }
+ );
+ }
}
diff --git a/tests/integration/Customer/CustomerLoginRequestTest.php b/tests/integration/Customer/CustomerLoginRequestTest.php
index 5486c89340..e234f81d06 100644
--- a/tests/integration/Customer/CustomerLoginRequestTest.php
+++ b/tests/integration/Customer/CustomerLoginRequestTest.php
@@ -19,11 +19,13 @@
use Commercetools\Core\Model\Customer\Customer;
use Commercetools\Core\Model\Customer\CustomerDraft;
use Commercetools\Core\Model\Customer\CustomerToken;
+use Commercetools\Core\Model\Message\CustomerPasswordUpdatedMessage;
use Commercetools\Core\Model\Store\Store;
use Commercetools\Core\Request\Customers\CustomerCreateRequest;
use Commercetools\Core\Request\Customers\CustomerDeleteRequest;
use Commercetools\Core\Request\Customers\CustomerLoginRequest;
use Commercetools\Core\Request\InStores\InStoreRequestDecorator;
+use Commercetools\Core\Request\Messages\MessageQueryRequest;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LogLevel;
@@ -158,9 +160,29 @@ function (Customer $customer) use ($client, $password) {
$request = RequestBuilder::of()->customers()
->changePassword($customer, $password, CustomerFixture::uniqueCustomerString());
$response = $this->execute($client, $request);
- $result = $request->mapFromResponse($response);
-
- $this->assertSame($customer->getId(), $result->getId());
+ $customerUpdated = $request->mapFromResponse($response);
+
+ $this->assertSame($customer->getId(), $customerUpdated->getId());
+
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "CustomerPasswordUpdated"')
+ ->where('resource(id = "' . $customerUpdated->getId() . '")');
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var CustomerPasswordUpdatedMessage $message
+ */
+ $message = $result->current();
+
+ $this->assertInstanceOf(CustomerPasswordUpdatedMessage::class, $message);
+ $this->assertSame($customerUpdated->getId(), $message->getResource()->getId());
+ $this->assertTrue(!$message->getReset());
}
);
}
@@ -218,9 +240,29 @@ function (Customer $customer) use ($client, $password) {
$request = RequestBuilder::of()->customers()
->resetPassword($token, $newPassword);
$response = $this->execute($client, $request);
- $result = $request->mapFromResponse($response);
-
- $this->assertSame($customer->getId(), $result->getId());
+ $customerUpdated = $request->mapFromResponse($response);
+
+ $this->assertSame($customer->getId(), $customerUpdated->getId());
+
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "CustomerPasswordUpdated"')
+ ->where('resource(id = "' . $customerUpdated->getId() . '")');
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var CustomerPasswordUpdatedMessage $message
+ */
+ $message = $result->current();
+
+ $this->assertInstanceOf(CustomerPasswordUpdatedMessage::class, $message);
+ $this->assertSame($customerUpdated->getId(), $message->getResource()->getId());
+ $this->assertTrue($message->getReset());
$request = RequestBuilder::of()->customers()
->login($customer->getEmail(), $newPassword);
@@ -560,6 +602,84 @@ function (Cart $anonCart) use ($client, $customer, $password, $cart) {
}
);
}
+ public function testInStoreChangePasswordSuccess()
+ {
+ $client = $this->getApiClient();
+ $password = 'test-' . CustomerFixture::uniqueCustomerString() . '-password';
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client, $password) {
+ CustomerFixture::withDraftCustomer(
+ $client,
+ function (CustomerDraft $draft) use ($password) {
+ return $draft->setPassword($password);
+ },
+ function (Customer $customer) use ($client, $store, $password) {
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest(
+ $store->getKey(),
+ RequestBuilder::of()->customers()
+ ->changePassword($customer, $password, CustomerFixture::uniqueCustomerString())
+ );
+ $response = $this->execute($client, $request);
+ $customerUpdated = $request->mapFromResponse($response);
+
+ $this->assertSame($customer->getId(), $customerUpdated->getId());
+
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "CustomerPasswordUpdated"')
+ ->where('resource(id = "' . $customerUpdated->getId() . '")');
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var CustomerPasswordUpdatedMessage $message
+ */
+ $message = $result->current();
+
+ $this->assertInstanceOf(CustomerPasswordUpdatedMessage::class, $message);
+ $this->assertSame($customerUpdated->getId(), $message->getResource()->getId());
+ $this->assertTrue(!$message->getReset());
+ }
+ );
+ }
+ );
+ }
+
+ public function testInStoreChangePasswordFailure()
+ {
+ $this->expectException(FixtureException::class);
+ $this->expectExceptionCode(400);
+ $this->expectExceptionMessageMatches("/InvalidCurrentPassword/");
+
+ $client = $this->getApiClient();
+ $password = 'test-' . CustomerFixture::uniqueCustomerString() . '-password';
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client, $password) {
+ CustomerFixture::withDraftCustomer(
+ $client,
+ function (CustomerDraft $draft) use ($password) {
+ return $draft->setPassword($password);
+ },
+ function (Customer $customer) use ($client, $password, $store) {
+ $request = InStoreRequestDecorator::ofStoreKeyAndRequest(
+ $store->getKey(),
+ RequestBuilder::of()->customers()
+ ->changePassword($customer, CustomerFixture::uniqueCustomerString(), $password)
+ );
+ $this->execute($client, $request);
+ }
+ );
+ }
+ );
+ }
public function testInStorePasswordReset()
{
diff --git a/tests/integration/DiscountCode/DiscountCodeFixture.php b/tests/integration/DiscountCode/DiscountCodeFixture.php
index 9ac420dd94..3a2a1aadfd 100644
--- a/tests/integration/DiscountCode/DiscountCodeFixture.php
+++ b/tests/integration/DiscountCode/DiscountCodeFixture.php
@@ -38,6 +38,19 @@ final public static function defaultDiscountCodeDraftFunction(
return $draft;
}
+ final public static function defaultActiveDiscountCodeDraftFunction(
+ CartDiscountReferenceCollection $cartDiscountReferenceCollection
+ ) {
+ $uniqueDiscountCodeString = self::uniqueDiscountCodeString();
+ $draft = DiscountCodeDraft::ofCodeDiscountsAndActive(
+ 'test-' . $uniqueDiscountCodeString . '-code',
+ $cartDiscountReferenceCollection,
+ true
+ );
+
+ return $draft;
+ }
+
final public static function discountCodeDraftWithoutCartDiscountFunction()
{
$uniqueDiscountCodeString = self::uniqueDiscountCodeString();
@@ -165,6 +178,59 @@ function (CartDiscount $cartDiscount) use (
}
);
}
+
+ final public static function withActiveDraftDiscountCode(
+ ApiClient $client,
+ callable $draftBuilderFunction,
+ callable $assertFunction,
+ callable $createFunction = null,
+ callable $deleteFunction = null,
+ callable $draftFunction = null
+ ) {
+ CartDiscountFixture::withDraftCartDiscount(
+ $client,
+ function (CartDiscountDraft $cartDiscountDraft) {
+ return $cartDiscountDraft->setRequiresDiscountCode(true);
+ },
+ function (CartDiscount $cartDiscount) use (
+ $client,
+ $draftBuilderFunction,
+ $assertFunction,
+ $createFunction,
+ $deleteFunction,
+ $draftFunction
+ ) {
+ $cartDiscountReferences = CartDiscountReferenceCollection::of()
+ ->add(CartDiscountReference::ofId($cartDiscount->getId()));
+ if ($draftFunction == null) {
+ $draftFunction = function () use ($cartDiscountReferences) {
+ return call_user_func([__CLASS__, 'defaultActiveDiscountCodeDraftFunction'], $cartDiscountReferences);
+ };
+ } else {
+ $draftFunction = function () use ($cartDiscountReferences, $draftFunction) {
+ return call_user_func($draftFunction, $cartDiscountReferences);
+ };
+ }
+ if ($createFunction == null) {
+ $createFunction = [__CLASS__, 'defaultDiscountCodeCreateFunction'];
+ }
+ if ($deleteFunction == null) {
+ $deleteFunction = [__CLASS__, 'defaultDiscountCodeDeleteFunction'];
+ }
+
+ parent::withDraftResource(
+ $client,
+ $draftBuilderFunction,
+ $assertFunction,
+ $createFunction,
+ $deleteFunction,
+ $draftFunction,
+ [$cartDiscount]
+ );
+ }
+ );
+ }
+
final public static function withDraftCategory(
ApiClient $client,
callable $draftBuilderFunction,
@@ -237,6 +303,23 @@ final public static function withDiscountCode(
);
}
+ final public static function withActiveDiscountCode(
+ ApiClient $client,
+ callable $assertFunction,
+ callable $createFunction = null,
+ callable $deleteFunction = null,
+ callable $draftFunction = null
+ ) {
+ self::withActiveDraftDiscountCode(
+ $client,
+ [__CLASS__, 'defaultDiscountCodeDraftBuilderFunction'],
+ $assertFunction,
+ $createFunction,
+ $deleteFunction,
+ $draftFunction
+ );
+ }
+
final public static function withUpdateableDiscountCode(
ApiClient $client,
callable $assertFunction,
diff --git a/tests/integration/Inventory/InventoryUpdateRequestTest.php b/tests/integration/Inventory/InventoryUpdateRequestTest.php
index 9b65d9551a..9379a5690a 100644
--- a/tests/integration/Inventory/InventoryUpdateRequestTest.php
+++ b/tests/integration/Inventory/InventoryUpdateRequestTest.php
@@ -187,6 +187,7 @@ function (InventoryEntry $inventoryEntry) use ($client, $channel) {
public function testQueryChannels()
{
+ self::markTestSkipped();
$client = $this->getApiClient();
ChannelFixture::withChannel(
diff --git a/tests/integration/Me/MeCartRequestTest.php b/tests/integration/Me/MeCartRequestTest.php
index df4a115e66..93f0975e18 100644
--- a/tests/integration/Me/MeCartRequestTest.php
+++ b/tests/integration/Me/MeCartRequestTest.php
@@ -6,14 +6,13 @@
namespace Commercetools\Core\IntegrationTests\Me;
-use Commercetools\Core\Client\ClientFactory;
-use Commercetools\Core\Error\BadRequestException;
-use Commercetools\Core\Fixtures\AnonymousId;
-use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\Client;
-use Commercetools\Core\Config;
use Commercetools\Core\Client\OAuth\Manager;
+use Commercetools\Core\Config;
+use Commercetools\Core\Error\BadRequestException;
use Commercetools\Core\Error\ResourceNotFoundError;
+use Commercetools\Core\Fixtures\AnonymousId;
+use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Core\Model\Cart\CartDraft;
use Commercetools\Core\Model\Cart\MyCartDraft;
@@ -103,8 +102,7 @@ public function testAnonIdOAuth()
$anonId = uniqid();
$config = $this->getClientConfig(['view_products', 'manage_my_profile', 'manage_my_orders']);
$config->setGrantType(Config::GRANT_TYPE_ANONYMOUS)
- ->setAnonymousId($anonId)
- ;
+ ->setAnonymousId($anonId);
$testHandler = new TestHandler();
$logger = new Logger('test');
@@ -136,8 +134,7 @@ public function testCustomerOAuth()
$config = $this->getClientConfig(['view_products', 'manage_my_profile', 'manage_my_orders']);
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$testHandler = new TestHandler();
$logger = new Logger('test');
@@ -168,8 +165,7 @@ public function testCustomerRefreshTokenOAuth()
$config = $this->getClientConfig(['view_products', 'manage_my_profile', 'manage_my_orders']);
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$testHandler = new TestHandler();
$logger = new Logger('test');
@@ -327,8 +323,7 @@ public function testCustomerGetMyCart()
$config = $this->getClientConfig('manage_my_orders');
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$handler = new TestHandler();
$logger = new Logger('testOauth');
@@ -364,8 +359,7 @@ public function testCustomerNoAccess()
$config = $this->getClientConfig('manage_my_orders');
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$client = Client::ofConfigCacheAndLogger($config, $this->getCache(), $this->getLogger());
$client->getOauthManager()->getHttpClient(['verify' => $this->getVerifySSL()]);
@@ -394,8 +388,7 @@ public function testCustomerQuery()
$config = $this->getClientConfig('manage_my_orders');
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$client = Client::ofConfigCacheAndLogger($config, $this->getCache(), $this->getLogger());
$client->getOauthManager()->getHttpClient(['verify' => $this->getVerifySSL()]);
@@ -463,8 +456,7 @@ public function testCustomActiveCart()
$config = $this->getClientConfig('manage_my_orders');
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$handler = new TestHandler();
$logger = new Logger('testOauth');
@@ -532,8 +524,7 @@ public function testCustomerNoCart()
$config = $this->getClientConfig('manage_my_orders');
$config->setGrantType(Config::GRANT_TYPE_PASSWORD)
->setUsername($customer->getEmail())
- ->setPassword($customerDraft->getPassword())
- ;
+ ->setPassword($customerDraft->getPassword());
$handler = new TestHandler();
$logger = new Logger('testOauth');
diff --git a/tests/integration/Me/MeOrderRequestTest.php b/tests/integration/Me/MeOrderRequestTest.php
index a2d002cf19..75d882584f 100644
--- a/tests/integration/Me/MeOrderRequestTest.php
+++ b/tests/integration/Me/MeOrderRequestTest.php
@@ -12,6 +12,7 @@
use Commercetools\Core\Config;
use Commercetools\Core\Error\ResourceNotFoundError;
use Commercetools\Core\Model\Cart\CartDraft;
+use Commercetools\Core\Model\Cart\CartReference;
use Commercetools\Core\Model\Cart\LineItemDraft;
use Commercetools\Core\Model\Cart\LineItemDraftCollection;
use Commercetools\Core\Model\Cart\MyCartDraft;
@@ -102,7 +103,7 @@ protected function createOrder(CartDraft $draft)
$cart->getVersion()
);
- $orderRequest = OrderCreateFromCartRequest::ofCartIdAndVersion($cart->getId(), $cart->getVersion());
+ $orderRequest = OrderCreateFromCartRequest::ofCartAndVersion(CartReference::ofId($cart->getId()), $cart->getVersion());
$response = $orderRequest->executeWithClient($this->getClient());
$order = $orderRequest->mapResponse($response);
$this->cleanupRequests[] = $this->deleteRequest = OrderDeleteRequest::ofIdAndVersion(
diff --git a/tests/integration/Order/OrderQueryRequestTest.php b/tests/integration/Order/OrderQueryRequestTest.php
index 6ba1df1b46..9971661293 100644
--- a/tests/integration/Order/OrderQueryRequestTest.php
+++ b/tests/integration/Order/OrderQueryRequestTest.php
@@ -8,6 +8,7 @@
use Commercetools\Core\Builder\Request\RequestBuilder;
use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\Model\Cart\CartDraft;
+use Commercetools\Core\Model\Cart\CartReference;
use Commercetools\Core\Model\Cart\LineItemDraft;
use Commercetools\Core\Model\Cart\LineItemDraftCollection;
use Commercetools\Core\Model\Customer\Customer;
@@ -55,7 +56,7 @@ protected function createOrder(CartDraft $draft)
$response = $request->executeWithClient($this->getClient());
$cart = $request->mapResponse($response);
- $orderRequest = OrderCreateFromCartRequest::ofCartIdAndVersion($cart->getId(), $cart->getVersion());
+ $orderRequest = OrderCreateFromCartRequest::ofCartAndVersion(CartReference::ofId($cart->getId()), $cart->getVersion());
$response = $orderRequest->executeWithClient($this->getClient());
$order = $orderRequest->mapResponse($response);
$this->cleanupRequests[] = $this->deleteRequest = OrderDeleteRequest::ofIdAndVersion(
diff --git a/tests/integration/Order/OrderUpdateRequestTest.php b/tests/integration/Order/OrderUpdateRequestTest.php
index 16b1a29e09..d8ea5b2ad6 100644
--- a/tests/integration/Order/OrderUpdateRequestTest.php
+++ b/tests/integration/Order/OrderUpdateRequestTest.php
@@ -37,6 +37,8 @@
use Commercetools\Core\Model\Order\ParcelCollection;
use Commercetools\Core\Model\Order\ParcelMeasurements;
use Commercetools\Core\Model\Order\PaymentState;
+use Commercetools\Core\Model\Order\ReturnInfo;
+use Commercetools\Core\Model\Order\ReturnInfoCollection;
use Commercetools\Core\Model\Order\ReturnItem;
use Commercetools\Core\Model\Order\ReturnItemCollection;
use Commercetools\Core\Model\Order\ReturnPaymentState;
@@ -78,17 +80,20 @@
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressAction;
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressCustomFieldAction;
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressCustomTypeAction;
-use Commercetools\Core\Request\Orders\Command\StagedOrderSetDeliveryAddressCustomFieldAction;
-use Commercetools\Core\Request\Orders\Command\StagedOrderSetDeliveryAddressCustomTypeAction;
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryItemsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetItemShippingAddressCustomFieldAction;
use Commercetools\Core\Request\Orders\Command\OrderSetItemShippingAddressCustomTypeAction;
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemShippingDetailsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetLocaleAction;
use Commercetools\Core\Request\Orders\Command\OrderSetOrderNumberAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetParcelCustomFieldAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetParcelCustomTypeAction;
use Commercetools\Core\Request\Orders\Command\OrderSetParcelItemsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetParcelMeasurementsAction;
use Commercetools\Core\Request\Orders\Command\OrderSetParcelTrackingDataAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetReturnInfoAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetReturnItemCustomFieldAction;
+use Commercetools\Core\Request\Orders\Command\OrderSetReturnItemCustomTypeAction;
use Commercetools\Core\Request\Orders\Command\OrderSetReturnPaymentStateAction;
use Commercetools\Core\Request\Orders\Command\OrderSetReturnShipmentStateAction;
use Commercetools\Core\Request\Orders\Command\OrderSetShippingAddress;
@@ -1633,4 +1638,278 @@ function (Order $order) use ($client, $type) {
}
);
}
+
+ public function testSetReturnInfo()
+ {
+ $client = $this->getApiClient();
+
+ OrderFixture::withUpdateableOrder(
+ $client,
+ function (Order $order) use ($client) {
+ $lineItem = $order->getLineItems()->current();
+
+ $request = RequestBuilder::of()->orders()->update($order)
+ ->addAction(
+ OrderSetReturnInfoAction::of()->setItems(
+ ReturnInfoCollection::of()->add(
+ ReturnInfo::of()
+ ->setItems(ReturnItemCollection::of()->add(
+ ReturnItem::of()
+ ->setQuantity(1)
+ ->setLineItemId($lineItem->getId())
+ ->setShipmentState(ReturnShipmentState::RETURNED)
+ ))
+ ->setReturnTrackingId(OrderFixture::uniqueOrderString())
+ )
+ )
+ );
+
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertNotSame($order->getVersion(), $result->getVersion());
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame(
+ ReturnShipmentState::RETURNED,
+ $result->getReturnInfo()->current()->getItems()->current()->getShipmentState()
+ );
+ $returnItem = $result->getReturnInfo()->current()->getItems()->current();
+ $this->assertSame(
+ $lineItem->getId(),
+ $returnItem->getLineItemId()
+ );
+ $order = $result;
+ $request = RequestBuilder::of()->orders()->update($order)
+ ->addAction(
+ OrderSetReturnShipmentStateAction::ofReturnItemIdAndShipmentState(
+ $returnItem->getId(),
+ ReturnShipmentState::BACK_IN_STOCK
+ )
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $returnItem = $result->getReturnInfo()->current()->getItems()->current();
+ $this->assertNotSame($order->getVersion(), $result->getVersion());
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame(
+ ReturnShipmentState::BACK_IN_STOCK,
+ $returnItem->getShipmentState()
+ );
+ $order = $result;
+ $request = RequestBuilder::of()->orders()->update($order)
+ ->addAction(
+ OrderSetReturnPaymentStateAction::ofReturnItemIdAndPaymentState(
+ $returnItem->getId(),
+ ReturnPaymentState::REFUNDED
+ )
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $returnItem = $result->getReturnInfo()->current()->getItems()->current();
+ $this->assertNotSame($order->getVersion(), $result->getVersion());
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame(
+ ReturnPaymentState::REFUNDED,
+ $returnItem->getPaymentState()
+ );
+
+ return $result;
+ }
+ );
+ }
+
+ public function testSetReturnItemCustom()
+ {
+ $client = $this->getApiClient();
+
+ TypeFixture::withDraftType(
+ $client,
+ function (TypeDraft $typeDraft) {
+ return $typeDraft->setKey(TypeFixture::uniqueTypeString())
+ ->setResourceTypeIds(['order', 'order-return-item']);
+ },
+ function (Type $type) use ($client) {
+ OrderFixture::withUpdateableOrder(
+ $client,
+ function (Order $order) use ($client, $type) {
+ $this->assertInstanceOf(Order::class, $order);
+ $lineItemId = $order->getLineItems()->current()->getId();
+
+ $request = RequestBuilder::of()->orders()->update($order)
+ ->addAction(
+ OrderAddReturnInfoAction::of()->setItems(
+ ReturnItemCollection::of()->add(
+ ReturnItem::of()
+ ->setQuantity(1)
+ ->setLineItemId($lineItemId)
+ ->setShipmentState(ReturnShipmentState::RETURNED)
+ )
+ )
+ );
+ $response = $this->execute($client, $request);
+ $orderWithReturnedItem = $request->mapFromResponse($response);
+
+ $this->assertNotSame($order->getVersion(), $orderWithReturnedItem->getVersion());
+ $this->assertInstanceOf(Order::class, $orderWithReturnedItem);
+ $this->assertSame(
+ ReturnShipmentState::RETURNED,
+ $orderWithReturnedItem->getReturnInfo()->current()->getItems()->current()->getShipmentState()
+ );
+
+ $field = 'testField';
+ $newValue = 'new value';
+
+ $itemReturnedId = $orderWithReturnedItem->getReturnInfo()->current()->getItems()->current()->getId();
+
+ $request = RequestBuilder::of()->orders()->update($orderWithReturnedItem)
+ ->addAction(
+ OrderSetReturnItemCustomTypeAction::ofTypeKey($type->getKey())
+ ->setReturnItemId($itemReturnedId)
+ ->setFields(FieldContainer::of()
+ ->set($field, $newValue))
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame($newValue, $result->getReturnInfo()->current()->getItems()->current()->getCustom()->getFields()->getTestField());
+ $this->assertSame($itemReturnedId, $result->getReturnInfo()->current()->getItems()->current()->getId());
+
+ $newValue2 = 'new value 2';
+
+ $request = RequestBuilder::of()->orders()->update($result)
+ ->addAction(
+ OrderSetReturnItemCustomFieldAction::ofName($field)
+ ->setReturnItemId($itemReturnedId)
+ ->setValue('' . $newValue2 . '')
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame($newValue2, $result->getReturnInfo()->current()->getItems()->current()->getCustom()->getFields()->getTestField());
+ $this->assertSame($itemReturnedId, $result->getReturnInfo()->current()->getItems()->current()->getId());
+
+ return $result;
+ }
+ );
+ }
+ );
+ }
+
+
+ public function testSetParcelCustom()
+ {
+ $client = $this->getApiClient();
+
+ TypeFixture::withDraftType(
+ $client,
+ function (TypeDraft $typeDraft) {
+ return $typeDraft->setKey(TypeFixture::uniqueTypeString())
+ ->setResourceTypeIds(['order', 'order-parcel']);
+ },
+ function (Type $type) use ($client) {
+ OrderFixture::withUpdateableOrder(
+ $client,
+ function (Order $order) use ($client, $type) {
+ $this->assertInstanceOf(Order::class, $order);
+ $lineItem = $order->getLineItems()->current();
+
+ $request = RequestBuilder::of()->orders()->update($order)
+ ->addAction(
+ OrderAddDeliveryAction::ofDeliveryItems(
+ DeliveryItemCollection::of()->add(
+ DeliveryItem::of()->setId($lineItem->getId())->setQuantity(1)
+ )
+ )->setAddress(Address::of()->setCountry('DE'))
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertNotSame($order->getVersion(), $result->getVersion());
+ $this->assertInstanceOf(Order::class, $result);
+
+ $shippingInfo = $result->getShippingInfo();
+ $this->assertInstanceOf(ShippingInfo::class, $shippingInfo);
+
+ $delivery = $shippingInfo->getDeliveries()->current();
+ $this->assertSame($lineItem->getId(), $delivery->getItems()->current()->getId());
+ $order = $result;
+
+ $request = RequestBuilder::of()->orders()->update($order)
+ ->addAction(
+ OrderAddParcelToDeliveryAction::ofDeliveryId($delivery->getId())
+ ->setMeasurements(
+ ParcelMeasurements::of()
+ ->setHeightInMillimeter(100)
+ ->setLengthInMillimeter(100)
+ ->setWidthInMillimeter(100)
+ ->setWeightInGram(100)
+ )
+ ->setTrackingData(
+ TrackingData::of()
+ ->setTrackingId('123456')
+ ->setCarrier('DHL')
+ ->setProvider('Schenker')
+ ->setProviderTransaction('abcdef')
+ ->setIsReturn(false)
+ )
+ ->setItems(
+ DeliveryItemCollection::of()->add(
+ DeliveryItem::of()->setId($lineItem->getId())->setQuantity(3)
+ )
+ )
+ );
+ $response = $this->execute($client, $request);
+ $orderWithParcel = $request->mapFromResponse($response);
+
+ $this->assertNotSame($order->getVersion(), $orderWithParcel->getVersion());
+ $this->assertInstanceOf(Order::class, $orderWithParcel);
+ $delivery = $orderWithParcel->getShippingInfo()->getDeliveries()->current();
+ $this->assertSame('DE', $delivery->getAddress()->getCountry());
+ $this->assertSame(100, $delivery->getParcels()->current()->getMeasurements()->getHeightInMillimeter());
+ $this->assertSame('DHL', $delivery->getParcels()->current()->getTrackingData()->getCarrier());
+
+ $field = 'testField';
+ $newValue = 'new value';
+
+ $parcelId = $orderWithParcel->getShippingInfo()->getDeliveries()->current()->getParcels()->current()->getId();
+
+ $request = RequestBuilder::of()->orders()->update($orderWithParcel)
+ ->addAction(
+ OrderSetParcelCustomTypeAction::ofTypeKey($type->getKey())
+ ->setParcelId($parcelId)
+ ->setFields(FieldContainer::of()
+ ->set($field, $newValue))
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame($newValue, $result->getShippingInfo()->getDeliveries()->current()->getParcels()->current()->getCustom()->getFields()->getTestField());
+ $this->assertSame($parcelId, $result->getShippingInfo()->getDeliveries()->current()->getParcels()->current()->getId());
+
+ $newValue2 = 'new value 2';
+
+ $request = RequestBuilder::of()->orders()->update($result)
+ ->addAction(
+ OrderSetParcelCustomFieldAction::ofName($field)
+ ->setParcelId($parcelId)
+ ->setValue('' . $newValue2 . '')
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Order::class, $result);
+ $this->assertSame($newValue2, $result->getShippingInfo()->getDeliveries()->current()->getParcels()->current()->getCustom()->getFields()->getTestField());
+ $this->assertSame($parcelId, $result->getShippingInfo()->getDeliveries()->current()->getParcels()->current()->getId());
+
+ return $result;
+ }
+ );
+ }
+ );
+ }
}
diff --git a/tests/integration/OrderEdit/OrderEditUpdateRequestTest.php b/tests/integration/OrderEdit/OrderEditUpdateRequestTest.php
index ff0d633b3c..0b09267925 100644
--- a/tests/integration/OrderEdit/OrderEditUpdateRequestTest.php
+++ b/tests/integration/OrderEdit/OrderEditUpdateRequestTest.php
@@ -6,29 +6,39 @@
namespace Commercetools\Core\IntegrationTests\OrderEdit;
use Commercetools\Core\Builder\Request\RequestBuilder;
+use Commercetools\Core\IntegrationTests\Cart\CartFixture;
+use Commercetools\Core\IntegrationTests\Channel\ChannelFixture;
use Commercetools\Core\IntegrationTests\Order\OrderUpdateRequestTest;
+use Commercetools\Core\IntegrationTests\Product\ProductFixture;
use Commercetools\Core\IntegrationTests\Type\TypeFixture;
use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Core\Model\Cart\ExternalTaxAmountDraft;
use Commercetools\Core\Model\Cart\ScoreShippingRateInput;
+use Commercetools\Core\Model\Channel\Channel;
+use Commercetools\Core\Model\Channel\ChannelDraft;
use Commercetools\Core\Model\Common\Address;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
+use Commercetools\Core\Model\Message\OrderLineItemDistributionChannelSetMessage;
use Commercetools\Core\Model\Order\Order;
use Commercetools\Core\Model\OrderEdit\OrderEdit;
use Commercetools\Core\Model\OrderEdit\OrderEditApplied;
use Commercetools\Core\Model\OrderEdit\OrderEditDraft;
use Commercetools\Core\Model\OrderEdit\OrderEditPreviewSuccess;
+use Commercetools\Core\Model\Product\Product;
use Commercetools\Core\Model\ShippingMethod\ShippingRateDraft;
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
use Commercetools\Core\Model\Type\Type;
use Commercetools\Core\Model\Type\TypeReference;
+use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction;
+use Commercetools\Core\Request\Messages\MessageQueryRequest;
use Commercetools\Core\Request\OrderEdits\Command\OrderEditSetCommentAction;
use Commercetools\Core\Request\OrderEdits\Command\OrderEditSetCustomFieldAction;
use Commercetools\Core\Request\OrderEdits\Command\OrderEditSetCustomTypeAction;
use Commercetools\Core\Request\OrderEdits\Command\OrderEditSetKeyAction;
use Commercetools\Core\Request\OrderEdits\Command\OrderEditSetStagedActionsAction;
+use Commercetools\Core\Request\OrderEdits\OrderEditUpdateRequest;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddCustomLineItemAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddDiscountCodeAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddItemShippingAddressAction;
@@ -66,6 +76,7 @@
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetItemShippingAddressCustomTypeAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemCustomFieldAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemCustomTypeAction;
+use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemDistributionChannelAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemPriceAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemShippingDetailsAction;
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemTaxAmountAction;
@@ -378,7 +389,9 @@ public function stagedActionsProvider()
StagedOrderSetLineItemPriceAction::class => [function () {
return StagedOrderSetLineItemPriceAction::of()->setLineItemId($this->getProduct()->getId());
}],
-
+ StagedOrderSetLineItemDistributionChannelAction::class => [function () {
+ return StagedOrderSetLineItemDistributionChannelAction::of()->setLineItemId($this->getProduct()->getId());
+ }],
//custom line items
StagedOrderAddCustomLineItemAction::class => [function () {
return StagedOrderAddCustomLineItemAction::of()
@@ -553,4 +566,64 @@ function (OrderEdit $orderEdit, Order $order) use ($client) {
}
);
}
+
+ public function testSetLineItemDistributionChannel()
+ {
+ $client = $this->getApiClient();
+
+ ChannelFixture::withDraftChannel(
+ $client,
+ function (ChannelDraft $channelDraft) {
+ return $channelDraft->setRoles(['ProductDistribution']);
+ },
+ function (Channel $channel) use ($client) {
+ OrderEditFixture::withUpdateableOrderEdit(
+ $client,
+ function (OrderEdit $orderEdit, Order $order) use ($client, $channel) {
+ $lineItemId = $order->getLineItems()->current()->getId();
+
+ $request = RequestBuilder::of()->orderEdits()->update($orderEdit)->setActions([
+ OrderEditSetStagedActionsAction::of()->setStagedActions(
+ StagedOrderUpdateActionCollection::of()
+ ->add(StagedOrderSetLineItemDistributionChannelAction::of()
+ ->setLineItemId($lineItemId)->setDistributionChannel($channel->getReference()))
+ )
+ ]);
+ $response = $client->execute($request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertNotSame($orderEdit->getVersion(), $result->getVersion());
+ $this->assertInstanceOf(OrderEdit::class, $result);
+
+ $request = RequestBuilder::of()->orderEdits()->apply($result, $order->getVersion());
+ $response = $client->execute($request);
+ $orderEditApplied = $request->mapFromResponse($response);
+
+ // test for OrderLineItemDistributionChannelSetMessage
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "OrderLineItemDistributionChannelSet"')
+ ->where('resource(id = "' . $order->getId() . '")');
+ $response = $this->execute($client, $request);
+ $messageResult = $request->mapFromResponse($response);
+ } while (is_null($orderEdit) && $retries <= 9);
+
+ /**
+ * @var OrderLineItemDistributionChannelSetMessage $message
+ */
+ $message = $messageResult->current();
+
+ $this->assertInstanceOf(OrderLineItemDistributionChannelSetMessage::class, $message);
+ $this->assertSame($order->getId(), $message->getResource()->getId());
+ $this->assertSame($order->getLineItems()->current()->getId(), $message->getLineItemId());
+
+ return $orderEditApplied;
+ }
+ );
+ }
+ );
+ }
}
diff --git a/tests/integration/Payment/PaymentUpdateRequestTest.php b/tests/integration/Payment/PaymentUpdateRequestTest.php
index be169e0705..f3b62c3f0b 100644
--- a/tests/integration/Payment/PaymentUpdateRequestTest.php
+++ b/tests/integration/Payment/PaymentUpdateRequestTest.php
@@ -7,6 +7,7 @@
namespace Commercetools\Core\IntegrationTests\Payment;
use Commercetools\Core\Builder\Request\RequestBuilder;
+use Commercetools\Core\Helper\Uuid;
use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\IntegrationTests\Customer\CustomerFixture;
use Commercetools\Core\IntegrationTests\State\StateFixture;
@@ -14,6 +15,8 @@
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Customer\Customer;
+use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
+use Commercetools\Core\Model\CustomField\FieldContainer;
use Commercetools\Core\Model\Payment\Payment;
use Commercetools\Core\Model\Payment\PaymentDraft;
use Commercetools\Core\Model\Payment\Transaction;
@@ -43,6 +46,8 @@
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceCodeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceTextAction;
+use Commercetools\Core\Request\Payments\Command\PaymentSetTransactionCustomFieldAction;
+use Commercetools\Core\Request\Payments\Command\PaymentSetTransactionCustomTypeAction;
use Commercetools\Core\Request\Payments\Command\PaymentTransitionStateAction;
use Commercetools\Core\Request\Payments\PaymentUpdateRequest;
@@ -682,4 +687,82 @@ function (Payment $payment) use ($client, $type) {
}
);
}
+
+
+ public function testPaymentTransactionCustomField()
+ {
+ $client = $this->getApiClient();
+
+ TypeFixture::withDraftType(
+ $client,
+ function (TypeDraft $typeDraft) {
+ return $typeDraft->setKey('key-' . TypeFixture::uniqueTypeString())
+ ->setResourceTypeIds(['payment', 'transaction']);
+ },
+ function (Type $type) use ($client) {
+ PaymentFixture::withUpdateablePayment(
+ $client,
+ function (Payment $payment) use ($client, $type) {
+ $id = Uuid::uuidv4();
+ $transaction = Transaction::of()
+ ->setId($id)
+ ->setType(Transaction::AUTHORIZATION)
+ ->setAmount(Money::ofCurrencyAndAmount('EUR', 100))
+ ->setCustom(
+ CustomFieldObjectDraft::ofTypeKey($type->getKey())
+ ->setFields(FieldContainer::of()->set('testField', 'value'))
+ )
+ ->setInteractionId($id)
+ ->setState(TransactionState::SUCCESS);
+
+ $request = RequestBuilder::of()->payments()->update($payment)
+ ->addAction(
+ PaymentAddTransactionAction::of()->setTransaction($transaction)
+ );
+ $response = $this->execute($client, $request);
+ $paymentWithTransaction = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Payment::class, $paymentWithTransaction);
+ $this->assertSame(
+ $transaction->getInteractionId(),
+ $paymentWithTransaction->getTransactions()->current()->getInteractionId()
+ );
+ $this->assertNotSame($payment->getVersion(), $paymentWithTransaction->getVersion());
+
+ $request = RequestBuilder::of()->payments()->update($paymentWithTransaction)
+ ->addAction(
+ PaymentSetTransactionCustomTypeAction::ofTypeKey($type->getKey())
+ ->setTransactionId($paymentWithTransaction->getTransactions()->current()->getId())
+ );
+ $response = $this->execute($client, $request);
+ $resultTransactionCustomType = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Payment::class, $resultTransactionCustomType);
+ $this->assertSame(
+ $transaction->getInteractionId(),
+ $resultTransactionCustomType->getTransactions()->current()->getInteractionId()
+ );
+
+ $name = 'testField';
+
+ $request = RequestBuilder::of()->payments()->update($resultTransactionCustomType)
+ ->addAction(
+ PaymentSetTransactionCustomFieldAction::ofTransactionIdAndName($resultTransactionCustomType->getTransactions()->current()->getId(), $name)
+ ->setValue('testValue')
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Payment::class, $result);
+ $this->assertSame(
+ $transaction->getInteractionId(),
+ $result->getTransactions()->current()->getInteractionId()
+ );
+
+ return $result;
+ }
+ );
+ }
+ );
+ }
}
diff --git a/tests/integration/Product/ProductHeadRequestTest.php b/tests/integration/Product/ProductHeadRequestTest.php
new file mode 100644
index 0000000000..710709d4d2
--- /dev/null
+++ b/tests/integration/Product/ProductHeadRequestTest.php
@@ -0,0 +1,102 @@
+getApiClient();
+ ProductFixture::withProduct(
+ $client,
+ function (Product $product) use ($client) {
+ $request = RequestBuilder::of()->products()->head();
+ $response = $this->execute($client, $request);
+
+ $this->assertSame(200, $response->getStatusCode());
+ }
+ );
+ }
+
+ public function testProductByIdExists()
+ {
+ $client = $this->getApiClient();
+
+ ProductFixture::withProduct(
+ $client,
+ function (Product $product) use ($client) {
+ $request = RequestBuilder::of()->products()->getByIdHead($product->getId());
+ $response = $this->execute($client, $request);
+
+ $this->assertSame(200, $response->getStatusCode());
+ }
+ );
+ }
+
+ public function testProductByIdDoesNotExists()
+ {
+ $this->expectExceptionCode(404);
+ $client = $this->getApiClient();
+
+ $request = RequestBuilder::of()->products()->getByIdHead("test-id");
+ $this->execute($client, $request);
+ }
+
+ public function testProductByKeyExists()
+ {
+ $client = $this->getApiClient();
+
+ ProductFixture::withDraftProduct(
+ $client,
+ function (ProductDraft $draft) {
+ return $draft->setKey(ProductFixture::uniqueProductString());
+ },
+ function (Product $product) use ($client) {
+ $request = RequestBuilder::of()->products()->getByKeyHead($product->getKey());
+ $response = $this->execute($client, $request);
+
+ $this->assertSame(200, $response->getStatusCode());
+ }
+ );
+ }
+
+ public function testProductByKeyDoesNotExists()
+ {
+ $this->expectExceptionCode(404);
+ $client = $this->getApiClient();
+
+ $request = RequestBuilder::of()->products()->getByKeyHead("test-key");
+ $this->execute($client, $request);
+ }
+
+ public function testProductByQueryPredicateExists()
+ {
+ $client = $this->getApiClient();
+
+ ProductFixture::withProduct(
+ $client,
+ function (Product $product) use ($client) {
+ $request = RequestBuilder::of()->products()->head()
+ ->where('id=:id', ['id' => $product->getId()]);
+ $response = $this->execute($client, $request);
+
+ $this->assertSame(200, $response->getStatusCode());
+ }
+ );
+ }
+
+ public function testProductByQueryPredicateDoesNotExists()
+ {
+ $this->expectExceptionCode(404);
+ $client = $this->getApiClient();
+
+ $request = RequestBuilder::of()->products()->head()
+ ->where('id=:id', ['id' => "88f6556a-239f-46c9-9fec-b9535f60272b"]);
+ $this->execute($client, $request);
+ }
+}
diff --git a/tests/integration/Product/ProductUpdateRequestTest.php b/tests/integration/Product/ProductUpdateRequestTest.php
index 102828a71a..c6c777da76 100644
--- a/tests/integration/Product/ProductUpdateRequestTest.php
+++ b/tests/integration/Product/ProductUpdateRequestTest.php
@@ -31,6 +31,9 @@
use Commercetools\Core\Model\Common\Money;
use Commercetools\Core\Model\Common\PriceDraft;
use Commercetools\Core\Model\Common\PriceDraftCollection;
+use Commercetools\Core\Model\Message\ProductSlugChangedMessage;
+use Commercetools\Core\Model\Message\ProductVariantAddedMessage;
+use Commercetools\Core\Model\Message\ProductVariantDeletedMessage;
use Commercetools\Core\Model\Product\LocalizedSearchKeywords;
use Commercetools\Core\Model\Product\Product;
use Commercetools\Core\Model\Product\ProductDraft;
@@ -45,6 +48,7 @@
use Commercetools\Core\Model\TaxCategory\TaxCategory;
use Commercetools\Core\Model\Type\Type;
use Commercetools\Core\Model\Type\TypeDraft;
+use Commercetools\Core\Request\Messages\MessageQueryRequest;
use Commercetools\Core\Request\Products\Command\ProductAddAssetAction;
use Commercetools\Core\Request\Products\Command\ProductAddExternalImageAction;
use Commercetools\Core\Request\Products\Command\ProductAddPriceAction;
@@ -227,14 +231,35 @@ function (Product $product) use ($client) {
)
);
$response = $this->execute($client, $request);
- $result = $request->mapFromResponse($response);
-
- $this->assertInstanceOf(Product::class, $result);
- $this->assertNotSame($slug, $result->getMasterData()->getCurrent()->getSlug()->en);
- $this->assertSame($slug, $result->getMasterData()->getStaged()->getSlug()->en);
- $this->assertNotSame($product->getVersion(), $result->getVersion());
-
- return $result;
+ $productUpdated = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Product::class, $productUpdated);
+ $this->assertNotSame($slug, $productUpdated->getMasterData()->getCurrent()->getSlug()->en);
+ $this->assertSame($slug, $productUpdated->getMasterData()->getStaged()->getSlug()->en);
+ $this->assertNotSame($product->getVersion(), $productUpdated->getVersion());
+
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "ProductSlugChanged"')
+ ->where('resource(id = "' . $productUpdated->getId() . '")');
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var ProductSlugChangedMessage $message
+ */
+ $message = $result->current();
+
+ $this->assertInstanceOf(ProductSlugChangedMessage::class, $message);
+ $this->assertSame($productUpdated->getId(), $message->getResource()->getId());
+ $this->assertSame($productUpdated->getMasterData()->getCurrent()->getSlug()->en, $message->getOldSlug()->en);
+ $this->assertSame($productUpdated->getMasterData()->getStaged()->getSlug()->en, $message->getSlug()->en);
+
+ return $productUpdated;
}
);
}
@@ -261,6 +286,27 @@ function (Product $product) use ($client) {
$this->assertSame($sku, $result->getMasterData()->getStaged()->getVariants()->current()->getKey());
$this->assertNotSame($product->getVersion(), $result->getVersion());
+ // test for ProductVariantAddedMessage
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "ProductVariantAdded"')
+ ->where('resource(id = "' . $result->getId() . '")');
+ $response = $this->execute($client, $request);
+ $messageResult = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var ProductVariantAddedMessage $message
+ */
+ $message = $messageResult->current();
+
+ $this->assertInstanceOf(ProductVariantAddedMessage::class, $message);
+ $this->assertSame($result->getId(), $message->getResource()->getId());
+ $this->assertSame($result->getMasterData()->getStaged()->getVariants()->current()->getKey(), $message->getVariant()->getKey());
+
$product = $result;
$request = RequestBuilder::of()->products()->update($product)
@@ -277,6 +323,27 @@ function (Product $product) use ($client) {
$this->assertEmpty($result->getMasterData()->getStaged()->getVariants());
$this->assertNotSame($product->getVersion(), $result->getVersion());
+ // test for ProductVariantDeletedMessage
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "ProductVariantDeleted"')
+ ->where('resource(id = "' . $result->getId() . '")');
+ $response = $this->execute($client, $request);
+ $messageResult = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var ProductVariantDeletedMessage $message
+ */
+ $message = $messageResult->current();
+
+ $this->assertInstanceOf(ProductVariantDeletedMessage::class, $message);
+ $this->assertSame($result->getId(), $message->getResource()->getId());
+ $this->assertEmpty($result->getMasterData()->getStaged()->getMasterVariant()->getKey());
+
return $result;
}
);
@@ -1925,15 +1992,15 @@ function (Product $product) use ($client, $productDiscount) {
CartFixture::withDraftCart(
$client,
function (CartDraft $cartDraft) use ($productResult, $variantResult) {
- return $cartDraft->setLineItems(
- LineItemDraftCollection::of()->add(
- LineItemDraft::ofProductIdVariantIdAndQuantity(
- $productResult->getId(),
- $variantResult->getId(),
- 1
- )
- )
- );
+ return $cartDraft->setLineItems(
+ LineItemDraftCollection::of()->add(
+ LineItemDraft::ofProductIdVariantIdAndQuantity(
+ $productResult->getId(),
+ $variantResult->getId(),
+ 1
+ )
+ )
+ );
},
function (Cart $cart) use ($client) {
$this->assertSame(900, $cart->getTotalPrice()->getCentAmount());
diff --git a/tests/integration/Project/ProjectFixture.php b/tests/integration/Project/ProjectFixture.php
index 66b5a76034..e6c02d5cb0 100644
--- a/tests/integration/Project/ProjectFixture.php
+++ b/tests/integration/Project/ProjectFixture.php
@@ -14,6 +14,7 @@
use Commercetools\Core\Request\Project\Command\ProjectChangeCurrenciesAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeLanguagesAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
+use Commercetools\Core\Request\Project\Command\ProjectChangeProductSearchIndexingEnabledAction;
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
use Commercetools\Core\Request\Project\ProjectGetRequest;
use Commercetools\Core\Request\Project\ProjectUpdateRequest;
@@ -60,6 +61,10 @@ final public static function setupProject(ApiClient $client)
$request->addAction(ProjectChangeCountryTaxRateFallbackEnabledAction::ofCountryTaxRateFallbackEnabled(false));
}
+ if ($project->getSearchIndexing() === null) {
+ $request->addAction(ProjectChangeProductSearchIndexingEnabledAction::ofEnabled(true));
+ }
+
if ($request->hasActions()) {
$response = $client->execute($request);
$project = $request->mapFromResponse($response);
diff --git a/tests/integration/Project/ProjectGetRequestTest.php b/tests/integration/Project/ProjectGetRequestTest.php
index 714615d480..ab05354f05 100644
--- a/tests/integration/Project/ProjectGetRequestTest.php
+++ b/tests/integration/Project/ProjectGetRequestTest.php
@@ -8,6 +8,7 @@
use Commercetools\Core\Builder\Request\RequestBuilder;
use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\Model\Project\Project;
+use Commercetools\Core\Request\Project\Command\ProjectChangeLanguagesAction;
class ProjectGetRequestTest extends ApiTestCase
{
diff --git a/tests/integration/Project/ProjectUpdateRequestTest.php b/tests/integration/Project/ProjectUpdateRequestTest.php
index 9059a09cd1..19cfa96473 100644
--- a/tests/integration/Project/ProjectUpdateRequestTest.php
+++ b/tests/integration/Project/ProjectUpdateRequestTest.php
@@ -13,11 +13,11 @@
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\Message\MessagesConfigurationDraft;
use Commercetools\Core\Model\Project\CartClassificationType;
-use Commercetools\Core\Model\Project\CartsConfiguration;
use Commercetools\Core\Model\Project\CartScoreType;
use Commercetools\Core\Model\Project\CartValueType;
use Commercetools\Core\Model\Project\ExternalOAuth;
use Commercetools\Core\Model\Project\Project;
+use Commercetools\Core\Model\Project\ShoppingListsConfiguration;
use Commercetools\Core\Request\Project\Command\ProjectChangeCountriesAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeCountryTaxRateFallbackEnabledAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeCurrenciesAction;
@@ -25,6 +25,8 @@
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction;
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction;
+use Commercetools\Core\Request\Project\Command\ProjectChangeProductSearchIndexingEnabledAction;
+use Commercetools\Core\Request\Project\Command\ProjectChangeShoppingListsConfigurationAction;
use Commercetools\Core\Request\Project\Command\ProjectSetExternalOAuthAction;
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
@@ -428,6 +430,75 @@ function (ProjectSetExternalOAuthAction $action) {
$this->assertNull($result->getExternalOAuth());
+ return $result;
+ }
+ );
+ }
+ public function testChangeShoppingListsConfiguration()
+ {
+ $client = $this->getApiClient();
+
+ ProjectFixture::withProject(
+ $client,
+ function (Project $project) use ($client) {
+ $deleteDaysAfterLastModification = $project->getShoppingLists()->getDeleteDaysAfterLastModification();
+ $shoppingListsConfiguration = ShoppingListsConfiguration::of()->setDeleteDaysAfterLastModification($deleteDaysAfterLastModification);
+
+ $request = RequestBuilder::of()->project()->update($project)
+ ->addAction(
+ ProjectChangeShoppingListsConfigurationAction::ofShoppingListsConfiguration($shoppingListsConfiguration)
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Project::class, $result);
+ $this->assertSame($deleteDaysAfterLastModification, $result->getShoppingLists()->getDeleteDaysAfterLastModification());
+
+ $shoppingListsConfiguration = ShoppingListsConfiguration::of()->setDeleteDaysAfterLastModification(42);
+
+ $request = RequestBuilder::of()->project()->update($result)
+ ->addAction(
+ ProjectChangeShoppingListsConfigurationAction::ofShoppingListsConfiguration($shoppingListsConfiguration)
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Project::class, $result);
+ $this->assertSame(42, $result->getShoppingLists()->getDeleteDaysAfterLastModification());
+
+ return $result;
+ }
+ );
+ }
+
+ public function testChangeProductSearchIndexingEnabled()
+ {
+ self::markTestSkipped();
+ $client = $this->getApiClient();
+
+ ProjectFixture::withProject(
+ $client,
+ function (Project $project) use ($client) {
+ $status = $project->getSearchIndexing()->getProducts()->getStatus();
+ if ($status === "Deactivated") {
+ $enabled = false;
+ } elseif ($status === "Activated") {
+ $enabled = true;
+ } else {
+ $this->assertSame("Indexing", $status);
+
+ return $project;
+ }
+ $request = RequestBuilder::of()->project()->update($project)
+ ->addAction(
+ ProjectChangeProductSearchIndexingEnabledAction::ofEnabled(!$enabled)
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Project::class, $result);
+ $this->assertNotSame($status, $result->getSearchIndexing()->getProducts()->getStatus());
+
return $result;
}
);
diff --git a/tests/integration/ShippingMethod/ShippingMethodUpdateRequestTest.php b/tests/integration/ShippingMethod/ShippingMethodUpdateRequestTest.php
index 2998a27f47..6c371bf3bc 100644
--- a/tests/integration/ShippingMethod/ShippingMethodUpdateRequestTest.php
+++ b/tests/integration/ShippingMethod/ShippingMethodUpdateRequestTest.php
@@ -40,6 +40,7 @@
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetDescriptionAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetKeyAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetLocalizedDescriptionAction;
+use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetLocalizedNameAction;
use Commercetools\Core\Request\ShippingMethods\Command\ShippingMethodSetPredicateAction;
class ShippingMethodUpdateRequestTest extends ApiTestCase
@@ -574,4 +575,31 @@ function (ShippingMethod $shippingMethod) use ($client) {
}
);
}
+
+
+ public function testSetLocalizedName()
+ {
+ $client = $this->getApiClient();
+
+ ShippingMethodFixture::withUpdateableShippingMethod(
+ $client,
+ function (ShippingMethod $shippingMethod) use ($client) {
+ $localizedName = LocalizedString::ofLangAndText('en', 'localized-name');
+
+ $request = RequestBuilder::of()->shippingMethods()->update($shippingMethod)
+ ->addAction(
+ ShippingMethodSetLocalizedNameAction::of()
+ ->setLocalizedName($localizedName)
+ );
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(ShippingMethod::class, $result);
+ $this->assertSame($localizedName->en, $result->getLocalizedName()->en);
+ $this->assertNotSame($shippingMethod->getVersion(), $result->getVersion());
+
+ return $result;
+ }
+ );
+ }
}
diff --git a/tests/integration/Store/StoreDeleteRequestTest.php b/tests/integration/Store/StoreDeleteRequestTest.php
index 8e5797352e..00c4151669 100644
--- a/tests/integration/Store/StoreDeleteRequestTest.php
+++ b/tests/integration/Store/StoreDeleteRequestTest.php
@@ -5,7 +5,11 @@
use Commercetools\Core\Builder\Request\RequestBuilder;
use Commercetools\Core\Fixtures\FixtureException;
use Commercetools\Core\IntegrationTests\ApiTestCase;
+use Commercetools\Core\Model\Message\StoreCreatedMessage;
+use Commercetools\Core\Model\Message\StoreDeletedMessage;
use Commercetools\Core\Model\Store\Store;
+use Commercetools\Core\Model\Store\StoreDraft;
+use Commercetools\Core\Request\Messages\MessageQueryRequest;
class StoreDeleteRequestTest extends ApiTestCase
{
@@ -32,4 +36,68 @@ function (Store $store) use ($client) {
}
);
}
+
+ public function testStoreCreatedMessage()
+ {
+ $client = $this->getApiClient();
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client) {
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "StoreCreated"')
+ ->where('resource(id = "' . $store->getId() . '")');
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var StoreCreatedMessage $message
+ */
+ $message = $result->current();
+
+ $this->assertInstanceOf(StoreCreatedMessage::class, $message);
+ $this->assertSame($store->getId(), $message->getResource()->getId());
+ }
+ );
+ }
+
+ public function testStoreDeletedMessage()
+ {
+ $client = $this->getApiClient();
+
+ StoreFixture::withStore(
+ $client,
+ function (Store $store) use ($client) {
+ $request = RequestBuilder::of()->stores()->delete($store);
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+
+ $this->assertInstanceOf(Store::class, $result);
+
+ $retries = 0;
+ do {
+ $retries++;
+ sleep(1);
+ $request = MessageQueryRequest::of()
+ ->where('type = "StoreDeleted"')
+ ->where('resource(id = "' . $store->getId() . '")');
+ $response = $this->execute($client, $request);
+ $result = $request->mapFromResponse($response);
+ } while (is_null($result) && $retries <= 9);
+
+ /**
+ * @var StoreDeletedMessage $message
+ */
+ $message = $result->current();
+
+ $this->assertInstanceOf(StoreDeletedMessage::class, $message);
+ $this->assertSame($store->getId(), $message->getResource()->getId());
+ }
+ );
+ }
}
diff --git a/tests/unit/Builder/Update/GenericActionBuilderTest.php b/tests/unit/Builder/Update/GenericActionBuilderTest.php
index 33a07b1f73..3d25d7d659 100644
--- a/tests/unit/Builder/Update/GenericActionBuilderTest.php
+++ b/tests/unit/Builder/Update/GenericActionBuilderTest.php
@@ -33,7 +33,7 @@ public function getActionClasses()
$actions = [];
foreach ($phpFiles as $phpFile) {
$class = $this->getClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
diff --git a/tests/unit/Model/RamlModelTest.php b/tests/unit/Model/RamlModelTest.php
index 8ada141620..4e7e7aa0f1 100644
--- a/tests/unit/Model/RamlModelTest.php
+++ b/tests/unit/Model/RamlModelTest.php
@@ -243,6 +243,9 @@ protected function getCommandClass($domain, $model)
case 'Inventory':
$model = str_replace('InventoryEntry', 'Inventory', $model);
break;
+ case 'Me':
+ $model = str_replace('Me', 'My', $model);
+ break;
case 'OrderEdit':
$domain .= 's';
if (strpos($model, 'StagedOrder') === 0) {
@@ -473,7 +476,7 @@ public function getModelClasses($searchPath)
$modelClasses = [];
foreach ($phpFiles as $phpFile) {
$class = $this->getFileClassName($phpFile->getRealPath());
- if (strpos($class, 'Core\\Helper') > 0) {
+ if ($class != null && strpos($class, 'Core\\Helper') > 0) {
continue;
}
@@ -635,6 +638,7 @@ private function ramlToModelMap()
'Extension\ExtensionAzureFunctionsAuthentication' => 'Extension\AzureFunctionsAuthentication',
'Extension\ExtensionAuthorizationHeaderAuthentication' => 'Extension\AuthorizationHeaderAuthentication',
'Extension\ExtensionTrigger' => 'Extension\Trigger',
+ 'Message\ContainerAndKey' => 'Common\ContainerAndKey',
];
}
diff --git a/tests/unit/Request/AbstractByIdHeadRequestTest.php b/tests/unit/Request/AbstractByIdHeadRequestTest.php
new file mode 100644
index 0000000000..95a1b15d3f
--- /dev/null
+++ b/tests/unit/Request/AbstractByIdHeadRequestTest.php
@@ -0,0 +1,62 @@
+getRequest(static::ABSTRACT_HEAD_REQUEST, ['']);
+ $request->setId('id');
+ $this->assertSame('id', $request->getId());
+ }
+
+ public function testHttpRequestMethod()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['id']);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame(HttpMethod::HEAD, $httpRequest->getMethod());
+ }
+
+ public function testHttpRequestPath()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['id']);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame('test/id', (string)$httpRequest->getUri());
+ }
+
+ public function testHttpRequestObject()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['id']);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertEmpty((string)$httpRequest->getBody());
+ }
+
+ public function testBuildResponse()
+ {
+ $mockBuilder = $this->getMockBuilder('\GuzzleHttp\Psr7\Response');
+ $mockBuilder->disableOriginalConstructor();
+ $guzzleResponse = $mockBuilder->getMock();
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['id']);
+ $response = $request->buildResponse($guzzleResponse);
+
+ $this->assertInstanceOf(ResourceResponse::class, $response);
+ }
+}
diff --git a/tests/unit/Request/AbstractByKeyHeadRequestTest.php b/tests/unit/Request/AbstractByKeyHeadRequestTest.php
new file mode 100644
index 0000000000..4e43bef4d2
--- /dev/null
+++ b/tests/unit/Request/AbstractByKeyHeadRequestTest.php
@@ -0,0 +1,62 @@
+getRequest(static::ABSTRACT_HEAD_REQUEST, ['']);
+ $request->setKey('key');
+ $this->assertSame('key', $request->getKey());
+ }
+
+ public function testHttpRequestMethod()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['key']);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame(HttpMethod::HEAD, $httpRequest->getMethod());
+ }
+
+ public function testHttpRequestPath()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['key']);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame('test/key=key', (string)$httpRequest->getUri());
+ }
+
+ public function testHttpRequestObject()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['key']);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertEmpty((string)$httpRequest->getBody());
+ }
+
+ public function testBuildResponse()
+ {
+ $mockBuilder = $this->getMockBuilder('\GuzzleHttp\Psr7\Response');
+ $mockBuilder->disableOriginalConstructor();
+ $guzzleResponse = $mockBuilder->getMock();
+
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST, ['key']);
+ $response = $request->buildResponse($guzzleResponse);
+
+ $this->assertInstanceOf(ResourceResponse::class, $response);
+ }
+}
diff --git a/tests/unit/Request/AbstractHeadRequestTest.php b/tests/unit/Request/AbstractHeadRequestTest.php
new file mode 100644
index 0000000000..8e919c1a46
--- /dev/null
+++ b/tests/unit/Request/AbstractHeadRequestTest.php
@@ -0,0 +1,64 @@
+getRequest(static::ABSTRACT_HEAD_REQUEST);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame(HttpMethod::HEAD, $httpRequest->getMethod());
+ }
+
+ public function testHttpRequestPath()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame('test', (string)$httpRequest->getUri());
+ }
+
+ public function testHttpRequestObject()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST);
+ $httpRequest = $request->httpRequest();
+
+ $this->assertEmpty((string)$httpRequest->getBody());
+ }
+
+ public function testBuildResponse()
+ {
+ $mockBuilder = $this->getMockBuilder('\GuzzleHttp\Psr7\Response');
+ $mockBuilder->disableOriginalConstructor();
+ $guzzleResponse = $mockBuilder->getMock();
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST);
+ $response = $request->buildResponse($guzzleResponse);
+
+ $this->assertInstanceOf(ResourceResponse::class, $response);
+ }
+
+ public function testWhere()
+ {
+ $request = $this->getRequest(static::ABSTRACT_HEAD_REQUEST);
+ $request->where('test');
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame('test?where=test', (string)$httpRequest->getUri());
+ }
+}
diff --git a/tests/unit/Request/Customers/CustomerLoginRequestTest.php b/tests/unit/Request/Customers/CustomerLoginRequestTest.php
index cacf27ce1b..ee8b962c7a 100644
--- a/tests/unit/Request/Customers/CustomerLoginRequestTest.php
+++ b/tests/unit/Request/Customers/CustomerLoginRequestTest.php
@@ -59,7 +59,7 @@ public function testHttpRequestObjectWithCart()
$httpRequest = $request->httpRequest();
$this->assertJsonStringEqualsJsonString(
- json_encode(['email' => 'email', 'password' => 'password', 'anonymousCartId' => 'cartId']),
+ json_encode(["email" => "email","password" => "password","anonymousCart" => ["typeId" => "cart","id" => "cartId"]]),
(string)$httpRequest->getBody()
);
}
diff --git a/tests/unit/Request/GenericActionTest.php b/tests/unit/Request/GenericActionTest.php
index 2704acaeb1..bd9eb89657 100644
--- a/tests/unit/Request/GenericActionTest.php
+++ b/tests/unit/Request/GenericActionTest.php
@@ -118,6 +118,7 @@
use Commercetools\Core\Request\Inventory\Command\InventorySetExpectedDeliveryAction;
use Commercetools\Core\Request\Inventory\Command\InventorySetRestockableInDaysAction;
use Commercetools\Core\Request\Inventory\Command\InventorySetSupplyChannelAction;
+use Commercetools\Core\Request\Me\Command\MyCartAddLineItemAction;
use Commercetools\Core\Request\Orders\Command\OrderAddDeliveryAction;
use Commercetools\Core\Request\Orders\Command\OrderAddParcelToDeliveryAction;
use Commercetools\Core\Request\Orders\Command\OrderAddReturnInfoAction;
@@ -151,6 +152,8 @@
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceCodeAction;
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceTextAction;
+use Commercetools\Core\Request\Payments\Command\PaymentSetTransactionCustomFieldAction;
+use Commercetools\Core\Request\Payments\Command\PaymentSetTransactionCustomTypeAction;
use Commercetools\Core\Request\Payments\Command\PaymentTransitionStateAction;
use Commercetools\Core\Request\ProductDiscounts\Command\ProductDiscountChangeIsActiveAction;
use Commercetools\Core\Request\ProductDiscounts\Command\ProductDiscountChangeNameAction;
@@ -203,8 +206,6 @@
use Commercetools\Core\Request\Reviews\Command\ReviewSetAuthorNameAction;
use Commercetools\Core\Request\Reviews\Command\ReviewSetCustomerAction;
use Commercetools\Core\Request\Reviews\Command\ReviewSetKeyAction;
-use Commercetools\Core\Request\Reviews\Command\ReviewSetLocaleAction;
-use Commercetools\Core\Request\Reviews\Command\ReviewSetRatingAction;
use Commercetools\Core\Request\Reviews\Command\ReviewSetTargetAction;
use Commercetools\Core\Request\Reviews\Command\ReviewSetTextAction;
use Commercetools\Core\Request\Reviews\Command\ReviewSetTitleAction;
@@ -740,6 +741,11 @@ public function actionArgumentProvider()
'ofProductIdVariantIdAndQuantity',
['productId', 1, 2]
],
+ [
+ MyCartAddLineItemAction::class,
+ 'ofProductIdVariantIdAndQuantity',
+ ['productId', 1, 2]
+ ],
[
CartAddPaymentAction::class,
'of',
@@ -1401,6 +1407,14 @@ public function actionArgumentProvider()
'ofName',
[$this->getInstance(LocalizedString::class)]
],
+ [
+ PaymentSetTransactionCustomFieldAction::class,
+ 'of',
+ ],
+ [
+ PaymentSetTransactionCustomTypeAction::class,
+ 'of',
+ ],
];
$actionNames = array_map(function ($value) {
diff --git a/tests/unit/Request/GenericByIdHeadRequestTest.php b/tests/unit/Request/GenericByIdHeadRequestTest.php
new file mode 100644
index 0000000000..a0dd1a72d4
--- /dev/null
+++ b/tests/unit/Request/GenericByIdHeadRequestTest.php
@@ -0,0 +1,72 @@
+ [
+ ProductByIdHeadRequest::class,
+ Product::class,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testMapResult($requestClass, $resultClass)
+ {
+ $result = $this->mapResult($requestClass, ['id']);
+ $this->assertInstanceOf($resultClass, $result);
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testMapEmptyResult($requestClass, $resultClass)
+ {
+ $result = $this->mapEmptyResult($requestClass, ['id']);
+ $this->assertNull($result);
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testBuilder($requestClass, $resultClass)
+ {
+ $class = new \ReflectionClass($requestClass);
+ $domain = lcfirst(basename(dirname($class->getFileName())));
+
+ $builder = RequestBuilder::of();
+
+ $domainBuilder = $builder->$domain();
+ $request = $domainBuilder->getByIdHead('');
+ $this->assertInstanceOf($requestClass, $request);
+ }
+}
diff --git a/tests/unit/Request/GenericByKeyHeadRequestTest.php b/tests/unit/Request/GenericByKeyHeadRequestTest.php
new file mode 100644
index 0000000000..cdae67d48f
--- /dev/null
+++ b/tests/unit/Request/GenericByKeyHeadRequestTest.php
@@ -0,0 +1,99 @@
+ [
+ ProductByKeyHeadRequest::class,
+ Product::class,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testMapResult($requestClass, $resultClass)
+ {
+ $result = $this->mapResult($requestClass, ['key']);
+ $this->assertInstanceOf($resultClass, $result);
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testMapEmptyResult($requestClass, $resultClass)
+ {
+ $result = $this->mapEmptyResult($requestClass, ['key']);
+ $this->assertNull($result);
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testBuilder($requestClass, $resultClass)
+ {
+ $class = new \ReflectionClass($requestClass);
+ $domain = lcfirst(basename(dirname($class->getFileName())));
+
+ $builder = RequestBuilder::of();
+
+ $domainBuilder = $builder->$domain();
+ $request = $domainBuilder->getByKeyHead('');
+ $this->assertInstanceOf($requestClass, $request);
+ }
+}
diff --git a/tests/unit/Request/GenericHeadRequestTest.php b/tests/unit/Request/GenericHeadRequestTest.php
new file mode 100644
index 0000000000..2ba7cee669
--- /dev/null
+++ b/tests/unit/Request/GenericHeadRequestTest.php
@@ -0,0 +1,70 @@
+ [
+ ProductHeadRequest::class,
+ Product::class,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ * @param $resultClass
+ */
+ public function testMapResult($requestClass, $resultClass)
+ {
+ $result = $this->mapResult($requestClass);
+ $this->assertInstanceOf($resultClass, $result);
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ */
+ public function testMapEmptyResult($requestClass)
+ {
+ $result = $this->mapEmptyResult($requestClass);
+ $this->assertNull($result);
+ }
+
+ /**
+ * @dataProvider mapResultProvider
+ * @param $requestClass
+ */
+ public function testBuilder($requestClass)
+ {
+ $class = new \ReflectionClass($requestClass);
+ $domain = lcfirst(basename(dirname($class->getFileName())));
+
+ $builder = RequestBuilder::of();
+
+ $domainBuilder = $builder->$domain();
+ $request = $domainBuilder->head('');
+ $this->assertInstanceOf($requestClass, $request);
+ }
+}
diff --git a/tests/unit/Request/Me/MeRequestTest.php b/tests/unit/Request/Me/MeRequestTest.php
new file mode 100644
index 0000000000..81e6860e6b
--- /dev/null
+++ b/tests/unit/Request/Me/MeRequestTest.php
@@ -0,0 +1,22 @@
+addAction(MyCartAddLineItemAction::ofProductIdVariantIdAndQuantity(
+ 'bla',
+ 1,
+ 1
+ ));
+ $httpRequest = $request->httpRequest();
+
+ $this->assertSame('me/carts/cartId', (string)$httpRequest->getUri());
+ }
+}
diff --git a/tests/unit/Request/Orders/OrderCreateFromCartRequestTest.php b/tests/unit/Request/Orders/OrderCreateFromCartRequestTest.php
index 1e768ca139..591458a8db 100644
--- a/tests/unit/Request/Orders/OrderCreateFromCartRequestTest.php
+++ b/tests/unit/Request/Orders/OrderCreateFromCartRequestTest.php
@@ -75,7 +75,10 @@ public function testHttpRequestObject()
$httpRequest = $request->httpRequest();
$expectedResult = [
- 'id' => '12345',
+ "cart" => [
+ "id" => "12345",
+ "typeId" => "cart"
+ ],
'version' => 1,
'orderNumber' => '12345678',
'paymentState' => 'paid',
diff --git a/tools/php_cs_fixer/php-cs-fixer-psr2.php b/tools/php_cs_fixer/php-cs-fixer-psr2.php
index cf2dc0623a..d755b4f5c3 100644
--- a/tools/php_cs_fixer/php-cs-fixer-psr2.php
+++ b/tools/php_cs_fixer/php-cs-fixer-psr2.php
@@ -56,7 +56,7 @@
$services->set(MethodArgumentSpaceFixer::class)
->call('configure', [[
- 'ensure_fully_multiline' => true,
+ 'on_multiline' => 'ensure_fully_multiline',
]]);
$services->set(NoBreakCommentFixer::class);
@@ -86,5 +86,8 @@
$services->set(SwitchCaseSpaceFixer::class);
- $services->set(VisibilityRequiredFixer::class);
+ $services->set(VisibilityRequiredFixer::class)
+ ->call('configure', [[
+ 'elements' => ['property', 'method']
+ ]]);
};