Conditions | 41 |
Paths | > 20000 |
Total Lines | 346 |
Code Lines | 231 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | public function index() |
||
26 | { |
||
27 | $redirect = ''; |
||
28 | |||
29 | if ($this->cart->hasShipping()) { |
||
30 | // Validate if shipping address has been set. |
||
31 | if (!isset($this->session->data['shipping_address'])) { |
||
32 | $redirect = $this->url->link('checkout/checkout', '', true); |
||
33 | } |
||
34 | |||
35 | // Validate if shipping method has been set. |
||
36 | if (!isset($this->session->data['shipping_method'])) { |
||
37 | $redirect = $this->url->link('checkout/checkout', '', true); |
||
38 | } |
||
39 | } else { |
||
40 | unset($this->session->data['shipping_address']); |
||
41 | unset($this->session->data['shipping_method']); |
||
42 | unset($this->session->data['shipping_methods']); |
||
43 | } |
||
44 | |||
45 | // Validate if payment address has been set. |
||
46 | if (!isset($this->session->data['payment_address'])) { |
||
47 | $redirect = $this->url->link('checkout/checkout', '', true); |
||
48 | } |
||
49 | |||
50 | // Validate if payment method has been set. |
||
51 | if (!isset($this->session->data['payment_method'])) { |
||
52 | $redirect = $this->url->link('checkout/checkout', '', true); |
||
53 | } |
||
54 | |||
55 | // Validate cart has products and has stock. |
||
56 | if ((!$this->cart->hasProducts()) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { |
||
57 | $redirect = $this->url->link('checkout/cart'); |
||
58 | } |
||
59 | |||
60 | // Validate minimum quantity requirements. |
||
61 | $products = $this->cart->getProducts(); |
||
62 | |||
63 | foreach ($products as $product) { |
||
64 | $product_total = 0; |
||
65 | |||
66 | foreach ($products as $product_2) { |
||
67 | if ($product_2['product_id'] == $product['product_id']) { |
||
68 | $product_total += $product_2['quantity']; |
||
69 | } |
||
70 | } |
||
71 | |||
72 | if ($product['minimum'] > $product_total) { |
||
73 | $redirect = $this->url->link('checkout/cart'); |
||
74 | |||
75 | break; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | if (!$redirect) { |
||
80 | $order_data = array(); |
||
81 | |||
82 | $totals = array(); |
||
83 | $total = 0; |
||
84 | |||
85 | // Because __call can not keep var references so we put them into an array. |
||
86 | $total_data = array( |
||
87 | 'totals' => &$totals, |
||
88 | 'total' => &$total |
||
89 | ); |
||
90 | |||
91 | $this->load->model('extension/extension'); |
||
92 | |||
93 | $sort_order = array(); |
||
94 | |||
95 | $results = $this->model_extension_extension->getExtensions('total'); |
||
96 | |||
97 | foreach ($results as $key => $value) { |
||
98 | $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); |
||
99 | } |
||
100 | |||
101 | array_multisort($sort_order, SORT_ASC, $results); |
||
102 | |||
103 | foreach ($results as $result) { |
||
104 | if ($this->config->get($result['code'] . '_status')) { |
||
105 | $this->load->model('extension/total/' . $result['code']); |
||
106 | |||
107 | // We have to put the totals in an array so that they pass by reference. |
||
108 | $this->{'model_extension_total_' . $result['code']}->getTotal($total_data); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | $sort_order = array(); |
||
113 | |||
114 | foreach ($totals as $key => $value) { |
||
115 | $sort_order[$key] = $value['sort_order']; |
||
116 | } |
||
117 | |||
118 | array_multisort($sort_order, SORT_ASC, $totals); |
||
119 | |||
120 | $order_data['totals'] = $totals; |
||
121 | |||
122 | $this->load->language('checkout/checkout'); |
||
123 | |||
124 | $order_data['invoice_prefix'] = $this->config->get('config_invoice_prefix'); |
||
125 | $order_data['store_name'] = $this->config->get('config_name'); |
||
126 | |||
127 | $order_data['store_url'] = '/'; |
||
128 | |||
129 | if ($this->customer->isLogged()) { |
||
130 | $this->load->model('account/customer'); |
||
131 | |||
132 | $customer_info = $this->model_account_customer->getCustomer($this->customer->getId()); |
||
133 | |||
134 | $order_data['customer_id'] = $this->customer->getId(); |
||
135 | $order_data['customer_group_id'] = $customer_info['customer_group_id']; |
||
136 | $order_data['firstname'] = $customer_info['firstname']; |
||
137 | $order_data['lastname'] = $customer_info['lastname']; |
||
138 | $order_data['email'] = $customer_info['email']; |
||
139 | $order_data['telephone'] = $customer_info['telephone']; |
||
140 | $order_data['fax'] = $customer_info['fax']; |
||
141 | $order_data['custom_field'] = json_decode($customer_info['custom_field'], true); |
||
142 | } elseif (isset($this->session->data['guest'])) { |
||
143 | $order_data['customer_id'] = 0; |
||
144 | $order_data['customer_group_id'] = $this->session->data['guest']['customer_group_id']; |
||
145 | $order_data['firstname'] = $this->session->data['guest']['firstname']; |
||
146 | $order_data['lastname'] = $this->session->data['guest']['lastname']; |
||
147 | $order_data['email'] = $this->session->data['guest']['email']; |
||
148 | $order_data['telephone'] = $this->session->data['guest']['telephone']; |
||
149 | $order_data['fax'] = $this->session->data['guest']['fax']; |
||
150 | $order_data['custom_field'] = $this->session->data['guest']['custom_field']; |
||
151 | } |
||
152 | |||
153 | $order_data['payment_firstname'] = $this->session->data['payment_address']['firstname']; |
||
154 | $order_data['payment_lastname'] = $this->session->data['payment_address']['lastname']; |
||
155 | $order_data['payment_company'] = $this->session->data['payment_address']['company']; |
||
156 | $order_data['payment_address_1'] = $this->session->data['payment_address']['address_1']; |
||
157 | $order_data['payment_address_2'] = $this->session->data['payment_address']['address_2']; |
||
158 | $order_data['payment_city'] = $this->session->data['payment_address']['city']; |
||
159 | $order_data['payment_postcode'] = $this->session->data['payment_address']['postcode']; |
||
160 | $order_data['payment_zone'] = $this->session->data['payment_address']['zone']; |
||
161 | $order_data['payment_zone_id'] = $this->session->data['payment_address']['zone_id']; |
||
162 | $order_data['payment_country'] = $this->session->data['payment_address']['country']; |
||
163 | $order_data['payment_country_id'] = $this->session->data['payment_address']['country_id']; |
||
164 | $order_data['payment_address_format'] = $this->session->data['payment_address']['address_format']; |
||
165 | $order_data['payment_custom_field'] = (isset($this->session->data['payment_address']['custom_field']) ? $this->session->data['payment_address']['custom_field'] : array()); |
||
166 | |||
167 | if (isset($this->session->data['payment_method']['title'])) { |
||
168 | $order_data['payment_method'] = $this->session->data['payment_method']['title']; |
||
169 | } else { |
||
170 | $order_data['payment_method'] = ''; |
||
171 | } |
||
172 | |||
173 | if (isset($this->session->data['payment_method']['code'])) { |
||
174 | $order_data['payment_code'] = $this->session->data['payment_method']['code']; |
||
175 | } else { |
||
176 | $order_data['payment_code'] = ''; |
||
177 | } |
||
178 | |||
179 | if ($this->cart->hasShipping()) { |
||
180 | $order_data['shipping_firstname'] = $this->session->data['shipping_address']['firstname']; |
||
181 | $order_data['shipping_lastname'] = $this->session->data['shipping_address']['lastname']; |
||
182 | $order_data['shipping_company'] = $this->session->data['shipping_address']['company']; |
||
183 | $order_data['shipping_address_1'] = $this->session->data['shipping_address']['address_1']; |
||
184 | $order_data['shipping_address_2'] = $this->session->data['shipping_address']['address_2']; |
||
185 | $order_data['shipping_city'] = $this->session->data['shipping_address']['city']; |
||
186 | $order_data['shipping_postcode'] = $this->session->data['shipping_address']['postcode']; |
||
187 | $order_data['shipping_zone'] = $this->session->data['shipping_address']['zone']; |
||
188 | $order_data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id']; |
||
189 | $order_data['shipping_country'] = $this->session->data['shipping_address']['country']; |
||
190 | $order_data['shipping_country_id'] = $this->session->data['shipping_address']['country_id']; |
||
191 | $order_data['shipping_address_format'] = $this->session->data['shipping_address']['address_format']; |
||
192 | $order_data['shipping_custom_field'] = (isset($this->session->data['shipping_address']['custom_field']) ? $this->session->data['shipping_address']['custom_field'] : array()); |
||
193 | |||
194 | if (isset($this->session->data['shipping_method']['title'])) { |
||
195 | $order_data['shipping_method'] = $this->session->data['shipping_method']['title']; |
||
196 | } else { |
||
197 | $order_data['shipping_method'] = ''; |
||
198 | } |
||
199 | |||
200 | if (isset($this->session->data['shipping_method']['code'])) { |
||
201 | $order_data['shipping_code'] = $this->session->data['shipping_method']['code']; |
||
202 | } else { |
||
203 | $order_data['shipping_code'] = ''; |
||
204 | } |
||
205 | } else { |
||
206 | $order_data['shipping_firstname'] = ''; |
||
207 | $order_data['shipping_lastname'] = ''; |
||
208 | $order_data['shipping_company'] = ''; |
||
209 | $order_data['shipping_address_1'] = ''; |
||
210 | $order_data['shipping_address_2'] = ''; |
||
211 | $order_data['shipping_city'] = ''; |
||
212 | $order_data['shipping_postcode'] = ''; |
||
213 | $order_data['shipping_zone'] = ''; |
||
214 | $order_data['shipping_zone_id'] = ''; |
||
215 | $order_data['shipping_country'] = ''; |
||
216 | $order_data['shipping_country_id'] = ''; |
||
217 | $order_data['shipping_address_format'] = ''; |
||
218 | $order_data['shipping_custom_field'] = array(); |
||
219 | $order_data['shipping_method'] = ''; |
||
220 | $order_data['shipping_code'] = ''; |
||
221 | } |
||
222 | |||
223 | $order_data['products'] = array(); |
||
224 | |||
225 | foreach ($this->cart->getProducts() as $product) { |
||
226 | $option_data = array(); |
||
227 | |||
228 | foreach ($product['option'] as $option) { |
||
229 | $option_data[] = array( |
||
230 | 'product_option_id' => $option['product_option_id'], |
||
231 | 'product_option_value_id' => $option['product_option_value_id'], |
||
232 | 'option_id' => $option['option_id'], |
||
233 | 'option_value_id' => $option['option_value_id'], |
||
234 | 'name' => $option['name'], |
||
235 | 'value' => $option['value'], |
||
236 | 'type' => $option['type'] |
||
237 | ); |
||
238 | } |
||
239 | |||
240 | $order_data['products'][] = array( |
||
241 | 'product_id' => $product['product_id'], |
||
242 | 'name' => $product['name'], |
||
243 | 'model' => $product['model'], |
||
244 | 'option' => $option_data, |
||
245 | 'download' => $product['download'], |
||
246 | 'quantity' => $product['quantity'], |
||
247 | 'subtract' => $product['subtract'], |
||
248 | 'price' => $product['price'], |
||
249 | 'total' => $product['total'], |
||
250 | 'reward' => $product['reward'] |
||
251 | ); |
||
252 | } |
||
253 | |||
254 | $order_data['comment'] = $this->session->data['comment']; |
||
255 | $order_data['total'] = $total_data['total']; |
||
256 | |||
257 | if (isset($this->request->cookie['tracking'])) { |
||
258 | $order_data['tracking'] = $this->request->cookie['tracking']; |
||
259 | |||
260 | $subtotal = $this->cart->getSubTotal(); |
||
261 | |||
262 | $order_data['commission'] = 0; |
||
263 | |||
264 | // Marketing |
||
265 | $this->load->model('checkout/marketing'); |
||
266 | |||
267 | $marketing_info = $this->model_checkout_marketing->getMarketingByCode($this->request->cookie['tracking']); |
||
268 | |||
269 | if ($marketing_info) { |
||
270 | $order_data['marketing_id'] = $marketing_info['marketing_id']; |
||
271 | } else { |
||
272 | $order_data['marketing_id'] = 0; |
||
273 | } |
||
274 | } else { |
||
275 | $order_data['commission'] = 0; |
||
276 | $order_data['marketing_id'] = 0; |
||
277 | $order_data['tracking'] = ''; |
||
278 | } |
||
279 | |||
280 | $order_data['language_id'] = $this->config->get('config_language_id'); |
||
281 | $order_data['currency_id'] = $this->currency->getId($this->session->data['currency']); |
||
282 | $order_data['currency_code'] = $this->session->data['currency']; |
||
283 | $order_data['currency_value'] = $this->currency->getValue($this->session->data['currency']); |
||
284 | $order_data['ip'] = $this->request->server['REMOTE_ADDR']; |
||
285 | |||
286 | if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) { |
||
287 | $order_data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR']; |
||
288 | } elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) { |
||
289 | $order_data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP']; |
||
290 | } else { |
||
291 | $order_data['forwarded_ip'] = ''; |
||
292 | } |
||
293 | |||
294 | if (isset($this->request->server['HTTP_USER_AGENT'])) { |
||
295 | $order_data['user_agent'] = $this->request->server['HTTP_USER_AGENT']; |
||
296 | } else { |
||
297 | $order_data['user_agent'] = ''; |
||
298 | } |
||
299 | |||
300 | if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) { |
||
301 | $order_data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE']; |
||
302 | } else { |
||
303 | $order_data['accept_language'] = ''; |
||
304 | } |
||
305 | |||
306 | $this->load->model('checkout/order'); |
||
307 | |||
308 | $this->session->data['order_id'] = $this->model_checkout_order->addOrder($order_data); |
||
309 | |||
310 | $data['column_name'] = $this->language->get('column_name'); |
||
311 | $data['column_model'] = $this->language->get('column_model'); |
||
312 | $data['column_quantity'] = $this->language->get('column_quantity'); |
||
313 | $data['column_price'] = $this->language->get('column_price'); |
||
314 | $data['column_total'] = $this->language->get('column_total'); |
||
315 | |||
316 | $this->load->model('tool/upload'); |
||
317 | |||
318 | $data['products'] = array(); |
||
319 | |||
320 | foreach ($this->cart->getProducts() as $product) { |
||
321 | $option_data = array(); |
||
322 | |||
323 | foreach ($product['option'] as $option) { |
||
324 | if ($option['type'] != 'file') { |
||
325 | $value = $option['value']; |
||
326 | } else { |
||
327 | $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); |
||
328 | |||
329 | if ($upload_info) { |
||
330 | $value = $upload_info['name']; |
||
331 | } else { |
||
332 | $value = ''; |
||
333 | } |
||
334 | } |
||
335 | |||
336 | $option_data[] = array( |
||
337 | 'name' => $option['name'], |
||
338 | 'value' => (\voku\helper\UTF8::strlen($value) > 20 ? \voku\helper\UTF8::substr($value, 0, 20) . '..' : $value) |
||
339 | ); |
||
340 | } |
||
341 | |||
342 | $data['products'][] = array( |
||
343 | 'cart_id' => $product['cart_id'], |
||
344 | 'product_id' => $product['product_id'], |
||
345 | 'name' => $product['name'], |
||
346 | 'model' => $product['model'], |
||
347 | 'option' => $option_data, |
||
348 | 'quantity' => $product['quantity'], |
||
349 | 'subtract' => $product['subtract'], |
||
350 | 'price' => $this->currency->format($product['price'], $this->session->data['currency']), |
||
351 | 'total' => $this->currency->format($product['price'] * $product['quantity'], $this->session->data['currency']), |
||
352 | 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']) |
||
353 | ); |
||
354 | } |
||
355 | |||
356 | $data['totals'] = array(); |
||
357 | |||
358 | foreach ($order_data['totals'] as $total) { |
||
359 | $data['totals'][] = array( |
||
360 | 'title' => $total['title'], |
||
361 | 'text' => $this->currency->format($total['value'], $this->session->data['currency']) |
||
362 | ); |
||
363 | } |
||
364 | |||
365 | $data['payment'] = $this->load->controller('extension/payment/' . $this->session->data['payment_method']['code']); |
||
366 | } else { |
||
367 | $data['redirect'] = $redirect; |
||
368 | } |
||
369 | |||
370 | $this->response->setOutput($this->load->view('checkout/confirm', $data)); |
||
371 | } |
||
373 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.