diff --git a/install.xml b/install.xml index ba1b9fd..ce9a4b3 100644 --- a/install.xml +++ b/install.xml @@ -11,7 +11,7 @@ https://www.myparcel.nl/ - + diff --git a/upload/admin/controller/extension/shipping/myparcel_shipping.php b/upload/admin/controller/extension/shipping/myparcel_shipping.php index df8b865..6a39a5a 100644 --- a/upload/admin/controller/extension/shipping/myparcel_shipping.php +++ b/upload/admin/controller/extension/shipping/myparcel_shipping.php @@ -78,6 +78,16 @@ public function index() { $data['shipping_myparcel_shipping_cost'] = $this->config->get('shipping_myparcel_shipping_cost'); } + if (isset($this->request->post['shipping_myparcel_shipping_tax_class_id'])) { + $data['shipping_myparcel_shipping_tax_class_id'] = $this->request->post['shipping_myparcel_shipping_tax_class_id']; + } else { + $data['shipping_myparcel_shipping_tax_class_id'] = $this->config->get('shipping_myparcel_shipping_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + if (isset($this->request->post['shipping_myparcel_shipping_status'])) { $data['shipping_myparcel_shipping_status'] = $this->request->post['shipping_myparcel_shipping_status']; } else { @@ -115,6 +125,7 @@ function install() $this->model_setting_setting->editSetting('shipping_myparcel_shipping', array( 'shipping_myparcel_shipping_title' => 'Shipping & Handling', 'shipping_myparcel_shipping_cost' => 0, + 'shipping_myparcel_shipping_tax_class_id' => 0, 'shipping_myparcel_shipping_status' => 1, 'shipping_myparcel_shipping_sort_order' => 0 )); diff --git a/upload/admin/controller/extension/total/myparcel_total.php b/upload/admin/controller/extension/total/myparcel_total.php index 09b1b21..03f2050 100644 --- a/upload/admin/controller/extension/total/myparcel_total.php +++ b/upload/admin/controller/extension/total/myparcel_total.php @@ -89,7 +89,6 @@ public function index() } else { $this->response->setOutput($this->load->view(MyParcel()->getTotalPath() . 'myparcel_total.tpl', $data)); } - } function validate() diff --git a/upload/admin/view/template/extension/shipping/myparcel_shipping.twig b/upload/admin/view/template/extension/shipping/myparcel_shipping.twig index 8ab72a2..fb669be 100644 --- a/upload/admin/view/template/extension/shipping/myparcel_shipping.twig +++ b/upload/admin/view/template/extension/shipping/myparcel_shipping.twig @@ -37,6 +37,21 @@ +
+ +
+ +
+
diff --git a/upload/catalog/model/extension/shipping/myparcel_shipping.php b/upload/catalog/model/extension/shipping/myparcel_shipping.php index be3a48e..89a5bc1 100644 --- a/upload/catalog/model/extension/shipping/myparcel_shipping.php +++ b/upload/catalog/model/extension/shipping/myparcel_shipping.php @@ -2,11 +2,11 @@ class ModelExtensionShippingMyparcelShipping extends Model { function getQuote($address) { - $checkout_settings = $this->config->get('module_myparcelnl_fields_checkout'); - $status_config = $this->config->get('shipping_myparcel_shipping_status'); - $status = !empty($status_config) ? true : false; - $belgium_enabled = !empty($checkout_settings['belgium_enabled']) ? true : false; - $country_iso_code = isset($address['iso_code_2']) ? $address['iso_code_2'] : null; + $checkout_settings = $this->config->get('module_myparcelnl_fields_checkout'); + $status_config = $this->config->get('shipping_myparcel_shipping_status'); + $status = !empty($status_config); + $belgium_enabled = !empty($checkout_settings['belgium_enabled']); + $country_iso_code = $address['iso_code_2'] ?? null; $method_data = array(); @@ -29,7 +29,7 @@ function getQuote($address) { $checkout_helper = MyParcel()->shipment->checkout; $checkout_helper->setSessionOrderDeliveryOptions($this->session->data['myparcel_order_id']); - $data = isset($this->session->data['myparcel']) ? $this->session->data['myparcel'] : false; + $data = $this->session->data['myparcel'] ?? false; if ($data) { $total_array = $checkout_helper->getTotalArray($data); @@ -40,13 +40,14 @@ function getQuote($address) { } $quote_data = array(); + $total_price += $this->config->get('shipping_myparcel_shipping_cost'); $quote_data['myparcel_shipping'] = array( 'code' => 'myparcel_shipping.myparcel_shipping', 'title' => $this->config->get('shipping_myparcel_shipping_title'), 'cost' => $total_price, - 'tax_class_id' => '', - 'text' => $this->currency->format($this->tax->calculate($total_price, '', ''), $this->session->data['currency']) + 'tax_class_id' => $this->config->get('shipping_myparcel_shipping_tax_class_id'), + 'text' => $this->currency->format($this->tax->calculate($total_price, $this->config->get('shipping_myparcel_shipping_tax_class_id'), $this->config->get('config_tax')), $this->session->data['currency']) ); $method_data = array( diff --git a/upload/system/library/myparcelnl/includes/class_myparcel_helper.php b/upload/system/library/myparcelnl/includes/class_myparcel_helper.php index 88165ba..eb59142 100644 --- a/upload/system/library/myparcelnl/includes/class_myparcel_helper.php +++ b/upload/system/library/myparcelnl/includes/class_myparcel_helper.php @@ -23,7 +23,7 @@ public function filterEUOrders( $order_ids ) function isEUCountry($country_code) { // $eu_countries = array( 'GB', 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'EL', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); - $eu_countries = array( 'NL', 'BE', 'AT','BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'XK' ); + $eu_countries = array( 'NL', 'BE', 'AT', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'XK' ); return in_array( $country_code, $eu_countries); } @@ -737,7 +737,6 @@ function set_module_text($language) $data['entry_tab_3_title_shipment_processing_parameters'] = $language->get('entry_tab_3_title_shipment_processing_parameters'); $data['entry_tab_3_label_dropoff_days'] = $language->get('entry_tab_3_label_dropoff_days'); $data['entry_tab_3_label_cut_off_time'] = $language->get('entry_tab_3_label_cut_off_time'); - $data['entry_tab_3_label_cut_off_time'] = $language->get('entry_tab_3_label_cut_off_time'); $data['entry_tab_3_label_dropoff_delay'] = $language->get('entry_tab_3_label_dropoff_delay'); $data['entry_tab_3_label_delivery_days_window'] = $language->get('entry_tab_3_label_delivery_days_window'); $data['entry_tab_3_label_additional_fee'] = $language->get('entry_tab_3_label_additional_fee'); diff --git a/upload/system/library/myparcelnl/includes/class_myparcel_shipment_checkout.php b/upload/system/library/myparcelnl/includes/class_myparcel_shipment_checkout.php index 1a300ba..3bce715 100644 --- a/upload/system/library/myparcelnl/includes/class_myparcel_shipment_checkout.php +++ b/upload/system/library/myparcelnl/includes/class_myparcel_shipment_checkout.php @@ -1,6 +1,6 @@ get('cart'); - $config = $registry->get('config'); - $checkout_settings = $config->get('module_myparcelnl_fields_checkout'); - $belgium_enabled = !empty($checkout_settings['belgium_enabled']) ? true : false; - $country_code = MyParcel()->helper->getCountryIsoCodeFromSession(); + $registry = MyParcel::$registry; + $cart = $registry->get('cart'); + $config = $registry->get('config'); + $checkout_settings = $config->get('module_myparcelnl_fields_checkout'); + $belgium_enabled = !empty($checkout_settings['belgium_enabled']) ? true : false; + $country_code = MyParcel()->helper->getCountryIsoCodeFromSession(); /** * If country is BE * Then check if the BE setting is enabled @@ -108,8 +108,7 @@ function getTotalArray($data, $price_format = false, $order_id = null, $prefix = $recipient_only = true; } - $total_array = $this->getDeliveryTotalsFromSavedData($delivery_options, $signed, $recipient_only, $price_format, $order_id, $prefix, $taxIncluded); - return $total_array; + return $this->getDeliveryTotalsFromSavedData($delivery_options, $signed, $recipient_only, $price_format, $order_id, $prefix, $taxIncluded); } /** @@ -161,7 +160,7 @@ public function getDeliveryTotalsFromSavedData($myparcel_delivery_options, $sign if (empty($prices)) { $prices = $this->getDeliveryPrices($price_format, false, $prefix, $taxIncluded, $order_id, $cart->getSubTotal()); // Get Prices without formatting - $country_code = MyParcel()->helper->getCountryIsoCodeFromSession(); + $country_code = MyParcel()->helper->getCountryIsoCodeFromSession(); $prices = !empty($country_code) ? $prices[$country_code] : $prices; } @@ -173,7 +172,7 @@ public function getDeliveryTotalsFromSavedData($myparcel_delivery_options, $sign } else { // MAILBOX mode - $mailbox_fee = floatval(MyParcel()->settings->checkout->mailbox_fee); + $mailbox_fee = (float) MyParcel()->settings->checkout->mailbox_fee; if ($price_format) { $mailbox_fee = $this->formatDeliveryPrice($mailbox_fee, null, true, $prefix); } @@ -276,169 +275,90 @@ public function getDeliveryDateFromSavedData($myparcel_delivery_options) } } - /** - * Retrieve delivery prices that are set in admin settings - * @param boolean $price_format (add currency symbol and convert dot/comma) - * @param boolean $color_format (add color code into price) - * @param string prefix - * @return array prices of delivery types - */ - function getDeliveryPrices($price_format = true, $color_format = true, $prefix = '', $addTax = true, $order_id = 0, $value = 0) - { - $registry = MyParcel::$registry; - /** @var \Cart\Cart $cart **/ - $cart = $registry->get('cart'); - /** @var \Cart\Currency $currency **/ - $currency = $registry->get('currency'); - $config = $registry->get('config'); - $checkout_settings = $config->get('module_myparcelnl_fields_checkout'); - $price_options = array_merge( self::$delivery_extra_options, self::$delivery_types ); - $prices = array(); - - // default settings - $price_type = 0; - $subtotal1_min = isset($checkout_settings['subtotal1_min']) ? $checkout_settings['subtotal1_min'] : 0; - $subtotal1_max = isset($checkout_settings['subtotal1_max']) ? $checkout_settings['subtotal1_max'] : 50; - $subtotal2_min = isset($checkout_settings['subtotal2_min']) ? $checkout_settings['subtotal2_min'] : 50.01; - $subtotal2_max = isset($checkout_settings['subtotal2_max']) ? $checkout_settings['subtotal2_max'] : 1000000; - - if($order_id > 0) { - $loader = $registry->get('load'); - $loader->model('checkout/order'); - $model_order = $registry->get('model_checkout_order'); - $order = $model_order->getOrder($order_id); - $value = $order['total']; - - if($subtotal2_min <= $value && $value < $subtotal2_max) - $price_type = 1; - }else{ - if($subtotal2_min <= $value && $value < $subtotal2_max) - $price_type = 1; - } - - foreach ($price_options as $key => $option) { - // JS API correction - /* if ($option == 'standard') { - $option = 'default'; - }*/ - - $option_enabled = (!empty($checkout_settings[$option.'_enabled'])) ? true : false; - - if ($option_enabled) { - if ($price_type == 0 && (float)$checkout_settings[$option . '_fee'] >= 0) { - $fee = (float)$checkout_settings[$option . '_fee']; - - if($fee >= 0) { - $fee = $this->convertPriceToFloat($fee); - - //$fee += $this->getMyParcelShippingCost(); - if ($addTax) { - $fee_including_tax = $this->getTotalDeliveryTaxAmountFromCart($fee, $cart); - } else { - $fee_including_tax = $fee; - } - - if ($price_format) { - $formatted_fee = $this->formatDeliveryPrice($fee_including_tax, $currency, $color_format, $prefix); - } else { - $formatted_fee = $fee_including_tax; - } - - $prices[$option] = $formatted_fee; - } - } - - if ($price_type == 1 && (float)($checkout_settings[$option . '_fee2']) >= 0 ) { - $fee = (float)$checkout_settings[$option . '_fee2']; - - if($fee >= 0) { - $fee = $this->convertPriceToFloat($fee); - - //$fee += $this->getMyParcelShippingCost(); - if ($addTax) { - $fee_including_tax = $this->getTotalDeliveryTaxAmountFromCart($fee, $cart); - } else { - $fee_including_tax = $fee; - } - - if ($price_format) { - $formatted_fee = $this->formatDeliveryPrice($fee_including_tax, $currency, $color_format, $prefix); - } else { - $formatted_fee = $fee_including_tax; - } - - $prices[$option] = $formatted_fee; - } - } - } else { - if (in_array($option, self::$delivery_extra_options)) { - $prices[$option] = 'disabled'; - } - } - } - - if (empty($prices)) { - $prices['pickup'] = ''; - $prices['pickup_express'] = ''; - } - - $belgium_enabled = !empty($checkout_settings['belgium_enabled']) ? true : false; - - if ($belgium_enabled) { - $price_options = array_merge( self::$belgium_delivery_types ); - $be_prices = array(); - - foreach ($price_options as $option) { - - $formatted_fee = ''; - - if ($price_type == 0 && (float)($checkout_settings['belgium_' . $option . '_fee']) >= 0) { - $fee = (float)$checkout_settings['belgium_' . $option . '_fee']; - $fee = $this->convertPriceToFloat($fee); -// $fee_including_tax = $this->getTotalDeliveryTaxAmountFromCart($fee, $cart); - if ($addTax) { - $fee_including_tax = $this->getTotalDeliveryTaxAmountFromCart($fee, $cart); - } else { - $fee_including_tax = $fee; - } - //$fee_including_tax = $fee; - if ($price_format) { - $formatted_fee = $this->formatDeliveryPrice($fee_including_tax, $currency, $color_format, $prefix); - } else { - $formatted_fee = $fee_including_tax; - } - } - - if ($price_type == 1 && (float)($checkout_settings['belgium_' . $option . '_fee2']) >= 0) { - $fee = (float)$checkout_settings['belgium_' . $option . '_fee2']; - $fee = $this->convertPriceToFloat($fee); -// $fee_including_tax = $this->getTotalDeliveryTaxAmountFromCart($fee, $cart); - if ($addTax) { - $fee_including_tax = $this->getTotalDeliveryTaxAmountFromCart($fee, $cart); - } else { - $fee_including_tax = $fee; - } - //$fee_including_tax = $fee; - if ($price_format) { - $formatted_fee = $this->formatDeliveryPrice($fee_including_tax, $currency, $color_format, $prefix); - } else { - $formatted_fee = $fee_including_tax; - } - } - - $be_prices[$option] = $formatted_fee; - } - - return array( - 'NL' => $prices, - 'BE' => $be_prices - ); - } - - return array( - 'NL' => $prices, - ); - } + /** + * Retrieve delivery prices that are set in admin settings + * @param boolean $priceFormat (add currency symbol and convert dot/comma) + * @param boolean $colorFormat (add color code into price) + * @param string $prefix prefix + * @return array prices of delivery types + */ + function getDeliveryPrices($priceFormat = true, $colorFormat = true, $prefix = '', $addTax = true, $order_id = 0, $value = 0) + { + $registry = MyParcel::$registry; + /** @var \Cart\Currency $currency * */ + $currency = $registry->get('currency'); + $config = $registry->get('config'); + $checkoutSettings = $config->get('module_myparcelnl_fields_checkout'); + + /** + * overwrite (!) $value with total order value if $order_id is set + */ + if ($order_id > 0) { + $loader = $registry->get('load'); + $loader->model('checkout/order'); + $order = $registry->get('model_checkout_order')->getOrder($order_id); + $value = $order['total']; + } + + // default settings + $feeSuffix = ''; + $subtotal2Min = $checkoutSettings['subtotal2_min'] ?? 50.01; + $subtotal2Max = $checkoutSettings['subtotal2_max'] ?? 1000000; + + if ($subtotal2Min <= $value && $value < $subtotal2Max) { + $feeSuffix = '2'; + } + + $getOptions = function (array $priceOptions, string $optionPrefix = '') use ($checkoutSettings, $feeSuffix, $currency, $addTax, $priceFormat, $colorFormat, $prefix) { + $prices = array(); + foreach ($priceOptions as $option) { + $isShipmentOption = in_array($option, self::$delivery_extra_options, true); + + if (empty($checkoutSettings["$optionPrefix{$option}_enabled"])) { + if ($isShipmentOption) { + $prices[$option] = 'disabled'; + } + continue; + } + + $fee = $this->convertPriceToFloat($checkoutSettings["$optionPrefix{$option}_fee$feeSuffix"] ?? 0); + + if (!$isShipmentOption) { + $fee += $this->getMyParcelShippingCost(); + } + + if ($addTax) { + $fee = $this->addTaxToDeliveryFee($fee); + } + + if ($priceFormat) { + $prices[$option] = $this->formatDeliveryPrice($fee, $currency, $colorFormat, $prefix); + } else { + $prices[$option] = $fee; + } + } + return $prices; + }; + + $prices = $getOptions(array_merge(self::$delivery_extra_options, self::$delivery_types)); + + if (!$prices) { + $prices['pickup'] = ''; + $prices['pickup_express'] = ''; + } + + if (!empty($checkoutSettings['belgium_enabled'])) { + + return array( + 'NL' => $prices, + 'BE' => $getOptions(self::$belgium_delivery_types, 'belgium_') + ); + } + + return array( + 'NL' => $prices, + ); + } /** * Converts price string to float value, assuming no thousand-separators used @@ -448,33 +368,28 @@ function getDeliveryPrices($price_format = true, $color_format = true, $prefix = function convertPriceToFloat( $price ) { $price = str_replace(',', '.', $price); - $price = floatval($price); - return $price; + return (float) $price; } /** - * Calculate a price base on taxes that affect in cart session * @param float $deliveryFee - * @param Cart $cart * @return float price with taxes included */ - function getTotalDeliveryTaxAmountFromCart($deliveryFee, $cart) - { - if (! $deliveryFee) { - return 0; - } - - $registry = MyParcel::$registry; - $tax = $registry->get('tax'); + public function addTaxToDeliveryFee($deliveryFee) + { + if (!$deliveryFee) { + return 0; + } - if ($cart instanceof Cart && ($taxes = $cart->getTaxes())) { - - return $tax->calculate($deliveryFee, $taxes, true); - } + $registry = MyParcel::$registry; + $config = $registry->get('config'); + $taxClassId = (int)$config->get('shipping_myparcel_shipping_tax_class_id'); - return $deliveryFee; - } + /** @var $tax Tax/Tax */ + $tax = $registry->get('tax'); + return $tax->calculate($deliveryFee, $taxClassId); + } function formatDeliveryPrice($price, $currency = null, $color_format = true, $prefix = '') { diff --git a/upload/system/library/myparcelnl/includes/class_myparcel_view.php b/upload/system/library/myparcelnl/includes/class_myparcel_view.php index 1fe78ad..d955efa 100644 --- a/upload/system/library/myparcelnl/includes/class_myparcel_view.php +++ b/upload/system/library/myparcelnl/includes/class_myparcel_view.php @@ -64,15 +64,11 @@ function export_print_batch() $session = $registry->get('session'); $url = $registry->get('url'); $token = $session->data['user_token']; - if (version_compare(VERSION, '2.0.0.0', '>=')) { - $formAction = $url->link(MyParcel()->getMyparcelControllerPath('myparcelnl', 'exportPrintBatch'), array('user_token' => $token)); - } else { - $formAction = $url->link(MyParcel()->getMyparcelControllerPath('myparcelnl', 'exportPrintBatch'), array('user_token' => $token)); - } + $formAction = $url->link(MyParcel()->getMyparcelControllerPath('myparcelnl', 'exportPrintBatch'), array('user_token' => $token), true); ob_start(); $this->render('view_export_print_batch', array('formAction' => $formAction)); - $html = ob_get_clean(); - return $html; + + return ob_get_clean(); } function column_myparcel($order_id, $screen = 'order_overview') diff --git a/upload/system/library/myparcelnl/myparcel.ocmod.xml b/upload/system/library/myparcelnl/myparcel.ocmod.xml index ba1b9fd..b6457d5 100644 --- a/upload/system/library/myparcelnl/myparcel.ocmod.xml +++ b/upload/system/library/myparcelnl/myparcel.ocmod.xml @@ -1831,49 +1831,6 @@ ]]> - - - - - - - 0) {]]> - session->data['myparcel']['data'])) { - /** @var MyParcel_Shipment_Checkout $checkout_helper * */ - $this->load->model('extension/myparcelnl/helper'); - $checkout_helper = MyParcel($this->registry)->shipment->checkout; - $helper = MyParcel()->helper; - $data = $this->session->data['myparcel']; - - if ((is_array($data['data']) && count($data['data'])) || (!is_array($data['data']) && count(json_decode(html_entity_decode($data['data']), true)))) { - $total_array = $checkout_helper->getTotalArray($data, false, null, '', false); - $total_price_without_tax = 0; - - foreach ($total_array as $total_code => $total_item) { - $total_price_without_tax += $total_item['price']; - } - //get tax - $currentTax =$helper->getTaxRate($key); - if($currentTax !== false){ - switch ($currentTax['type']){ - case 'P' : - $tax = $total_price_without_tax * ($currentTax['rate']/100); - break; - case 'F': - $tax = $currentTax['rate']; - break; - } - } - } - } - $value += $tax; - /* MyParcel Ocmod End */ - ]]> - - {{ tab_data }}]]> diff --git a/upload/system/library/myparcelnl/myparcel_trait.php b/upload/system/library/myparcelnl/myparcel_trait.php index 17a0a9d..c65749a 100644 --- a/upload/system/library/myparcelnl/myparcel_trait.php +++ b/upload/system/library/myparcelnl/myparcel_trait.php @@ -1,128 +1,102 @@ =')) { - trait MyparcelT { - public function getTotal($total) - { - if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) { - - if (!class_exists('MyParcel')) { - require_once DIR_SYSTEM . 'library/myparcelnl/class_myparcel.php'; - MyParcel($this->registry); - } - - if (MyParcel()->shipment->checkout->checkValidShippingMethod()) { - - $total_total_code = version_compare(VERSION, '3.0.0.0', '>=') ? 'myparcel_total' : 'total_myparcel_total'; - - if (!empty($this->session->data['myparcel']['data'])) { - - /** @var MyParcel_Shipment_Checkout $checkout_helper * */ - $checkout_helper = MyParcel()->shipment->checkout; - $data = $this->session->data['myparcel']; - - // Get current shipping title - $checkout_shipping_method = MyParcel()->shipment->shipment_helper->getShippingCodeByShippingQuote($this->session->data['shipping_method']['code']); - - $total_array = $checkout_helper->getTotalArray($data, false, null, '', false); - $total_price = 0; - - foreach ($total_array as $total_code => $total_item) { - $total_price += $total_item['price']; - } - - if(version_compare(VERSION, '2.3.0.0', '>=')) { - $this->load->language('extension/shipping/' . $checkout_shipping_method); - } else { - $this->load->language('shipping/' . $checkout_shipping_method); - } - - - if ($total_price > 0) { - $total['totals'][] = array( - 'code' => $total_total_code, - 'title' => $this->config->get('shipping_myparcel_shipping_title') . - ' - ' - . MyParcel()->lang->get('entry_details') . - ' - - ', - 'value' => $total_price, - 'sort_order' => $this->config->get('total_myparcel_total_sort_order') - ); - - $total['total'] += $total_price; - } - } else { - $session_data = $this->session->data; - $shipping_code = version_compare(VERSION, '3.0.0.0', '>=') ? 'myparcel_shipping.myparcel_shipping' : 'shipping_myparcel_shipping.shipping_myparcel_shipping'; - if (!empty($session_data['shipping_method']['code']) && $session_data['shipping_method']['code'] == $shipping_code) { - $total['totals'][] = array( - 'code' => $total_total_code, - 'title' => $this->config->get('shipping_myparcel_shipping_title'), - 'value' => $this->config->get('shipping_myparcel_shipping_cost'), - 'sort_order' => $this->config->get('shipping_sort_order') - ); - } - } - } - } - } - } +if (version_compare(VERSION, '2.2.0.0', '>=')) { + trait MyparcelT { + public function getTotal() { + if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) { + if (!class_exists('MyParcel')) { + require_once DIR_SYSTEM . 'library/myparcelnl/class_myparcel.php'; + MyParcel($this->registry); + } + + if (MyParcel()->shipment->checkout->checkValidShippingMethod() + && !empty($this->session->data['myparcel']['data']) + ) { + + /** @var MyParcel_Shipment_Checkout $checkout_helper * */ + $checkout_helper = MyParcel()->shipment->checkout; + $data = $this->session->data['myparcel']; + + // Get current shipping title + $checkout_shipping_method = MyParcel()->shipment->shipment_helper->getShippingCodeByShippingQuote($this->session->data['shipping_method']['code']); + + $total_array = $checkout_helper->getTotalArray($data, false, null, '', false); + $total_price = 0; + + foreach ($total_array as $total_code => $total_item) { + $total_price += $total_item['price']; + } + + if (version_compare(VERSION, '2.3.0.0', '>=')) { + $this->load->language('extension/shipping/' . $checkout_shipping_method); + } else { + $this->load->language('shipping/' . $checkout_shipping_method); + } + + if ($total_price > 0) { + $details = MyParcel()->lang->get('entry_details'); + $title = $this->config->get('shipping_myparcel_shipping_title'); + $this->session->data['shipping_method']['title'] = + "$title $details"; + $this->session->data['shipping_method']['cost'] = $total_price; + $this->session->data['shipping_method']['text'] = $title; // currently not used in OC that I can see + } + } + } + } + } } else { - trait MyparcelT { - public function getTotal(&$totals, &$price, &$taxes) - { - if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) { + trait MyparcelT { + public function getTotal(&$totals, &$price, &$taxes) { + if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) { - if (!class_exists('MyParcel')) { - require_once DIR_SYSTEM . 'library/myparcelnl/class_myparcel.php'; - MyParcel($this->registry); - } + if (!class_exists('MyParcel')) { + require_once DIR_SYSTEM . 'library/myparcelnl/class_myparcel.php'; + MyParcel($this->registry); + } - if (MyParcel()->shipment->checkout->checkValidShippingMethod()) { + if (MyParcel()->shipment->checkout->checkValidShippingMethod()) { - if (!empty($this->session->data['myparcel']['data'])) { + if (!empty($this->session->data['myparcel']['data'])) { - /** @var MyParcel_Shipment_Checkout $checkout_helper * */ - $checkout_helper = MyParcel()->shipment->checkout; - $data = $this->session->data['myparcel']; + /** @var MyParcel_Shipment_Checkout $checkout_helper * */ + $checkout_helper = MyParcel()->shipment->checkout; + $data = $this->session->data['myparcel']; - // Get current shipping title - $checkout_shipping_method = MyParcel()->shipment->shipment_helper->getShippingCodeByShippingQuote($this->session->data['shipping_method']['code']); + // Get current shipping title + $checkout_shipping_method = MyParcel()->shipment->shipment_helper->getShippingCodeByShippingQuote($this->session->data['shipping_method']['code']); - $total_array = $checkout_helper->getTotalArray($data, false, null, '', false); - $total_price = 0; + $total_array = $checkout_helper->getTotalArray($data, false, null, '', false); + $total_price = 0; - foreach ($total_array as $total_code => $total_item) { - $total_price += $total_item['price']; - } + foreach ($total_array as $total_code => $total_item) { + $total_price += $total_item['price']; + } - if(version_compare(VERSION, '2.3.0.0', '>=')) { - $this->load->language('extension/shipping/' . $checkout_shipping_method); - } else { - $this->load->language('shipping/' . $checkout_shipping_method); - } + if (version_compare(VERSION, '2.3.0.0', '>=')) { + $this->load->language('extension/shipping/' . $checkout_shipping_method); + } else { + $this->load->language('shipping/' . $checkout_shipping_method); + } - if ($total_price > 0) { - $totals[] = array( - 'code' => 'total_myparcel_total', - 'title' => $this->config->get('shipping_myparcel_shipping_title') . - ' + if ($total_price > 0) { + $totals[] = array( + 'code' => 'total_myparcel_total', + 'title' => $this->config->get('shipping_myparcel_shipping_title') . + ' ' - . MyParcel()->lang->get('entry_details') . - ' + . MyParcel()->lang->get('entry_details') . + ' ', - 'value' => $total_price, - 'sort_order' => $this->config->get('total_myparcel_total_sort_order') - ); - - $price += $total_price; - } - } - } - } - } - } + 'value' => $total_price, + 'sort_order' => $this->config->get('total_myparcel_total_sort_order') + ); + + $price += $total_price; + } + } + } + } + } + } } \ No newline at end of file diff --git a/upload/system/library/myparcelnl/views/view_iframe_base_delivery_options.php b/upload/system/library/myparcelnl/views/view_iframe_base_delivery_options.php index c006c43..f9a223f 100644 --- a/upload/system/library/myparcelnl/views/view_iframe_base_delivery_options.php +++ b/upload/system/library/myparcelnl/views/view_iframe_base_delivery_options.php @@ -567,7 +567,7 @@
- shipment->checkout->formatDeliveryPrice(MyParcel()->settings->checkout->mailbox_fee, null, false); ?> + shipment->checkout->formatDeliveryPrice(MyParcel()->shipment->checkout->addTaxToDeliveryFee(MyParcel()->settings->checkout->mailbox_fee ?: 0), null, false); ?> settings->checkout->mailbox_title; ?> diff --git a/upload/system/library/myparcelnl/views/view_iframe_delivery_checkout_header.php b/upload/system/library/myparcelnl/views/view_iframe_delivery_checkout_header.php index 54c5ff0..8ebf96e 100644 --- a/upload/system/library/myparcelnl/views/view_iframe_delivery_checkout_header.php +++ b/upload/system/library/myparcelnl/views/view_iframe_delivery_checkout_header.php @@ -1,7 +1,6 @@ shipment; -/** @var MyParcel_Shipment_Checkout $checkout_helper **/ $checkout_helper = $shipment_class->checkout; $frontend_api_url = 'https://api.myparcel.nl/delivery_options';