|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author @ct-jensschulze <[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 | + |
| 12 | +/** |
| 13 | + * @package Commercetools\Core\Model\Common |
| 14 | + * |
| 15 | + * @method Money getValue() |
| 16 | + * @method PriceDraft setValue(Money $value = null) |
| 17 | + * @method string getCountry() |
| 18 | + * @method PriceDraft setCountry(string $country = null) |
| 19 | + * @method CustomerGroupReference getCustomerGroup() |
| 20 | + * @method PriceDraft setCustomerGroup(CustomerGroupReference $customerGroup = null) |
| 21 | + * @method ChannelReference getChannel() |
| 22 | + * @method PriceDraft setChannel(ChannelReference $channel = null) |
| 23 | + * @method DateTimeDecorator getValidFrom() |
| 24 | + * @method PriceDraft setValidFrom(\DateTime $validFrom = null) |
| 25 | + * @method DateTimeDecorator getValidUntil() |
| 26 | + * @method PriceDraft setValidUntil(\DateTime $validUntil = null) |
| 27 | + * @method CustomFieldObject getCustom() |
| 28 | + * @method PriceDraft setCustom(CustomFieldObject $custom = null) |
| 29 | + */ |
| 30 | +class PriceDraft extends JsonObject |
| 31 | +{ |
| 32 | + const VALUE = 'value'; |
| 33 | + const COUNTRY = 'country'; |
| 34 | + const CUSTOMER_GROUP = 'customerGroup'; |
| 35 | + const CHANNEL = 'channel'; |
| 36 | + const VALID_FROM = 'validFrom'; |
| 37 | + const VALID_UNTIL = 'validUntil'; |
| 38 | + const DISCOUNTED = 'discounted'; |
| 39 | + const CUSTOM = 'custom'; |
| 40 | + |
| 41 | + public function fieldDefinitions() |
| 42 | + { |
| 43 | + return [ |
| 44 | + static::VALUE => [self::TYPE => '\Commercetools\Core\Model\Common\Money'], |
| 45 | + static::COUNTRY => [self::TYPE => 'string'], |
| 46 | + static::CUSTOMER_GROUP => [self::TYPE => '\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference'], |
| 47 | + static::CHANNEL => [self::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'], |
| 48 | + static::VALID_FROM => [ |
| 49 | + self::TYPE => '\DateTime', |
| 50 | + self::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
| 51 | + ], |
| 52 | + static::VALID_UNTIL => [ |
| 53 | + self::TYPE => '\DateTime', |
| 54 | + self::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
| 55 | + ], |
| 56 | + static::CUSTOM => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'], |
| 57 | + ]; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @param Money $money |
| 62 | + * @param Context|callable $context |
| 63 | + * @return Price |
| 64 | + */ |
| 65 | + public static function ofMoney(Money $money, $context = null) |
| 66 | + { |
| 67 | + $price = static::of($context); |
| 68 | + return $price->setValue($money); |
| 69 | + } |
| 70 | + |
| 71 | + public function __toString() |
| 72 | + { |
| 73 | + return $this->getValue()->__toString(); |
| 74 | + } |
| 75 | +} |
0 commit comments