1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\cart; |
12
|
|
|
|
13
|
|
|
use yii\base\InvalidConfigException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Purchase. |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractPurchase extends \hipanel\base\Model |
19
|
|
|
{ |
20
|
|
|
use \hipanel\base\ModelTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var AbstractCartPosition |
24
|
|
|
*/ |
25
|
|
|
public $position; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array result of purchase execution |
29
|
|
|
*/ |
30
|
|
|
protected $_result; |
31
|
|
|
|
32
|
|
|
public function getResult() |
33
|
|
|
{ |
34
|
|
|
return $this->_result; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** {@inheritdoc} */ |
38
|
|
|
public static function tableName() |
39
|
|
|
{ |
40
|
|
|
throw new InvalidConfigException('Method "tableName" must be declared'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string operation to be performed, e.g.: Renew, Transfer, Registration |
45
|
|
|
*/ |
46
|
|
|
public static function operation() |
47
|
|
|
{ |
48
|
|
|
throw new InvalidConfigException('Method "operation" must be declared'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** {@inheritdoc} */ |
52
|
|
|
public function init() |
53
|
|
|
{ |
54
|
|
|
parent::init(); |
55
|
|
|
|
56
|
|
|
$this->calculation_id = $this->position->getId(); |
|
|
|
|
57
|
|
|
$this->amount = $this->position->getQuantity(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Executes the purchase. |
62
|
|
|
* Calls proper API commands to purchase the product. |
63
|
|
|
* @throws ErrorPurchaseException in case of failed purchase |
64
|
|
|
* @return true if the item was purchased successfully |
65
|
|
|
*/ |
66
|
|
|
public function execute() |
67
|
|
|
{ |
68
|
|
|
if ($this->validate()) { |
69
|
|
|
$this->_result = static::perform(static::operation(), $this->getAttributes()); |
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return false; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function renderNotes() |
77
|
|
|
{ |
78
|
|
|
return ''; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** {@inheritdoc} */ |
82
|
|
|
public function rules() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
[['calculation_id', 'object', 'client', 'type', 'currency', 'item'], 'safe'], |
86
|
|
|
[['amount'], 'number'], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.