コード例 #1
0
 public function getTotal(&$totalData, &$total, &$taxes, $chosenOnes = false)
 {
     /// Checking order totals and defining local shipping cost per supplier
     $suppliers = array();
     $currentSupplierId = null;
     $currentSupplierOrderTotal = 0;
     foreach (CartDAO::getInstance()->getProducts($chosenOnes) as $product) {
         /// Show local shipping cost
         if ($currentSupplierId != $product['supplierId']) {
             $this->checkLocalShipping($currentSupplierId, $currentSupplierOrderTotal, $suppliers);
             $currentSupplierId = $product['supplierId'];
             $suppliers[$currentSupplierId]['shippingCost'] = $product['supplierShippingCost'];
             $suppliers[$currentSupplierId]['freeShippingThreshold'] = $product['supplierFreeShippingThreshold'];
             $currentSupplierOrderTotal = $product['total'];
         } else {
             $currentSupplierOrderTotal += $product['total'];
         }
     }
     $this->checkLocalShipping($currentSupplierId, $currentSupplierOrderTotal, $suppliers);
     /// Summing up the local shipping cost
     $localShippingTotal = 0;
     foreach ($suppliers as $supplier) {
         $localShippingTotal += $supplier['shippingCost'];
     }
     /// Filling out result
     $this->load->language('total/localShipping');
     $totalData[] = array('code' => 'localShipping', 'title' => $this->getLanguage()->get('LOCAL_SHIPPING'), 'text' => $this->getCurrency()->format($localShippingTotal), 'value' => $localShippingTotal, 'sort_order' => $this->config->get('localShipping_sort_order'));
     $total += $localShippingTotal;
 }
