function setPaymentMethod($payment_method) { if (!$payment_method) { return 0; } $payment_method = mslib_fe::getPaymentMethod($payment_method); $iso_customer = mslib_fe::getCountryByName($this->cart['user']['country']); $countries_id = $iso_customer['cn_iso_nr']; if ($payment_method['handling_costs']) { if (!strstr($payment_method['handling_costs'], "%")) { $this->cart['user']['payment_method_costs'] = $payment_method['handling_costs']; } else { // calculate total payment costs based by % if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $subtotal = $this->cart['summarize']['sub_total_including_vat'] - $this->cart['discount_amount']; } else { $subtotal = $this->cart['summarize']['sub_total'] - $this->cart['discount_amount']; } if ($subtotal) { if (strstr($payment_method['handling_costs'], "%")) { $percentage = str_replace("%", '', $payment_method['handling_costs']); $total_include_vat = 0; if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $total_include_vat = 1; } $subtotal = mslib_fe::countCartTotalPrice(1, $total_include_vat, $countries_id); if ($subtotal) { $handling_cost = $subtotal / 100 * $percentage; if ($total_include_vat && $payment_method['tax_rate']) { $handling_cost = $handling_cost / (1 + $payment_method['tax_rate']); } $this->cart['user']['payment_method_costs'] = $handling_cost; } } else { $this->cart['user']['payment_method_costs'] = $payment_method['handling_costs']; } } } } else { $this->cart['user']['payment_method_costs'] = 0; } if ($payment_method['tax_id'] && $this->cart['user']['payment_method_costs']) { $this->cart['user']['payment_total_tax_rate'] = $payment_method['tax_rate']; //if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { //$this->cart['user']['payment_method_costs']=$this->cart['user']['payment_method_costs']-($this->cart['user']['payment_method_costs']*$this->cart['user']['payment_total_tax_rate']); //} if ($payment_method['country_tax_rate']) { $this->cart['user']['payment_country_tax_rate'] = $payment_method['country_tax_rate']; $this->cart['user']['payment_country_tax'] = mslib_fe::taxDecimalCrop($this->cart['user']['payment_method_costs'] * $payment_method['country_tax_rate']); } else { $this->cart['user']['payment_country_tax_rate'] = 0; $this->cart['user']['payment_country_tax'] = 0; } if ($payment_method['region_tax_rate']) { $this->cart['user']['payment_region_tax_rate'] = $payment_method['region_tax_rate']; $this->cart['user']['payment_region_tax'] = mslib_fe::taxDecimalCrop($this->cart['user']['payment_method_costs'] * $payment_method['region_tax_rate']); } else { $this->cart['user']['payment_region_tax_rate'] = 0; $this->cart['user']['payment_region_tax'] = 0; } if ($this->cart['user']['payment_region_tax'] && $this->cart['user']['payment_country_tax']) { $this->cart['user']['payment_tax'] = $this->cart['user']['payment_country_tax'] + $this->cart['user']['payment_region_tax']; } else { $this->cart['user']['payment_tax'] = $this->cart['user']['payment_method_costs'] * $payment_method['tax_rate']; } } else { $this->cart['user']['payment_tax'] = 0; $this->cart['user']['payment_country_tax'] = 0; $this->cart['user']['payment_region_tax'] = 0; $this->cart['user']['payment_total_tax_rate'] = 0; $this->cart['user']['payment_country_tax_rate'] = 0; $this->cart['user']['payment_region_tax_rate'] = 0; } $this->cart['user']['payment_method'] = $payment_method['code']; $this->cart['user']['payment_method_label'] = $payment_method['name']; // payment eof // hook to rewrite the whole methods if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['setPaymentMethodPreSaveHook'])) { $params = array('cart_user' => &$this->cart['user']); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['setPaymentMethodPreSaveHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } tx_mslib_cart::storeCart($this->cart); }
$return_data['shipping_cost'] = 0; $return_data['shipping_costs_display'] = mslib_fe::amount2Cents(0); $return_data['shipping_method']['deliver_by'] = ''; $return_data['shopping_cart_total_price'] = mslib_fe::amount2Cents(mslib_fe::countCartTotalPrice(1, $count_cart_incl_vat, $iso_customer['cn_iso_nr'])); // foreach ($shipping_cost_data as $shipping_code => $shipping_cost) { if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $count_cart_incl_vat = 1; $return_data['shipping_cost'] = $shipping_cost['shipping_costs_including_vat']; $return_data['shipping_costs_display'] = mslib_fe::amount2Cents($shipping_cost['shipping_costs_including_vat']); } else { $return_data['shipping_cost'] = $shipping_cost['shipping_costs']; $return_data['shipping_costs_display'] = mslib_fe::amount2Cents($shipping_cost['shipping_costs']); } $return_data['shipping_method'] = $shipping_cost; $return_data['shopping_cart_total_price'] = mslib_fe::amount2Cents(mslib_fe::countCartTotalPrice(1, $count_cart_incl_vat, $iso_customer['cn_iso_nr']) + $return_data['shipping_cost']); } echo json_encode($return_data); exit; break; case 'get_product_shippingcost_overview': if (is_numeric($this->post['tx_multishop_pi1']['pid'])) { $return_data = array(); $product_data = mslib_fe::getProduct($this->post['tx_multishop_pi1']['pid']); if (!$this->post['tx_multishop_pi1']['qty']) { $this->post['tx_multishop_pi1']['qty'] = 1; } $return_data['delivery_time'] = 'e'; if (!empty($product_data['delivery_time'])) { $return_data['delivery_time'] = trim($product_data['delivery_time']); }
public function getShippingCosts($countries_id, $shipping_method_id) { if (!is_numeric($countries_id)) { return false; } if (!is_numeric($shipping_method_id)) { return false; } $str3 = $GLOBALS['TYPO3_DB']->SELECTquery('sm.shipping_costs_type, sm.handling_costs, c.price, c.override_shippingcosts, c.zone_id', 'tx_multishop_shipping_methods sm, tx_multishop_shipping_methods_costs c, tx_multishop_countries_to_zones c2z', 'sm.id=c.shipping_method_id and c.zone_id=c2z.zone_id and c.shipping_method_id=\'' . $shipping_method_id . '\' and (sm.page_uid=0 or sm.page_uid=\'' . $this->shop_pid . '\') and c2z.cn_iso_nr=\'' . $countries_id . '\'', '', '', ''); $qry3 = $GLOBALS['TYPO3_DB']->sql_query($str3); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry3)) { $row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry3); $shipping_method = mslib_fe::getShippingMethod($shipping_method_id, 's.id', $countries_id); //hook to let other plugins further manipulate the settings if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['getShippingCosts'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['getShippingCosts'] as $funcRef) { $params['row3'] =& $row3; $params['shipping_method'] =& $shipping_method; $params['countries_id'] =& $countries_id; \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } if ($row3['shipping_costs_type'] == 'weight') { $total_weight = mslib_fe::countCartWeight(); $steps = explode(",", $row3['price']); $current_price = ''; foreach ($steps as $step) { $cols = explode(":", $step); if (isset($cols[1])) { $current_price = $cols[1]; } if ($total_weight <= $cols[0]) { $current_price = $cols[1]; break; } } $shipping_cost = $current_price; $shipping_cost_method_box = $current_price; } elseif ($row3['shipping_costs_type'] == 'quantity') { $total_quantity = mslib_fe::countCartQuantity(); $steps = explode(",", $row3['price']); $current_price = ''; foreach ($steps as $step) { $cols = explode(":", $step); if (isset($cols[1])) { $current_price = $cols[1]; } if ($total_quantity <= $cols[0]) { $current_price = $cols[1]; break; } } $shipping_cost = $current_price; $shipping_cost_method_box = $current_price; } else { if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['getShippingCostsCustomType'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['getShippingCostsCustomType'] as $funcRef) { $params['row3'] =& $row3; $params['countries_id'] =& $countries_id; $params['shipping_method'] =& $shipping_method; $params['shipping_method_id'] =& $shipping_method_id; $params['shipping_cost'] =& $shipping_cost; $params['shipping_cost_method_box'] =& $shipping_cost_method_box; \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } else { $shipping_cost = $row3['price']; $shipping_cost_method_box = $row3['price']; } } // // calculate total costs $subtotal = mslib_fe::countCartTotalPrice(1, 0, $countries_id); if (strstr($subtotal, ",")) { $subtotal = str_replace(',', '.', $subtotal); } // if (!empty($row3['override_shippingcosts'])) { $old_shipping_costs = $shipping_cost; $shipping_cost = $row3['override_shippingcosts']; // custom code to change the shipping costs based on cart amount if (strstr($shipping_cost, ",") || strstr($shipping_cost, ":")) { $steps = explode(",", $shipping_cost); $count = 0; if (is_array($steps) && count($steps)) { foreach ($steps as $step) { // example: the value 200:15 means below 200 euro the shipping costs are 15 euro, above and equal 200 euro the shipping costs are 0 euro // example setting: 0:6.95,50:0 $split = explode(":", $step); if (is_numeric($split[0])) { if ($subtotal > $split[0] and isset($split[1])) { $shipping_cost = $split[1]; $shipping_cost_method_box = $split[1]; continue; } else { $shipping_cost = $old_shipping_costs; $shipping_cost_method_box = $old_shipping_costs; } } $count++; } } } } // custom code to change the shipping costs based on cart amount if (strstr($shipping_cost, ",") || strstr($shipping_cost, ":")) { $steps = explode(",", $shipping_cost); $count = 0; foreach ($steps as $step) { // example: the value 200:15 means below 200 euro the shipping costs are 15 euro, above and equal 200 euro the shipping costs are 0 euro // example setting: 0:6.95,50:0 $split = explode(":", $step); if (is_numeric($split[0])) { if ($count == 0) { if (isset($split[1])) { $shipping_cost = $split[1]; $shipping_cost_method_box = $split[1]; } else { $shipping_cost = $split[0]; $shipping_cost_method_box = $split[0]; continue; } } if ($subtotal > $split[0] and isset($split[1])) { $shipping_cost = $split[1]; $shipping_cost_method_box = $split[0]; continue; } } $count++; } } // custom code to change the shipping costs based on cart amount /* if (strstr($price,"%")) { // calculate total shipping costs based by % $subtotal=0; foreach ($this->cart['products'] as $products_id => $value) { if (is_numeric($products_id)) { $subtotal=$subtotal+($value['qty']*$value['final_price']); } } if ($subtotal) { $percentage=str_replace("%",'',$price); if ($percentage) { $price = ($subtotal/100*$percentage); } } } else { if (strstr($price,",")) { $steps=explode(",",$price); // calculate total costs $subtotal=mslib_fe::countCartTotalPrice(); $count=0; foreach ($steps as $step) { // example: the value 200:15 means below 200 euro the shipping costs are 15 euro, above and equal 200 euro the shipping costs are 0 euro // example setting: 0:6.95,50:0 $split=explode(":",$step); if (is_numeric($split[0])) { if ($count==0) { if (isset($split[1])) { $price=$split[1]; } else { $price=$split[0]; next(); } } if ($subtotal > $split[0] and isset($split[1])) { $price=$split[1]; next(); } } $count++; } } } */ if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $shipping_cost = round($shipping_cost, 2); $shipping_cost_method_box = round($shipping_cost_method_box, 2); } // shipping costs only for shipping method box display if ($shipping_cost_method_box) { if ($shipping_method['tax_id'] && $shipping_cost_method_box) { $shipping_method_box_total_tax_rate = $shipping_method['tax_rate']; if ($shipping_method['country_tax_rate']) { $shipping_method_box_country_tax_rate = $shipping_method['country_tax_rate']; $shipping_method_box_country_tax = mslib_fe::taxDecimalCrop($shipping_cost_method_box * $shipping_method['country_tax_rate']); } else { $shipping_method_box_country_tax_rate = 0; $shipping_method_box_country_tax = 0; } if ($shipping_method['region_tax_rate']) { $shipping_method_box_region_tax_rate = $shipping_method['region_tax_rate']; $shipping_method_box_region_tax = mslib_fe::taxDecimalCrop($shipping_cost_method_box * $shipping_method['region_tax_rate']); } else { $shipping_method_box_region_tax_rate = 0; $shipping_method_box_region_tax = 0; } if ($shipping_method_box_region_tax && $shipping_method_box_country_tax) { $shipping_method_box_tax = $shipping_method_box_country_tax + $shipping_method_box_region_tax; } else { $shipping_method_box_tax = mslib_fe::taxDecimalCrop($shipping_cost_method_box * $shipping_method['tax_rate']); } } } if ($shipping_cost) { if ($shipping_method['tax_id'] && $shipping_cost) { $shipping_total_tax_rate = $shipping_method['tax_rate']; if ($shipping_method['country_tax_rate']) { $shipping_country_tax_rate = $shipping_method['country_tax_rate']; $shipping_country_tax = mslib_fe::taxDecimalCrop($shipping_cost * $shipping_method['country_tax_rate']); } else { $shipping_country_tax_rate = 0; $shipping_country_tax = 0; } if ($shipping_method['region_tax_rate']) { $shipping_region_tax_rate = $shipping_method['region_tax_rate']; $shipping_region_tax = mslib_fe::taxDecimalCrop($shipping_cost * $shipping_method['region_tax_rate']); } else { $shipping_region_tax_rate = 0; $shipping_region_tax = 0; } if ($shipping_region_tax && $shipping_country_tax) { $shipping_tax = $shipping_country_tax + $shipping_region_tax; } else { $shipping_tax = mslib_fe::taxDecimalCrop($shipping_cost * $shipping_method['tax_rate']); } } } $handling_cost = 0; $handling_tax = 0; if (!empty($row3['handling_costs'])) { $handling_cost = $row3['handling_costs']; if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $handling_cost = round($row3['handling_costs'], 2); } $percentage_handling_cost = false; if (strpos($handling_cost, '%') !== false) { $handling_cost = str_replace('%', '', $handling_cost); $percentage_handling_cost = true; } if ($percentage_handling_cost) { $tmp_handling_cost = $handling_cost; $total_include_vat = 0; if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $total_include_vat = 1; } $subtotal = mslib_fe::countCartTotalPrice(1, $total_include_vat, $countries_id); if ($subtotal) { $handling_cost = $subtotal / 100 * $tmp_handling_cost; if ($total_include_vat && $shipping_method['tax_rate']) { $handling_cost = $handling_cost / (1 + $shipping_method['tax_rate']); } } } //var_dump($shipping_method['tax_rate']); //die(); if ($shipping_method['tax_id'] && $handling_cost) { $handling_total_tax_rate = $shipping_method['tax_rate']; if ($shipping_method['country_tax_rate']) { $handling_country_tax_rate = $shipping_method['country_tax_rate']; $handling_country_tax = mslib_fe::taxDecimalCrop($handling_cost * $shipping_method['country_tax_rate']); } else { $handling_country_tax_rate = 0; $handling_country_tax = 0; } if ($shipping_method['region_tax_rate']) { $handling_region_tax_rate = $shipping_method['region_tax_rate']; $handling_region_tax = mslib_fe::taxDecimalCrop($handling_cost * $shipping_method['region_tax_rate']); } else { $handling_region_tax_rate = 0; $handling_region_tax = 0; } if ($handling_region_tax && $handling_country_tax) { $handling_tax = $handling_country_tax + $handling_region_tax; } else { $handling_tax = mslib_fe::taxDecimalCrop($handling_cost * $shipping_method['tax_rate']); } } } $shipping_cost += $handling_cost; $shipping_tax += $handling_tax; $shipping_cost_method_box += $handling_cost; $shipping_method_box_tax += $handling_tax; $shipping_method['shipping_costs_method_box'] = $shipping_cost_method_box; $shipping_method['shipping_costs_method_box_including_vat'] = $shipping_cost_method_box + $shipping_method_box_tax; $shipping_method['shipping_costs'] = $shipping_cost; $shipping_method['shipping_costs_including_vat'] = $shipping_cost + $shipping_tax; return $shipping_method; } else { return false; } }