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

Commit 39f356a

Browse files
author
Jens Schulze
committed
feat(Product): support key for product and product variant
Closes #259
1 parent 7482d1b commit 39f356a

16 files changed

+464
-6
lines changed

src/Model/Product/Product.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* @method Product setReviewRatingStatistics(ReviewRatingStatistics $reviewRatingStatistics = null)
3636
* @method StateReference getState()
3737
* @method Product setState(StateReference $state = null)
38+
* @method string getKey()
39+
* @method Product setKey(string $key = null)
3840
* @method ProductReference getReference()
3941
*/
4042
class Product extends Resource
@@ -57,6 +59,7 @@ public function fieldDefinitions()
5759
'masterData' => [self::TYPE => '\Commercetools\Core\Model\Product\ProductCatalogData'],
5860
'reviewRatingStatistics' => [static::TYPE => '\Commercetools\Core\Model\Review\ReviewRatingStatistics'],
5961
'state' => [static::TYPE => '\Commercetools\Core\Model\State\StateReference'],
62+
'key' => [static::TYPE => 'string'],
6063
];
6164
}
6265
}

src/Model/Product/ProductDraft.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
* @method ProductDraft setState(StateReference $state = null)
4646
* @method bool getPublish()
4747
* @method ProductDraft setPublish(bool $publish = null)
48+
* @method string getKey()
49+
* @method ProductDraft setKey(string $key = null)
4850
*/
4951
class ProductDraft extends JsonObject
5052
{
@@ -65,6 +67,7 @@ public function fieldDefinitions()
6567
'searchKeywords' => [static::TYPE => '\Commercetools\Core\Model\Product\LocalizedSearchKeywords'],
6668
'state' => [static::TYPE => '\Commercetools\Core\Model\State\StateReference'],
6769
'publish' => [static::TYPE => 'bool'],
70+
'key' => [static::TYPE => 'string'],
6871
];
6972
}
7073

src/Model/Product/ProductProjection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
* @method ProductProjection setState(StateReference $state = null)
6363
* @method array getCategoryOrderHints()
6464
* @method ProductProjection setCategoryOrderHints(array $categoryOrderHints = null)
65+
* @method string getKey()
66+
* @method ProductProjection setKey(string $key = null)
6567
*/
6668
class ProductProjection extends JsonObject implements ReferenceObjectInterface
6769
{
@@ -95,6 +97,7 @@ public function fieldDefinitions()
9597
'searchKeywords' => [static::TYPE => '\Commercetools\Core\Model\Product\LocalizedSearchKeywords'],
9698
'reviewRatingStatistics' => [static::TYPE => '\Commercetools\Core\Model\Review\ReviewRatingStatistics'],
9799
'state' => [static::TYPE => '\Commercetools\Core\Model\State\StateReference'],
100+
'key' => [static::TYPE => 'string'],
98101
];
99102
}
100103

src/Model/Product/ProductVariant.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* @method ProductVariant setScopedPriceDiscounted(bool $scopedPriceDiscounted = null)
3939
* @method AssetCollection getAssets()
4040
* @method ProductVariant setAssets(AssetCollection $assets = null)
41+
* @method string getKey()
42+
* @method ProductVariant setKey(string $key = null)
4143
*/
4244
class ProductVariant extends JsonObject
4345
{
@@ -54,7 +56,8 @@ public function fieldDefinitions()
5456
'isMatchingVariant' => [static::TYPE => 'bool'],
5557
'scopedPrice' => [static::TYPE => '\Commercetools\Core\Model\Common\ScopedPrice'],
5658
'scopedPriceDiscounted' => [static::TYPE => 'bool'],
57-
'assets' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetCollection']
59+
'assets' => [static::TYPE => '\Commercetools\Core\Model\Common\AssetCollection'],
60+
'key' => [static::TYPE => 'string'],
5861
];
5962
}
6063
}

src/Request/Products/Command/ProductAddVariantAction.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Commercetools\Core\Model\Common\Context;
1010
use Commercetools\Core\Model\Common\PriceDraftCollection;
1111
use Commercetools\Core\Request\AbstractAction;
12+
use Commercetools\Core\Model\Common\ImageCollection;
1213

