1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[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
|
|
|
use DateTime; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @package Commercetools\Core\Model\Common |
16
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#scopedprice |
17
|
|
|
* @method Money getValue() |
18
|
|
|
* @method string getCountry() |
19
|
|
|
* @method CustomerGroupReference getCustomerGroup() |
20
|
|
|
* @method ChannelReference getChannel() |
21
|
|
|
* @method DiscountedPrice getDiscounted() |
22
|
|
|
* @method ScopedPrice setValue(Money $value = null) |
23
|
|
|
* @method ScopedPrice setCountry(string $country = null) |
24
|
|
|
* @method ScopedPrice setCustomerGroup(CustomerGroupReference $customerGroup = null) |
25
|
|
|
* @method ScopedPrice setChannel(ChannelReference $channel = null) |
26
|
|
|
* @method ScopedPrice setDiscounted(DiscountedPrice $discounted = null) |
27
|
|
|
* @method string getId() |
28
|
|
|
* @method ScopedPrice setId(string $id = null) |
29
|
|
|
* @method DateTimeDecorator getValidFrom() |
30
|
|
|
* @method ScopedPrice setValidFrom(DateTime $validFrom = null) |
31
|
|
|
* @method DateTimeDecorator getValidUntil() |
32
|
|
|
* @method ScopedPrice setValidUntil(DateTime $validUntil = null) |
33
|
|
|
* @method CustomFieldObject getCustom() |
34
|
|
|
* @method ScopedPrice setCustom(CustomFieldObject $custom = null) |
35
|
|
|
* @method Money getCurrentValue() |
36
|
|
|
* @method ScopedPrice setCurrentValue(Money $currentValue = null) |
37
|
|
|
*/ |
38
|
|
|
class ScopedPrice extends JsonObject |
39
|
|
|
{ |
40
|
|
|
const ID = 'id'; |
41
|
|
|
const VALUE = 'value'; |
42
|
|
|
const CURRENT_VALUE = 'currentValue'; |
43
|
|
|
const COUNTRY = 'country'; |
44
|
|
|
const CUSTOMER_GROUP = 'customerGroup'; |
45
|
|
|
const CHANNEL = 'channel'; |
46
|
|
|
const VALID_FROM = 'validFrom'; |
47
|
|
|
const VALID_UNTIL = 'validUntil'; |
48
|
|
|
const DISCOUNTED = 'discounted'; |
49
|
|
|
const CUSTOM = 'custom'; |
50
|
|
|
|
51
|
1 |
View Code Duplication |
public function fieldDefinitions() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
1 |
|
static::ID => [static::TYPE => 'string'], |
55
|
1 |
|
static::VALUE => [self::TYPE => Money::class], |
56
|
1 |
|
static::CURRENT_VALUE => [static::TYPE => Money::class], |
57
|
1 |
|
static::COUNTRY => [self::TYPE => 'string'], |
58
|
1 |
|
static::CUSTOMER_GROUP => [self::TYPE => CustomerGroupReference::class], |
59
|
1 |
|
static::CHANNEL => [self::TYPE => ChannelReference::class], |
60
|
1 |
|
static::VALID_FROM => [ |
61
|
1 |
|
self::TYPE => DateTime::class, |
62
|
1 |
|
self::DECORATOR => DateTimeDecorator::class |
63
|
|
|
], |
64
|
1 |
|
static::VALID_UNTIL => [ |
65
|
1 |
|
self::TYPE => DateTime::class, |
66
|
1 |
|
self::DECORATOR => DateTimeDecorator::class |
67
|
|
|
], |
68
|
1 |
|
static::DISCOUNTED => [self::TYPE => DiscountedPrice::class], |
69
|
1 |
|
static::CUSTOM => [static::TYPE => CustomFieldObject::class], |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param Money $money |
75
|
|
|
* @param Context|callable $context |
76
|
|
|
* @return ScopedPrice |
77
|
|
|
*/ |
78
|
|
|
public static function ofMoney(Money $money, $context = null) |
79
|
|
|
{ |
80
|
|
|
$price = static::of($context); |
81
|
|
|
return $price->setValue($money); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function __toString() |
85
|
|
|
{ |
86
|
|
|
return $this->getCurrentValue()->__toString(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.