/catalog/controller/checkout/checkout.php

https://gitlab.com/hazelnuts23/unitedfoodstuff · PHP · 147 lines · 111 code · 32 blank · 4 comment · 20 complexity · 33a88104915042dec7f37ac31747ae0e MD5 · raw file

  1. <?php
  2. class ControllerCheckoutCheckout extends Controller {
  3. public function index() {
  4. // Validate cart has products and has stock.
  5. if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
  6. $this->response->redirect($this->url->link('checkout/cart'));
  7. }
  8. // Validate minimum quantity requirements.
  9. $products = $this->cart->getProducts();
  10. foreach ($products as $product) {
  11. $product_total = 0;
  12. foreach ($products as $product_2) {
  13. if ($product_2['product_id'] == $product['product_id']) {
  14. $product_total += $product_2['quantity'];
  15. }
  16. }
  17. if ($product['minimum'] > $product_total) {
  18. $this->response->redirect($this->url->link('checkout/cart'));
  19. }
  20. }
  21. $this->load->language('checkout/checkout');
  22. $this->document->setTitle($this->language->get('heading_title'));
  23. $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
  24. $this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
  25. $this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
  26. // Required by klarna
  27. if ($this->config->get('klarna_account') || $this->config->get('klarna_invoice')) {
  28. $this->document->addScript('http://cdn.klarna.com/public/kitt/toc/v1.0/js/klarna.terms.min.js');
  29. }
  30. $data['breadcrumbs'] = array();
  31. $data['breadcrumbs'][] = array(
  32. 'text' => $this->language->get('text_home'),
  33. 'href' => $this->url->link('common/home')
  34. );
  35. $data['breadcrumbs'][] = array(
  36. 'text' => $this->language->get('text_cart'),
  37. 'href' => $this->url->link('checkout/cart')
  38. );
  39. $data['breadcrumbs'][] = array(
  40. 'text' => $this->language->get('heading_title'),
  41. 'href' => $this->url->link('checkout/checkout', '', 'SSL')
  42. );
  43. $data['heading_title'] = $this->language->get('heading_title');
  44. $data['text_checkout_option'] = $this->language->get('text_checkout_option');
  45. $data['text_checkout_account'] = $this->language->get('text_checkout_account');
  46. $data['text_checkout_payment_address'] = $this->language->get('text_checkout_payment_address');
  47. $data['text_checkout_shipping_address'] = $this->language->get('text_checkout_shipping_address');
  48. $data['text_checkout_shipping_method'] = $this->language->get('text_checkout_shipping_method');
  49. $data['text_checkout_payment_method'] = $this->language->get('text_checkout_payment_method');
  50. $data['text_checkout_confirm'] = $this->language->get('text_checkout_confirm');
  51. if (isset($this->session->data['error'])) {
  52. $data['error_warning'] = $this->session->data['error'];
  53. unset($this->session->data['error']);
  54. } else {
  55. $data['error_warning'] = '';
  56. }
  57. $data['logged'] = $this->customer->isLogged();
  58. if (isset($this->session->data['account'])) {
  59. $data['account'] = $this->session->data['account'];
  60. } else {
  61. $data['account'] = '';
  62. }
  63. $data['shipping_required'] = $this->cart->hasShipping();
  64. $data['column_left'] = $this->load->controller('common/column_left');
  65. $data['column_right'] = $this->load->controller('common/column_right');
  66. $data['content_top'] = $this->load->controller('common/content_top');
  67. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  68. $data['footer'] = $this->load->controller('common/footer');
  69. $data['header'] = $this->load->controller('common/header');
  70. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/checkout.tpl')) {
  71. $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/checkout/checkout.tpl', $data));
  72. } else {
  73. $this->response->setOutput($this->load->view('default/template/checkout/checkout.tpl', $data));
  74. }
  75. }
  76. public function country() {
  77. $json = array();
  78. $this->load->model('localisation/country');
  79. $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
  80. if ($country_info) {
  81. $this->load->model('localisation/zone');
  82. $json = array(
  83. 'country_id' => $country_info['country_id'],
  84. 'name' => $country_info['name'],
  85. 'iso_code_2' => $country_info['iso_code_2'],
  86. 'iso_code_3' => $country_info['iso_code_3'],
  87. 'address_format' => $country_info['address_format'],
  88. 'postcode_required' => $country_info['postcode_required'],
  89. 'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
  90. 'status' => $country_info['status']
  91. );
  92. }
  93. $this->response->addHeader('Content-Type: application/json');
  94. $this->response->setOutput(json_encode($json));
  95. }
  96. public function customfield() {
  97. $json = array();
  98. $this->load->model('account/custom_field');
  99. // Customer Group
  100. 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'))) {
  101. $customer_group_id = $this->request->get['customer_group_id'];
  102. } else {
  103. $customer_group_id = $this->config->get('config_customer_group_id');
  104. }
  105. $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
  106. foreach ($custom_fields as $custom_field) {
  107. $json[] = array(
  108. 'custom_field_id' => $custom_field['custom_field_id'],
  109. 'required' => $custom_field['required']
  110. );
  111. }
  112. $this->response->addHeader('Content-Type: application/json');
  113. $this->response->setOutput(json_encode($json));
  114. }
  115. }