1314
/**
1415
* @package Commercetools\Core\Request\Products\Command
@@ -23,6 +24,10 @@
2324
* @method ProductAddVariantAction setAttributes(AttributeCollection $attributes = null)
2425
* @method bool getStaged()
2526
* @method ProductAddVariantAction setStaged(bool $staged = null)
27+
* @method string getKey()
28+
* @method ProductAddVariantAction setKey(string $key = null)
29+
* @method ImageCollection getImages()
30+
* @method ProductAddVariantAction setImages(ImageCollection $images = null)
2631
*/
2732
class ProductAddVariantAction extends AbstractAction
2833
{
@@ -34,6 +39,8 @@ public function fieldDefinitions()
3439
'prices' => [static::TYPE => '\Commercetools\Core\Model\Common\PriceDraftCollection'],
3540
'attributes' => [static::TYPE => '\Commercetools\Core\Model\Common\AttributeCollection'],
3641
'staged' => [static::TYPE => 'bool'],
42+
'key' => [static::TYPE => 'string'],
43+
'images' => [static::TYPE => '\Commercetools\Core\Model\Common\ImageCollection']
3744
];
3845
}
3946

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Products\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Products\Command
13+
* @link https://dev.commercetools.com/http-api-projects-products.html#set-key
14+
* @method string getAction()
15+
* @method ProductSetKeyAction setAction(string $action = null)
16+
* @method string getKey()
17+
* @method ProductSetKeyAction setKey(string $key = null)
18+
*/
19+
class ProductSetKeyAction extends AbstractAction
20+
{
21+
public function fieldDefinitions()
22+
{
23+
return [
24+
'action' => [static::TYPE => 'string'],
25+
'key' => [static::TYPE => 'string']
26+
];
27+
}
28+
29+
/**
30+
* @param array $data
31+
* @param Context|callable $context
32+
*/
33+
public function __construct(array $data = [], $context = null)
34+
{
35+
parent::__construct($data, $context);
36+
$this->setAction('setKey');
37+
}
38+
39+
/**
40+
* @param string $key
41+
* @param Context|callable $context
42+
* @return ProductSetKeyAction
43+
*/
44+
public static function ofKey($key, $context = null)
45+
{
46+
return static::of($context)->setKey($key);
47+
}
48+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Products\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Products\Command
13+
* @link https://dev.commercetools.com/http-api-projects-products.html#set-productvariant-key
14+
* @method string getAction()
15+
* @method ProductSetProductVariantKeyAction setAction(string $action = null)
16+
* @method string getKey()
17+
* @method ProductSetProductVariantKeyAction setKey(string $key = null)
18+
* @method int getVariantId()
19+
* @method ProductSetProductVariantKeyAction setVariantId(int $variantId = null)
20+
* @method string getSku()
21+
* @method ProductSetProductVariantKeyAction setSku(string $sku = null)
22+
* @method bool getStaged()
23+
* @method ProductSetProductVariantKeyAction setStaged(bool $staged = null)
24+
*/
25+
class ProductSetProductVariantKeyAction extends AbstractAction
26+
{
27+
public function fieldDefinitions()
28+
{
29+
return [
30+
'action' => [static::TYPE => 'string'],
31+
'variantId' => [static::TYPE => 'int'],
32+
'sku' => [static::TYPE => 'string'],
33+
'key' => [static::TYPE => 'string'],
34+
'staged' => [static::TYPE => 'bool']
35+
];
36+
}
37+
38+
/**
39+
* @param array $data
40+
* @param Context|callable $context
41+
*/
42+
public function __construct(array $data = [], $context = null)
43+
{
44+
parent::__construct($data, $context);
45+
$this->setAction('setProductVariantKey');
46+
}
47+
48+
/**
49+
* @param $variantId
50+
* @param string $key
51+
* @param Context|callable $context
52+
* @return ProductSetProductVariantKeyAction
53+
*/
54+
public static function ofVariantIdAndKey($variantId, $key, $context = null)
55+
{
56+
return static::of($context)->setVariantId($variantId)->setKey($key);
57+
}
58+
59+
/**
60+
* @param $sku
61+
* @param string $key
62+
* @param Context|callable $context
63+
* @return ProductSetProductVariantKeyAction
64+
*/
65+
public static function ofSkuAndKey($sku, $key, $context = null)
66+
{
67+
return static::of($context)->setSku($sku)->setKey($key);
68+
}
69+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Products;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractByKeyGetRequest;
10+
use Commercetools\Core\Model\Product\Product;
11+
use Commercetools\Core\Response\ApiResponseInterface;
12+
13+
/**
14+
* @package Commercetools\Core\Request\Products
15+
*
16+
* @method Product mapResponse(ApiResponseInterface $response)
17+
*/
18+
class ProductByKeyGetRequest extends AbstractByKeyGetRequest
19+
{
20+
protected $resultClass = '\Commercetools\Core\Model\Product\Product';
21+
22+
/**
23+
* @param string $key
24+
* @param Context $context
25+
*/
26+
public function __construct($key, Context $context = null)
27+
{
28+
parent::__construct(ProductsEndpoint::endpoint(), $key, $context);
29+
}
30+
31+
/**
32+
* @param string $key
33+
* @param Context $context
34+
* @return static
35+
*/
36+
public static function ofKey($key, Context $context = null)
37+
{
38+
return new static($key, $context);
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Products;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractDeleteByKeyRequest;
10+
use Commercetools\Core\Model\Product\Product;
11+
use Commercetools\Core\Response\ApiResponseInterface;
12+
13+
/**
14+
* @package Commercetools\Core\Request\Products
15+
*
16+
* @method Product mapResponse(ApiResponseInterface $response)
17+
*/
18+
class ProductDeleteByKeyRequest extends AbstractDeleteByKeyRequest
19+
{
20+
protected $resultClass = '\Commercetools\Core\Model\Product\Product';
21+
22+
/**
23+
* @param string $key
24+
* @param int $version
25+
* @param Context $context
26+
*/
27+
public function __construct($key, $version, Context $context = null)
28+
{
29+
parent::__construct(ProductsEndpoint::endpoint(), $key, $version, $context);
30+
}
31+
32+
/**
33+
* @param string $key
34+
* @param int $version
35+
* @param Context $context
36+
* @return static
37+
*/
38+
public static function ofKeyAndVersion($key, $version, Context $context = null)
39+
{
40+
return new static($key, $version, $context);
41+
}
42+
}

src/Request/Products/ProductProjectionByIdGetRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/**
1717
* @package Commercetools\Core\Request\Products
18-
* @link https://dev.commercetools.com/http-api-projects-products.html#get-productprojection-by-id
18+
* @link https://dev.commercetools.com/http-api-projects-productProjections.html#get-productprojection-by-id
1919
* @method ProductProjection mapResponse(ApiResponseInterface $response)
2020
*/
2121
class ProductProjectionByIdGetRequest extends AbstractByIdGetRequest

0 commit comments

Comments
 (0)