|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author @jenschude <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\DiscountCode; |
|
7
|
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\CartDiscount\CartDiscountReferenceCollection; |
|
9
|
|
|
use Commercetools\Core\Model\Common\Context; |
|
10
|
|
|
use Commercetools\Core\Model\Common\DateTimeDecorator; |
|
11
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
|
12
|
|
|
use Commercetools\Core\Model\Common\LocalizedString; |
|
13
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
|
14
|
|
|
use DateTime; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @package Commercetools\Core\Model\DiscountCode |
|
18
|
|
|
* @link https://docs.commercetools.com/http-api-projects-discountCodes.html#discountcodedraft |
|
19
|
|
|
* @method LocalizedString getName() |
|
20
|
|
|
* @method DiscountCodeDraft setName(LocalizedString $name = null) |
|
21
|
|
|
* @method LocalizedString getDescription() |
|
22
|
|
|
* @method DiscountCodeDraft setDescription(LocalizedString $description = null) |
|
23
|
|
|
* @method string getCode() |
|
24
|
|
|
* @method DiscountCodeDraft setCode(string $code = null) |
|
25
|
|
|
* @method CartDiscountReferenceCollection getCartDiscounts() |
|
26
|
|
|
* @method DiscountCodeDraft setCartDiscounts(CartDiscountReferenceCollection $cartDiscounts = null) |
|
27
|
|
|
* @method string getCartPredicate() |
|
28
|
|
|
* @method DiscountCodeDraft setCartPredicate(string $cartPredicate = null) |
|
29
|
|
|
* @method bool getIsActive() |
|
30
|
|
|
* @method DiscountCodeDraft setIsActive(bool $isActive = null) |
|
31
|
|
|
* @method int getMaxApplications() |
|
32
|
|
|
* @method DiscountCodeDraft setMaxApplications(int $maxApplications = null) |
|
33
|
|
|
* @method int getMaxApplicationsPerCustomer() |
|
34
|
|
|
* @method DiscountCodeDraft setMaxApplicationsPerCustomer(int $maxApplicationsPerCustomer = null) |
|
35
|
|
|
* @method CustomFieldObjectDraft getCustom() |
|
36
|
|
|
* @method DiscountCodeDraft setCustom(CustomFieldObjectDraft $custom = null) |
|
37
|
|
|
* @method array getGroups() |
|
38
|
|
|
* @method DiscountCodeDraft setGroups(array $groups = null) |
|
39
|
|
|
* @method DateTimeDecorator getValidFrom() |
|
40
|
|
|
* @method DiscountCodeDraft setValidFrom(DateTime $validFrom = null) |
|
41
|
|
|
* @method DateTimeDecorator getValidUntil() |
|
42
|
|
|
* @method DiscountCodeDraft setValidUntil(DateTime $validUntil = null) |
|
43
|
|
|
*/ |
|
44
|
|
|
class DiscountCodeDraft extends JsonObject |
|
45
|
|
|
{ |
|
46
|
21 |
|
public function fieldDefinitions() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
21 |
|
'name' => [static::TYPE => LocalizedString::class], |
|
50
|
21 |
|
'description' => [static::TYPE => LocalizedString::class], |
|
51
|
21 |
|
'code' => [static::TYPE => 'string'], |
|
52
|
|
|
'cartDiscounts' => [ |
|
53
|
21 |
|
static::TYPE => CartDiscountReferenceCollection::class |
|
54
|
|
|
], |
|
55
|
21 |
|
'cartPredicate' => [static::TYPE => 'string'], |
|
56
|
21 |
|
'isActive' => [static::TYPE => 'bool'], |
|
57
|
21 |
|
'maxApplications' => [static::TYPE => 'int'], |
|
58
|
21 |
|
'maxApplicationsPerCustomer' => [static::TYPE => 'int'], |
|
59
|
21 |
|
'custom' => [static::TYPE => CustomFieldObjectDraft::class], |
|
60
|
21 |
|
'groups' => [static::TYPE => 'array'], |
|
61
|
|
|
'validFrom' => [ |
|
62
|
21 |
|
static::TYPE => DateTime::class, |
|
63
|
21 |
|
static::DECORATOR => DateTimeDecorator::class |
|
64
|
|
|
], |
|
65
|
|
|
'validUntil' => [ |
|
66
|
21 |
|
static::TYPE => DateTime::class, |
|
67
|
21 |
|
static::DECORATOR => DateTimeDecorator::class |
|
68
|
|
|
], |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $code |
|
74
|
|
|
* @param CartDiscountReferenceCollection $cartDiscounts |
|
75
|
|
|
* @param bool $isActive |
|
76
|
|
|
* @param Context|callable $context |
|
77
|
|
|
* @return DiscountCodeDraft |
|
78
|
|
|
*/ |
|
79
|
20 |
|
public static function ofCodeDiscountsAndActive( |
|
80
|
|
|
$code, |
|
81
|
|
|
CartDiscountReferenceCollection $cartDiscounts, |
|
82
|
|
|
$isActive, |
|
83
|
|
|
$context = null |
|
84
|
|
|
) { |
|
85
|
20 |
|
return static::of($context) |
|
86
|
20 |
|
->setCode($code) |
|
87
|
20 |
|
->setCartDiscounts($cartDiscounts) |
|
88
|
20 |
|
->setIsActive($isActive); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|