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

Commit 3a55e6d

Browse files
author
Jens Schulze
authored
feat(Builder): add request and update actions builder DSL
* WIP: add request builders * WIP: add builder tests * WIP: more generic builder tests * feat(Request): add request builder DSL * test(Request): add more generic request tests * feat(Updates): add update builder DSL * WIP: add test for action builder * docs(DocBlocks): add missing links to dev documentation * WIP: use array constructor for action builders * WIP: sort builder methods * WIP: refactor action builders * WIP: add setter for actions at update builder * feat(RequestBuilder): add SetCustomTypeActions at Customer, Cart, Order * feat(RequestBuilder): add remaining SetCustomField and SetCustomType actions * feat(RequestBuilder): setters CustomType & CustomField at OrderLineItem & OrderCustomLineItem
1 parent f53d0b5 commit 3a55e6d

File tree

114 files changed

+10462
-16
lines changed

Some content is hidden

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

114 files changed

+10462
-16
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ To get up and running, [create a free test project](http://admin.sphere.io) on t
6969

7070
require '../vendor/autoload.php';
7171

72-
use Commercetools\Core\Request\Products\ProductProjectionSearchRequest;
72+
use Commercetools\Core\Builder\Request\RequestBuilder;
7373
use Commercetools\Core\Client;
7474
use Commercetools\Core\Config;
7575
use Commercetools\Core\Model\Common\Context;
@@ -87,7 +87,8 @@ $config = Config::fromArray($config)->setContext($context);
8787
* execute the request and get the PHP Object
8888
* (the client can and should be re-used)
8989
*/
90-
$search = ProductProjectionSearchRequest::of()->addParam('text.en', 'red');
90+
$search = RequestBuilder::of()->productProjections()->search()
91+
->addParam('text.en', 'red');
9192

9293
$client = Client::ofConfig($config);
9394
$products = $client->execute($search)->toObject();

docroot/index.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Commercetools\Core;
77

88
use Cache\Adapter\Filesystem\FilesystemCachePool;
9+
use Commercetools\Core\Builder\Request\RequestBuilder;
910
use League\Flysystem\Adapter\Local;
1011
use League\Flysystem\Filesystem;
1112
use Monolog\Handler\StreamHandler;
@@ -31,8 +32,9 @@
3132
if (isset($_POST['search'])) {
3233
$search = $_POST['search'];
3334
}
34-
$request = ProductProjectionSearchRequest::of($config->getContext())
35-
->addParam('text.' . current($config->getContext()->getLanguages()), $search);
35+
$request = RequestBuilder::of()->productProjections()->search()
36+
->addParam('text.' . current($config->getContext()->getLanguages()), $search)
37+
->setContext($config->getContext());
3638

3739
$log = new Logger('name');
3840
$log->pushHandler(new StreamHandler('./requests.log'));
@@ -43,7 +45,8 @@
4345

4446
$client = Client::ofConfigCacheAndLogger($config, $cache, $log);
4547

46-
$products = $client->execute($request)->toObject();
48+
$response = $client->execute($request);
49+
$products = $request->mapFromResponse($response);
4750

4851
/**
4952
* @var ProductProjectionCollection $products
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* @author @jenschude <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Builder\Request;
7+
8+
use Commercetools\Core\Model\CartDiscount\CartDiscount;
9+
use Commercetools\Core\Model\CartDiscount\CartDiscountDraft;
10+
use Commercetools\Core\Request\CartDiscounts\CartDiscountByIdGetRequest;
11+
use Commercetools\Core\Request\CartDiscounts\CartDiscountCreateRequest;
12+
use Commercetools\Core\Request\CartDiscounts\CartDiscountDeleteRequest;
13+
use Commercetools\Core\Request\CartDiscounts\CartDiscountQueryRequest;
14+
use Commercetools\Core\Request\CartDiscounts\CartDiscountUpdateRequest;
15+
16+
class CartDiscountRequestBuilder
17+
{
18+
/**
19+
* @return CartDiscountQueryRequest
20+
*/
21+
public function query()
22+
{
23+
return CartDiscountQueryRequest::of();
24+
}
25+
26+
/**
27+
* @param CartDiscount $cartDiscount
28+
* @return CartDiscountUpdateRequest
29+
*/
30+
public function update(CartDiscount $cartDiscount)
31+
{
32+
return CartDiscountUpdateRequest::ofIdAndVersion($cartDiscount->getId(), $cartDiscount->getVersion());
33+
}
34+
35+
/**
36+
* @param CartDiscountDraft $cartDiscountDraft
37+
* @return CartDiscountCreateRequest
38+
*/
39+
public function create(CartDiscountDraft $cartDiscountDraft)
40+
{
41+
return CartDiscountCreateRequest::ofDraft($cartDiscountDraft);
42+
}
43+
44+
/**
45+
* @param CartDiscount $cartDiscount
46+
* @return CartDiscountDeleteRequest
47+
*/
48+
public function delete(CartDiscount $cartDiscount)
49+
{
50+
return CartDiscountDeleteRequest::ofIdAndVersion($cartDiscount->getId(), $cartDiscount->getVersion());
51+
}
52+
53+
/**
54+
* @param string $id
55+
* @return CartDiscountByIdGetRequest
56+
*/
57+
public function getById($id)
58+
{
59+
return CartDiscountByIdGetRequest::ofId($id);
60+
}
61+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @author @jenschude <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Builder\Request;
7+
8+
use Commercetools\Core\Model\Cart\Cart;
9+
use Commercetools\Core\Model\Cart\CartDraft;
10+
use Commercetools\Core\Request\Carts\CartByCustomerIdGetRequest;
11+
use Commercetools\Core\Request\Carts\CartByIdGetRequest;
12+
use Commercetools\Core\Request\Carts\CartCreateRequest;
13+
use Commercetools\Core\Request\Carts\CartDeleteRequest;
14+
use Commercetools\Core\Request\Carts\CartQueryRequest;
15+
use Commercetools\Core\Request\Carts\CartReplicateRequest;
16+
use Commercetools\Core\Request\Carts\CartUpdateRequest;
17+
18+
class CartRequestBuilder
19+
{
20+
/**
21+
* @return CartQueryRequest
22+
*/
23+
public function query()
24+
{
25+
return CartQueryRequest::of();
26+
}
27+
28+
/**
29+
* @param Cart $cart
30+
* @return CartUpdateRequest
31+
*/
32+
public function update(Cart $cart)
33+
{
34+
return CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion());
35+
}
36+
37+
/**
38+
* @param CartDraft $cartDraft
39+
* @return CartCreateRequest
40+
*/
41+
public function create(CartDraft $cartDraft)
42+
{
43+
return CartCreateRequest::ofDraft($cartDraft);
44+
}
45+
46+
/**
47+
* @param Cart $cart
48+
* @return CartDeleteRequest
49+
*/
50+
public function delete(Cart $cart)
51+
{
52+
return CartDeleteRequest::ofIdAndVersion($cart->getId(), $cart->getVersion());
53+
}
54+
55+
/**
56+
* @param string $id
57+
* @return CartByIdGetRequest
58+
*/
59+
public function getById($id)
60+
{
61+
return CartByIdGetRequest::ofId($id);
62+
}
63+
64+
/**
65+
* @param string $customerId
66+
* @return CartByCustomerIdGetRequest
67+
*/
68+
public function getByCustomerId($customerId)
69+
{
70+
return CartByCustomerIdGetRequest::ofCustomerId($customerId);
71+
}
72+
73+
public function replicate($cartId)
74+
{
75+
return CartReplicateRequest::ofCartId($cartId);
76+
}
77+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* @author @jenschude <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Builder\Request;
7+
8+
use Commercetools\Core\Model\Category\Category;
9+
use Commercetools\Core\Model\Category\CategoryDraft;
10+
use Commercetools\Core\Request\Categories\CategoryByIdGetRequest;
11+
use Commercetools\Core\Request\Categories\CategoryByKeyGetRequest;
12+
use Commercetools\Core\Request\Categories\CategoryCreateRequest;
13+
use Commercetools\Core\Request\Categories\CategoryDeleteByKeyRequest;
14+
use Commercetools\Core\Request\Categories\CategoryDeleteRequest;
15+
use Commercetools\Core\Request\Categories\CategoryQueryRequest;
16+
use Commercetools\Core\Request\Categories\CategoryUpdateByKeyRequest;
17+
use Commercetools\Core\Request\Categories\CategoryUpdateRequest;
18+
19+
class CategoryRequestBuilder
20+
{
21+
/**
22+
* @return CategoryQueryRequest
23+
*/
24+
public function query()
25+
{
26+
return CategoryQueryRequest::of();
27+
}
28+
29+
/**
30+
* @param Category $category
31+
* @return CategoryUpdateRequest
32+
*/
33+
public function update(Category $category)
34+
{
35+
return CategoryUpdateRequest::ofIdAndVersion($category->getId(), $category->getVersion());
36+
}
37+
38+
/**
39+
* @param Category $category
40+
* @return CategoryUpdateByKeyRequest
41+
*/
42+
public function updateByKey(Category $category)
43+
{
44+
return CategoryUpdateByKeyRequest::ofKeyAndVersion($category->getKey(), $category->getVersion());
45+
}
46+
47+
/**
48+
* @param CategoryDraft $categoryDraft
49+
* @return CategoryCreateRequest
50+
*/
51+
public function create(CategoryDraft $categoryDraft)
52+
{
53+
return CategoryCreateRequest::ofDraft($categoryDraft);
54+
}
55+
56+
/**
57+
* @param Category $category
58+
* @return CategoryDeleteRequest
59+
*/
60+
public function delete(Category $category)
61+
{
62+
return CategoryDeleteRequest::ofIdAndVersion($category->getId(), $category->getVersion());
63+
}
64+
65+
/**
66+
* @param Category $category
67+
* @return CategoryDeleteByKeyRequest
68+
*/
69+
public function deleteByKey(Category $category)
70+
{
71+
return CategoryDeleteByKeyRequest::ofKeyAndVersion($category->getKey(), $category->getVersion());
72+
}
73+
74+
/**
75+
* @param string $id
76+
* @return CategoryByIdGetRequest
77+
*/
78+
public function getById($id)
79+
{
80+
return CategoryByIdGetRequest::ofId($id);
81+
}
82+
83+
/**
84+
* @param string $key
85+
* @return CategoryByKeyGetRequest
86+
*/
87+
public function getByKey($key)
88+
{
89+
return CategoryByKeyGetRequest::ofKey($key);
90+
}
91+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* @author @jenschude <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Builder\Request;
7+
8+
use Commercetools\Core\Model\Channel\Channel;
9+
use Commercetools\Core\Model\Channel\ChannelDraft;
10+
use Commercetools\Core\Request\Channels\ChannelByIdGetRequest;
11+
use Commercetools\Core\Request\Channels\ChannelCreateRequest;
12+
use Commercetools\Core\Request\Channels\ChannelDeleteRequest;
13+
use Commercetools\Core\Request\Channels\ChannelQueryRequest;
14+
use Commercetools\Core\Request\Channels\ChannelUpdateRequest;
15+
16+
class ChannelRequestBuilder
17+
{
18+
/**
19+
* @return ChannelQueryRequest
20+
*/
21+
public function query()
22+
{
23+
return ChannelQueryRequest::of();
24+
}
25+
26+
/**
27+
* @param Channel $channel
28+
* @return ChannelUpdateRequest
29+
*/
30+
public function update(Channel $channel)
31+
{
32+
return ChannelUpdateRequest::ofIdAndVersion($channel->getId(), $channel->getVersion());
33+
}
34+
35+
/**
36+
* @param ChannelDraft $channelDraft
37+
* @return ChannelCreateRequest
38+
*/
39+
public function create(ChannelDraft $channelDraft)
40+
{
41+
return ChannelCreateRequest::ofDraft($channelDraft);
42+
}
43+
44+
/**
45+
* @param Channel $channel
46+
* @return ChannelDeleteRequest
47+
*/
48+
public function delete(Channel $channel)
49+
{
50+
return ChannelDeleteRequest::ofIdAndVersion($channel->getId(), $channel->getVersion());
51+
}
52+
53+
/**
54+
* @param string $id
55+
* @return ChannelByIdGetRequest
56+
*/
57+
public function getById($id)
58+
{
59+
return ChannelByIdGetRequest::ofId($id);
60+
}
61+
}

0 commit comments

Comments
 (0)