1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\CartDiscount; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
9
|
|
|
use Commercetools\Core\Model\Common\DiscountValue; |
10
|
|
|
use Commercetools\Core\Model\Common\MoneyCollection; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package Commercetools\Core\Model\CartDiscount |
14
|
|
|
* @link https://dev.commercetools.com/http-api-projects-cartDiscounts.html#cartdiscountvalue |
15
|
|
|
* @deprecated use RelativeCartDiscountValue, AbsoluteCartDiscountValue or GiftLineItemCartDiscountValue instead. |
16
|
|
|
* @method string getType() |
17
|
|
|
* @method CartDiscountValue setType(string $type = null) |
18
|
|
|
* @method int getPermyriad() |
19
|
|
|
* @method CartDiscountValue setPermyriad(int $permyriad = null) |
20
|
|
|
* @method MoneyCollection getMoney() |
21
|
|
|
* @method CartDiscountValue setMoney(MoneyCollection $money = null) |
22
|
|
|
*/ |
23
|
|
|
class CartDiscountValue extends DiscountValue |
24
|
|
|
{ |
25
|
|
|
const TYPE_RELATIVE = 'relative'; |
26
|
|
|
const TYPE_ABSOLUTE = 'absolute'; |
27
|
|
|
const TYPE_GIFT_LINE_ITEM = 'giftLineItem'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array $data |
31
|
|
|
* @param Context|callable $context |
32
|
|
|
* @return static |
33
|
|
|
*/ |
34
|
2 |
|
public static function fromArray(array $data, $context = null) |
35
|
|
|
{ |
36
|
2 |
|
if (isset($data['type'])) { |
37
|
2 |
|
$className = static::getClassByType($data['type']); |
38
|
2 |
|
if (class_exists($className)) { |
39
|
2 |
|
return new $className($data, $context); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
return new static($data, $context); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
protected static function getClassByType($type) |
46
|
|
|
{ |
47
|
2 |
|
$className = '\Commercetools\Core\Model\CartDiscount\\' . ucfirst($type) . 'CartDiscountValue'; |
48
|
2 |
|
return $className; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.