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