1 | <?php |
||
17 | class Address extends Base |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Address model instance |
||
22 | * @var \gplcart\core\models\Address $address |
||
23 | */ |
||
24 | protected $address; |
||
25 | |||
26 | /** |
||
27 | * @param AddressModel $alias |
||
28 | */ |
||
29 | public function __construct(AddressModel $alias) |
||
35 | |||
36 | /** |
||
37 | * Callback for "address-get" command |
||
38 | */ |
||
39 | public function cmdGetAddress() |
||
46 | |||
47 | /** |
||
48 | * Callback for "address-delete" command |
||
49 | */ |
||
50 | public function cmdDeleteAddress() |
||
51 | { |
||
52 | $id = $this->getParam(0); |
||
53 | |||
54 | if (empty($id)) { |
||
55 | $this->errorAndExit($this->text('Invalid argument')); |
||
56 | } |
||
57 | |||
58 | if ($this->getParam('user')) { |
||
59 | |||
60 | $deleted = $count = 0; |
||
61 | foreach ($this->address->getList(array('user_id' => $id)) as $item) { |
||
62 | $count++; |
||
63 | $deleted += (int) $this->address->delete($item['address_id']); |
||
64 | } |
||
65 | |||
66 | $result = $count && $count == $deleted; |
||
67 | |||
68 | } else { |
||
69 | |||
70 | if (!is_numeric($id)) { |
||
71 | $this->errorAndExit($this->text('Invalid argument')); |
||
72 | } |
||
73 | |||
74 | $result = $this->address->delete($id); |
||
75 | } |
||
76 | |||
77 | if (empty($result)) { |
||
78 | $this->errorAndExit($this->text('Unexpected result')); |
||
79 | } |
||
80 | |||
81 | $this->output(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Callback for "address-add" command |
||
86 | */ |
||
87 | public function cmdAddAddress() |
||
97 | |||
98 | /** |
||
99 | * Callback for "address-update" command |
||
100 | */ |
||
101 | public function cmdUpdateAddress() |
||
121 | |||
122 | /** |
||
123 | * Returns an array of addresses |
||
124 | * @return array |
||
125 | */ |
||
126 | protected function getListAddress() |
||
150 | |||
151 | /** |
||
152 | * Output table format |
||
153 | * @param array $items |
||
154 | */ |
||
155 | protected function outputFormatTableAddress(array $items) |
||
180 | |||
181 | /** |
||
182 | * Add a new address |
||
183 | */ |
||
184 | protected function addAddress() |
||
197 | |||
198 | /** |
||
199 | * Updates an address |
||
200 | * @param string $address_id |
||
201 | */ |
||
202 | protected function updateAddress($address_id) |
||
208 | |||
209 | /** |
||
210 | * Add a new address at once |
||
211 | */ |
||
212 | protected function submitAddAddress() |
||
219 | |||
220 | /** |
||
221 | * Add a new address step by step |
||
222 | */ |
||
223 | protected function wizardAddAddress() |
||
247 | |||
248 | } |
||
249 |