public function sidebar()
{
$this->load->language('checkout/checkout');
$this->load->language('extension/payment/klarna_checkout');
$this->load->model('extension/payment/klarna_checkout');
if (!$this->config->get('klarna_checkout_status')) {
return false;
}
$this->setPayment();
$this->setShipping();
// Shipping
$unset_shipping_method = true;
if (isset($this->session->data['shipping_method']) && isset($this->session->data['shipping_methods'])) {
foreach ($this->session->data['shipping_methods'] as $shipping_method) {
if ($shipping_method['quote']) {
foreach ($shipping_method['quote'] as $quote) {
if ($quote['code'] == $this->session->data['shipping_method']['code']) {
$unset_shipping_method = false;
break 2;
}
}
}
}
}
if ($unset_shipping_method) {
unset($this->session->data['shipping_method']);
}
if ((!isset($this->session->data['shipping_method']) || empty($this->session->data['shipping_method'])) && (isset($this->session->data['shipping_methods']) && !empty($this->session->data['shipping_methods']))) {
$this->session->data['shipping_method'] = $this->model_extension_payment_klarna_checkout->getDefaultShippingMethod($this->session->data['shipping_methods']);
}
$data['text_choose_shipping_method'] = $this->language->get('text_choose_shipping_method');
$data['text_shipping_method'] = $this->language->get('text_shipping_method');
$data['text_no_shipping'] = $this->language->get('error_no_shipping');
$data['button_remove'] = $this->language->get('button_remove');
$data['shipping_required'] = $this->cart->hasShipping();
if (isset($this->session->data['shipping_methods'])) {
$data['shipping_methods'] = $this->session->data['shipping_methods'];
} else {
unset($data['shipping_method']);
$data['shipping_methods'] = array();
}
if (isset($this->session->data['shipping_method']['code'])) {
$data['code'] = $this->session->data['shipping_method']['code'];
} else {
$data['code'] = '';
}
$this->load->model('tool/image');
$this->load->model('tool/upload');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_cart_width'), $this->config->get($this->config->get('config_theme') . '_image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value, 'type' => $option['type']);
}
// Display prices
if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
// Display prices
if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']);
} else {
$total = false;
}
$data['products'][] = array('cart_id' => $product['cart_id'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'recurring' => $product['recurring'] ? $product['recurring']['name'] : '', 'quantity' => $product['quantity'], 'price' => $price, 'total' => $total, 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']));
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array('key' => $key, 'description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount'], $this->session->data['currency']));
}
}
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array('totals' => &$totals, 'taxes' => &$taxes, 'total' => &$total);
$this->load->model('extension/extension');
$sort_order = array();
$results = $this->model_extension_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
$data['totals'] = array();
foreach ($totals as $total) {
$data['totals'][] = array('title' => $total['title'], 'text' => $this->currency->format($total['value'], $this->session->data['currency']));
}
$this->response->setOutput($this->load->view('extension/payment/klarna_checkout_sidebar', $data));
}