|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author @jenschude <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Common; |
|
7
|
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference; |
|
9
|
|
|
use Commercetools\Core\Model\Channel\ChannelReference; |
|
10
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObject; |
|
11
|
|
|
use DateTime; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @package Commercetools\Core\Model\Common |
|
15
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#pricedraft |
|
16
|
|
|
* @method Money getValue() |
|
17
|
|
|
* @method PriceDraft setValue(Money $value = null) |
|
18
|
|
|
* @method string getCountry() |
|
19
|
|
|
* @method PriceDraft setCountry(string $country = null) |
|
20
|
|
|
* @method CustomerGroupReference getCustomerGroup() |
|
21
|
|
|
* @method PriceDraft setCustomerGroup(CustomerGroupReference $customerGroup = null) |
|
22
|
|
|
* @method ChannelReference getChannel() |
|
23
|
|
|
* @method PriceDraft setChannel(ChannelReference $channel = null) |
|
24
|
|
|
* @method DateTimeDecorator getValidFrom() |
|
25
|
|
|
* @method PriceDraft setValidFrom(DateTime $validFrom = null) |
|
26
|
|
|
* @method DateTimeDecorator getValidUntil() |
|
27
|
|
|
* @method PriceDraft setValidUntil(DateTime $validUntil = null) |
|
28
|
|
|
* @method CustomFieldObject getCustom() |
|
29
|
|
|
* @method PriceDraft setCustom(CustomFieldObject $custom = null) |
|
30
|
|
|
* @method PriceTierCollection getTiers() |
|
31
|
|
|
* @method PriceDraft setTiers(PriceTierCollection $tiers = null) |
|
32
|
|
|
* @method DiscountedPrice getDiscounted() |
|
33
|
|
|
* @method PriceDraft setDiscounted(DiscountedPrice $discounted = null) |
|
34
|
|
|
*/ |
|
35
|
|
|
class PriceDraft extends JsonObject |
|
36
|
|
|
{ |
|
37
|
|
|
const VALUE = 'value'; |
|
38
|
|
|
const COUNTRY = 'country'; |
|
39
|
|
|
const CUSTOMER_GROUP = 'customerGroup'; |
|
40
|
|
|
const CHANNEL = 'channel'; |
|
41
|
|
|
const VALID_FROM = 'validFrom'; |
|
42
|
|
|
const VALID_UNTIL = 'validUntil'; |
|
43
|
|
|
const DISCOUNTED = 'discounted'; |
|
44
|
|
|
const CUSTOM = 'custom'; |
|
45
|
|
|
const TIERS = 'tiers'; |
|
46
|
|
|
|
|
47
|
225 |
|
public function fieldDefinitions() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
225 |
|
static::VALUE => [self::TYPE => Money::class], |
|
51
|
225 |
|
static::COUNTRY => [self::TYPE => 'string'], |
|
52
|
225 |
|
static::CUSTOMER_GROUP => [self::TYPE => CustomerGroupReference::class], |
|
53
|
225 |
|
static::CHANNEL => [self::TYPE => ChannelReference::class], |
|
54
|
225 |
|
static::VALID_FROM => [ |
|
55
|
225 |
|
self::TYPE => DateTime::class, |
|
56
|
225 |
|
self::DECORATOR => DateTimeDecorator::class |
|
57
|
|
|
], |
|
58
|
225 |
|
static::VALID_UNTIL => [ |
|
59
|
225 |
|
self::TYPE => DateTime::class, |
|
60
|
225 |
|
self::DECORATOR => DateTimeDecorator::class |
|
61
|
|
|
], |
|
62
|
225 |
|
static::CUSTOM => [static::TYPE => CustomFieldObject::class], |
|
63
|
225 |
|
static::TIERS => [static::TYPE => PriceTierCollection::class], |
|
64
|
225 |
|
static::DISCOUNTED => [static::TYPE => DiscountedPrice::class], |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Money $money |
|
70
|
|
|
* @param Context|callable $context |
|
71
|
|
|
* @return PriceDraft |
|
72
|
|
|
*/ |
|
73
|
223 |
|
public static function ofMoney(Money $money, $context = null) |
|
74
|
|
|
{ |
|
75
|
223 |
|
$price = static::of($context); |
|
76
|
223 |
|
return $price->setValue($money); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function __toString() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->getValue()->__toString(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|