cart.php (4592B)
1 <?php 2 class ControllerCommonCart extends Controller { 3 public function index() { 4 $this->load->language('common/cart'); 5 6 // Totals 7 $this->load->model('setting/extension'); 8 9 $totals = array(); 10 $taxes = $this->cart->getTaxes(); 11 $total = 0; 12 13 // Because __call can not keep var references so we put them into an array. 14 $total_data = array( 15 'totals' => &$totals, 16 'taxes' => &$taxes, 17 'total' => &$total 18 ); 19 20 // Display prices 21 if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { 22 $sort_order = array(); 23 24 $results = $this->model_setting_extension->getExtensions('total'); 25 26 foreach ($results as $key => $value) { 27 $sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order'); 28 } 29 30 array_multisort($sort_order, SORT_ASC, $results); 31 32 foreach ($results as $result) { 33 if ($this->config->get('total_' . $result['code'] . '_status')) { 34 $this->load->model('extension/total/' . $result['code']); 35 36 // We have to put the totals in an array so that they pass by reference. 37 $this->{'model_extension_total_' . $result['code']}->getTotal($total_data); 38 } 39 } 40 41 $sort_order = array(); 42 43 foreach ($totals as $key => $value) { 44 $sort_order[$key] = $value['sort_order']; 45 } 46 47 array_multisort($sort_order, SORT_ASC, $totals); 48 } 49 50 $data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency'])); 51 52 $this->load->model('tool/image'); 53 $this->load->model('tool/upload'); 54 55 $data['products'] = array(); 56 57 foreach ($this->cart->getProducts() as $product) { 58 if ($product['image']) { 59 $image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height')); 60 } else { 61 $image = ''; 62 } 63 64 $option_data = array(); 65 66 foreach ($product['option'] as $option) { 67 if ($option['type'] != 'file') { 68 $value = $option['value']; 69 } else { 70 $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); 71 72 if ($upload_info) { 73 $value = $upload_info['name']; 74 } else { 75 $value = ''; 76 } 77 } 78 79 $option_data[] = array( 80 'name' => $option['name'], 81 'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value), 82 'type' => $option['type'] 83 ); 84 } 85 86 // Display prices 87 if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { 88 $unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')); 89 90 $price = $this->currency->format($unit_price, $this->session->data['currency']); 91 $total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']); 92 } else { 93 $price = false; 94 $total = false; 95 } 96 97 $data['products'][] = array( 98 'cart_id' => $product['cart_id'], 99 'thumb' => $image, 100 'name' => $product['name'], 101 'model' => $product['model'], 102 'option' => $option_data, 103 'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''), 104 'quantity' => $product['quantity'], 105 'price' => $price, 106 'total' => $total, 107 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']) 108 ); 109 } 110 111 // Gift Voucher 112 $data['vouchers'] = array(); 113 114 if (!empty($this->session->data['vouchers'])) { 115 foreach ($this->session->data['vouchers'] as $key => $voucher) { 116 $data['vouchers'][] = array( 117 'key' => $key, 118 'description' => $voucher['description'], 119 'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency']) 120 ); 121 } 122 } 123 124 $data['totals'] = array(); 125 126 foreach ($totals as $total) { 127 $data['totals'][] = array( 128 'title' => $total['title'], 129 'text' => $this->currency->format($total['value'], $this->session->data['currency']), 130 ); 131 } 132 133 $data['cart'] = $this->url->link('checkout/cart'); 134 $data['checkout'] = $this->url->link('checkout/checkout', '', true); 135 136 return $this->load->view('common/cart', $data); 137 } 138 139 public function info() { 140 $this->response->setOutput($this->index()); 141 } 142 }