Nickbur /
Sunrise-CMS
| 1 | <?php |
||
| 2 | |||
| 3 | /* Divine CMS - Open source CMS for widespread use. |
||
| 4 | Copyright (c) 2019 Mykola Burakov ([email protected]) |
||
| 5 | |||
| 6 | See SOURCE.txt for other and additional information. |
||
| 7 | |||
| 8 | This file is part of Divine CMS. |
||
| 9 | |||
| 10 | This program is free software: you can redistribute it and/or modify |
||
| 11 | it under the terms of the GNU General Public License as published by |
||
| 12 | the Free Software Foundation, either version 3 of the License, or |
||
| 13 | (at your option) any later version. |
||
| 14 | |||
| 15 | This program is distributed in the hope that it will be useful, |
||
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 18 | GNU General Public License for more details. |
||
| 19 | |||
| 20 | You should have received a copy of the GNU General Public License |
||
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
||
| 22 | |||
| 23 | class ControllerCheckoutCheckout extends \Divine\Engine\Core\Controller |
||
|
0 ignored issues
–
show
|
|||
| 24 | { |
||
| 25 | public function index() |
||
|
0 ignored issues
–
show
|
|||
| 26 | { |
||
| 27 | // Validate cart has products and has stock. |
||
| 28 | if ((!$this->cart->hasProducts()) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { |
||
| 29 | $this->response->redirect($this->url->link('checkout/cart')); |
||
| 30 | } |
||
| 31 | |||
| 32 | // Validate minimum quantity requirements. |
||
| 33 | $products = $this->cart->getProducts(); |
||
| 34 | |||
| 35 | foreach ($products as $product) { |
||
| 36 | $product_total = 0; |
||
| 37 | |||
| 38 | foreach ($products as $product_2) { |
||
| 39 | if ($product_2['product_id'] == $product['product_id']) { |
||
| 40 | $product_total += $product_2['quantity']; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($product['minimum'] > $product_total) { |
||
| 45 | $this->response->redirect($this->url->link('checkout/cart')); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | $this->load->language('checkout/checkout'); |
||
| 50 | |||
| 51 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 52 | |||
| 53 | $data['breadcrumbs'] = array(); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 54 | |||
| 55 | $data['breadcrumbs'][] = array( |
||
| 56 | 'text' => $this->language->get('text_home'), |
||
| 57 | 'href' => $this->url->link('common/home') |
||
| 58 | ); |
||
| 59 | |||
| 60 | $data['breadcrumbs'][] = array( |
||
| 61 | 'text' => $this->language->get('text_cart'), |
||
| 62 | 'href' => $this->url->link('checkout/cart') |
||
| 63 | ); |
||
| 64 | |||
| 65 | $data['breadcrumbs'][] = array( |
||
| 66 | 'text' => $this->language->get('heading_title'), |
||
| 67 | 'href' => $this->url->link('checkout/checkout', '', true) |
||
| 68 | ); |
||
| 69 | |||
| 70 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 71 | |||
| 72 | $data['text_checkout_option'] = sprintf($this->language->get('text_checkout_option'), 1); |
||
| 73 | $data['text_checkout_account'] = sprintf($this->language->get('text_checkout_account'), 2); |
||
| 74 | $data['text_checkout_payment_address'] = sprintf($this->language->get('text_checkout_payment_address'), 2); |
||
| 75 | $data['text_checkout_shipping_address'] = sprintf($this->language->get('text_checkout_shipping_address'), 3); |
||
| 76 | $data['text_checkout_shipping_method'] = sprintf($this->language->get('text_checkout_shipping_method'), 4); |
||
| 77 | |||
| 78 | if ($this->cart->hasShipping()) { |
||
| 79 | $data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 5); |
||
| 80 | $data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 6); |
||
| 81 | } else { |
||
| 82 | $data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 3); |
||
| 83 | $data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 4); |
||
| 84 | } |
||
| 85 | |||
| 86 | if (isset($this->session->data['error'])) { |
||
| 87 | $data['error_warning'] = $this->session->data['error']; |
||
| 88 | unset($this->session->data['error']); |
||
| 89 | } else { |
||
| 90 | $data['error_warning'] = ''; |
||
| 91 | } |
||
| 92 | |||
| 93 | $data['logged'] = $this->customer->isLogged(); |
||
| 94 | |||
| 95 | if (isset($this->session->data['account'])) { |
||
| 96 | $data['account'] = $this->session->data['account']; |
||
| 97 | } else { |
||
| 98 | $data['account'] = ''; |
||
| 99 | } |
||
| 100 | |||
| 101 | $data['shipping_required'] = $this->cart->hasShipping(); |
||
| 102 | |||
| 103 | $data['column'] = $this->load->controller('common/column'); |
||
| 104 | |||
| 105 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 106 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 107 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 108 | $data['header'] = $this->load->controller('common/header'); |
||
| 109 | |||
| 110 | $this->response->setOutput($this->load->view('checkout/checkout', $data)); |
||
| 111 | } |
||
| 112 | |||
| 113 | public function country() |
||
| 114 | { |
||
| 115 | $json = array(); |
||
| 116 | |||
| 117 | $this->load->model('localisation/country'); |
||
| 118 | |||
| 119 | $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']); |
||
| 120 | |||
| 121 | if ($country_info) { |
||
| 122 | $this->load->model('localisation/zone'); |
||
| 123 | |||
| 124 | $json = array( |
||
| 125 | 'country_id' => $country_info['country_id'], |
||
| 126 | 'name' => $country_info['name'], |
||
| 127 | 'iso_code_2' => $country_info['iso_code_2'], |
||
| 128 | 'iso_code_3' => $country_info['iso_code_3'], |
||
| 129 | 'address_format' => $country_info['address_format'], |
||
| 130 | 'postcode_required' => $country_info['postcode_required'], |
||
| 131 | 'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']), |
||
| 132 | 'status' => $country_info['status'] |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | $this->response->addHeader('Content-Type: application/json'); |
||
| 137 | $this->response->setOutput(json_encode($json)); |
||
| 138 | } |
||
| 139 | |||
| 140 | public function customfield() |
||
| 141 | { |
||
| 142 | $json = array(); |
||
| 143 | |||
| 144 | $this->load->model('account/custom_field'); |
||
| 145 | |||
| 146 | // Customer Group |
||
| 147 | if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) { |
||
| 148 | $customer_group_id = $this->request->get['customer_group_id']; |
||
| 149 | } else { |
||
| 150 | $customer_group_id = $this->config->get('config_customer_group_id'); |
||
| 151 | } |
||
| 152 | |||
| 153 | $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id); |
||
| 154 | |||
| 155 | foreach ($custom_fields as $custom_field) { |
||
| 156 | $json[] = array( |
||
| 157 | 'custom_field_id' => $custom_field['custom_field_id'], |
||
| 158 | 'required' => $custom_field['required'] |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 162 | $this->response->addHeader('Content-Type: application/json'); |
||
| 163 | $this->response->setOutput(json_encode($json)); |
||
| 164 | } |
||
| 165 | } |
||
| 166 |
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.