コード例 #2
0
ファイル: cart.php プロジェクト: ralfeus/moomi-daeri.com
 public function index()
 {
     $this->language->load('checkout/cart');
     // Remove
     if (isset($this->request->get['remove'])) {
         $this->getCart()->remove($this->request->get['remove']);
         $this->redirect($this->url->link('checkout/cart'));
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         if (isset($this->request->post['quantity'])) {
             if (!is_array($this->request->post['quantity'])) {
                 if (isset($this->request->post['option'])) {
                     $option = $this->request->post['option'];
                 } else {
                     $option = array();
                 }
                 $this->getCart()->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
             } else {
                 foreach ($this->request->post['quantity'] as $key => $value) {
                     $this->cart->update($key, $value);
                 }
             }
         }
         if (isset($this->request->post['remove'])) {
             foreach ($this->request->post['remove'] as $key) {
                 $this->cart->remove($key);
             }
         }
         if (isset($this->request->post['voucher']) && $this->request->post['voucher']) {
             foreach ($this->request->post['voucher'] as $key) {
                 if (isset($this->session->data['vouchers'][$key])) {
                     unset($this->session->data['vouchers'][$key]);
                 }
             }
         }
         if (isset($this->request->post['redirect'])) {
             $this->session->data['redirect'] = $this->request->post['redirect'];
         }
         if (isset($this->request->post['quantity']) || isset($this->request->post['remove']) || isset($this->request->post['voucher'])) {
             unset($this->session->data['shipping_methods']);
             unset($this->session->data['shipping_method']);
             unset($this->session->data['payment_methods']);
             unset($this->session->data['payment_method']);
             unset($this->session->data['reward']);
             $this->redirect($this->url->link('checkout/cart'));
         }
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('href' => $this->url->link('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->data['breadcrumbs'][] = array('href' => $this->url->link('checkout/cart'), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator'));
     if ($this->cart->hasProducts() || isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_select'] = $this->language->get('text_select');
         $this->data['text_weight'] = $this->language->get('text_weight');
         $this->data['column_remove'] = $this->language->get('column_remove');
         $this->data['column_image'] = $this->language->get('column_image');
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['button_update'] = $this->language->get('button_update');
         $this->data['button_remove'] = $this->language->get('button_remove');
         $this->data['button_shopping'] = $this->language->get('button_shopping');
         $this->data['button_checkout'] = $this->language->get('button_checkout');
         $this->data['textBrand'] = $this->language->get('MANUFACTURER');
         $this->data['textCheckoutSelected'] = $this->language->get('CHECKOUT_SELECTED');
         if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
             $this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
         } else {
             $this->data['attention'] = '';
         }
         if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
             $this->data['error_warning'] = $this->language->get('error_stock');
         } elseif (isset($this->session->data['error'])) {
             $this->data['error_warning'] = $this->session->data['error'];
             unset($this->session->data['error']);
         } else {
             $this->data['error_warning'] = '';
         }
         if (isset($this->session->data['success'])) {
             $this->data['success'] = $this->session->data['success'];
             unset($this->session->data['success']);
         } else {
             $this->data['success'] = '';
         }
         if ($this->config->get('config_cart_weight')) {
             $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));
         } else {
             $this->data['weight'] = false;
         }
         $this->load->model('tool/image');
         $this->data['products'] = array();
         $products = CartDAO::getInstance()->getProducts();
         uasort($products, function ($a, $b) {
             if ($a['supplierId'] < $b['supplierId']) {
                 return -1;
             } elseif ($a['supplierId'] > $b['supplierId']) {
                 return 1;
             } else {
                 return 0;
             }
         });
         $currentSupplierId = null;
         $currentSupplierOrderTotal = 0;
         foreach ($products as $product) {
             $product_total = 0;
             foreach ($products as $product_2) {
                 if ($product_2['product_id'] == $product['product_id']) {
                     $product_total += $product_2['quantity'];
                 }
             }
             if ($product['minimum'] > $product_total) {
                 $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
             }
             //print_r($product);
             //$this->load->model('shop/general');
             //$order_product = $this->model_shop_general->getOrderProduct($pro)
             /*if($product['image'] == '' || $product['image'] == "data/event/agent-moomidae.jpg") {
                 $options = $this->modelOrderItem->getOptions($product['order_product_id']);
                 $itemUrl = !empty($options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'])
                 ? $options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'] : '';
                 $product['image'] = !empty($itemUrl) ? $itemUrl : $product['image'];
               }*/
             $product_image = ProductDAO::getInstance()->getImage($product['product_id']);
             if ($product['image']) {
                 $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
             } else {
                 $image = $this->model_tool_image->resize($product_image, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
             }
             $option_data = array();
             foreach ($product['option'] as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['option_value']));
                 } else {
                     $this->load->library('encryption');
                     $encryption = new Encryption($this->config->get('config_encryption'));
                     $file = substr($encryption->decrypt($option['option_value']), 0, strrpos($encryption->decrypt($option['option_value']), '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($file));
                 }
             }
             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')));
             } else {
                 $price = false;
             }
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $total = $this->currency->format($this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $total = false;
             }
             $this->data['products'][] = array('actionDeleteUrl' => $this->url->link('checkout/cart/removeItem', 'key=' . urlencode($product['key']), 'SSL'), 'key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'stock' => $product['stock'], 'reward' => $product['reward'] ? sprintf($this->language->get('text_reward'), $product['reward']) : '', 'price' => $price, 'total' => $total, 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), 'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key']), 'supplierId' => $product['supplierId']);
             /// Show local shipping cost
             if ($currentSupplierId != $product['supplierId']) {
                 if (!is_null($currentSupplierId)) {
                     $this->checkLocalShipping($currentSupplierId, $currentSupplierOrderTotal);
                 }
                 $currentSupplierId = $product['supplierId'];
                 $this->data['suppliers'][$currentSupplierId]['name'] = $product['brand'];
                 $this->data['suppliers'][$currentSupplierId]['shippingCost'] = $product['supplierShippingCost'];
                 $this->data['suppliers'][$currentSupplierId]['freeShippingThreshold'] = $product['supplierFreeShippingThreshold'];
                 $currentSupplierOrderTotal = $product['total'];
             } else {
                 $currentSupplierOrderTotal += $product['total'];
             }
         }
         /// Post-products last supplier check
         $this->checkLocalShipping($currentSupplierId, $currentSupplierOrderTotal);
         // Gift Voucher
         $this->data['vouchers'] = array();
         if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
             foreach ($this->session->data['vouchers'] as $key => $voucher) {
                 $this->data['vouchers'][] = array('key' => $key, 'description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']));
             }
         }
         $total_data = array();
         $total = 0;
         $taxes = $this->getCart()->getTaxes();
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $this->load->model('setting/extension');
             $sort_order = array();
             $results = \model\setting\ExtensionDAO::getInstance()->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('total/' . $result['code']);
                     $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
                 }
             }
             $sort_order = array();
             foreach ($total_data as $key => $value) {
                 $sort_order[$key] = $value['sort_order'];
             }
             array_multisort($sort_order, SORT_ASC, $total_data);
         }
         $this->data['totals'] = $total_data;
         // Modules
         $this->data['modules'] = array();
         if (isset($results)) {
             foreach ($results as $result) {
                 if ($this->config->get($result['code'] . '_status') && file_exists(DIR_APPLICATION . 'controller/total/' . $result['code'] . '.php')) {
                     $this->data['modules'][] = $this->getChild('total/' . $result['code']);
                 }
             }
         }
         if (isset($this->session->data['redirect'])) {
             $this->data['continue'] = $this->session->data['redirect'];
             unset($this->session->data['redirect']);
         } else {
             $this->data['continue'] = $this->url->link('common/home');
         }
         $this->data['urlCheckout'] = $this->url->link('checkout/checkout', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl.php')) {
             $this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl.php';
         } else {
             $this->template = 'default/template/checkout/cart.tpl.php';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     } else {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_error'] = $this->language->get('text_empty');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['continue'] = $this->url->link('common/home');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     }
 }