function getCart() { $this->cart = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->cart_page_uid); // custom hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartPreHook'])) { $params = array('cart' => &$this->cart); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartPreHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } //echo '<pre>'.print_r($this->cart,1); //die(); // custom hook that can be controlled by third-party plugin eof if ($this->cart['user']['country']) { $this->tta_user_info['default']['country'] = $this->cart['user']['country']; $this->tta_user_info['default']['region'] = $this->cart['user']['state']; } unset($this->cart['summarize']); if ($this->tta_user_info['default']['country']) { $iso_customer = mslib_fe::getCountryByName($this->tta_user_info['default']['country']); $iso_customer['country'] = $iso_customer['cn_short_en']; } else { $iso_customer = $this->tta_shop_info; } if (!$iso_customer['cn_iso_nr']) { // fall back (had issue with admin notification) $iso_customer = mslib_fe::getCountryByName($this->tta_shop_info['country']); $iso_customer['country'] = $iso_customer['cn_short_en']; } $vat_id = $this->cart['user']['tx_multishop_vat_id']; // accomodate the submission through onestep checkout for realtime cart preview if (isset($this->post['b_cc']) && !empty($this->post['b_cc']) && $this->post['tx_multishop_vat_id']) { $iso_customer = mslib_fe::getCountryByName($this->post['b_cc']); $iso_customer['country'] = $iso_customer['cn_short_en']; $vat_id = $this->post['tx_multishop_vat_id']; } $this->cart['user']['countries_id'] = $iso_customer['cn_iso_nr']; if (is_array($this->cart['products']) && count($this->cart['products'])) { if ($iso_customer['cn_iso_nr']) { // if store country is different from customer country and user provided valid VAT id, change VAT rate to zero $this->ms['MODULES']['DISABLE_VAT_RATE'] = 0; if ($this->ms['MODULES']['DISABLE_VAT_FOR_FOREIGN_CUSTOMERS_WITH_COMPANY_VAT_ID'] and $vat_id) { if (strtolower($iso_customer['country']) != strtolower($this->tta_shop_info['country'])) { $this->ms['MODULES']['DISABLE_VAT_RATE'] = 1; } } // products if (is_array($this->cart['products'])) { // redirect if products stock are negative or quantity ordered is greater than the stock itself $redirect_to_cart_page = false; foreach ($this->cart['products'] as $key => &$product) { if ($this->get['tx_multishop_pi1']['page_section'] == 'checkout') { //$product_db = mslib_fe::getProduct($product['products_id']); if (!$this->ms['MODULES']['ALLOW_ORDER_OUT_OF_STOCK_PRODUCT']) { if ($product['products_quantity'] < 1) { $redirect_to_cart_page = true; } else { if ($product['qty'] > $product['products_quantity']) { $redirect_to_cart_page = true; } } } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartProductIteratorPreProc'])) { $params = array('product' => $product, 'redirect_to_cart_page' => &$redirect_to_cart_page); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartProductIteratorPreProc'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } //var_dump($redirect_to_cart_page); if ($this->ms['MODULES']['DISABLE_VAT_RATE']) { $product['tax'] = 0; $product['tax_rate'] = 0; } else { $tax_rate = mslib_fe::taxRuleSet($product['tax_id'], 0, $iso_customer['cn_iso_nr'], 0); if (!$tax_rate['total_tax_rate']) { $tax_rate['total_tax_rate'] = 0; } if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { //$product['tax']=mslib_fe::taxDecimalCrop($product['final_price']*($tax_rate['total_tax_rate']/100), 2, false); $product['tax'] = round($product['final_price'] * ($tax_rate['total_tax_rate'] / 100), 2); } else { $product['tax'] = mslib_fe::taxDecimalCrop($product['final_price'] / 100 * $tax_rate['total_tax_rate']); } $product['tax_rate'] = $tax_rate['total_tax_rate'] / 100; } //error_log(print_r($product,1)); $total_attributes_tax = 0; $total_attributes_price = 0; if (is_array($product['attributes'])) { // loading the attributes foreach ($product['attributes'] as $attribute_key => $attribute_values) { $continue = 0; if (is_numeric($attribute_key)) { $str = "SELECT products_options_name,listtype from tx_multishop_products_options o where o.products_options_id='" . $attribute_key . "' "; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry); } if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartAttributesIteratorPreType'])) { $params = array('attribute_key' => &$attribute_key, 'attribute_values' => &$attribute_values, 'row' => &$row); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartAttributesIteratorPreType'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } switch ($row['listtype']) { case 'checkbox': if (is_array($attribute_values) && count($attribute_values)) { foreach ($attribute_values as $attribute_item) { $total_attributes_price += $attribute_item['price_prefix'] . $attribute_item['options_values_price']; if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { //$attributes['tax']=mslib_fe::taxDecimalCrop($attribute_item['options_values_price']*$product['tax_rate'], 2, false); $attributes['tax'] = round(($attribute_item['price_prefix'] . $attribute_item['options_values_price']) * $product['tax_rate'], 2); } else { $attributes['tax'] = mslib_fe::taxDecimalCrop(($attribute_item['price_prefix'] . $attribute_item['options_values_price']) * $product['tax_rate']); } $total_attributes_tax += $attribute_item['price_prefix'] . $attribute_item['tax']; } } break; case 'input': $multiple = 0; $continue = 0; break; default: $multiple = 0; $continue = 1; break; } if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartAttributesIteratorPostType'])) { $params = array('attribute_key' => &$attribute_key, 'attribute_values' => &$attribute_values, 'continue' => &$continue, 'multiple' => &$multiple, 'row' => &$row); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.tx_mslib_cart.php']['getCartAttributesIteratorPostType'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } if ($continue) { $array = array($attribute_values); foreach ($array as $attribute_item) { $total_attributes_price += $attribute_item['price_prefix'] . $attribute_item['options_values_price']; if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { //$attributes['tax']=mslib_fe::taxDecimalCrop($attribute_item['options_values_price']*$product['tax_rate'], 2, false); $attributes['tax'] = round(($attribute_item['price_prefix'] . $attribute_item['options_values_price']) * $product['tax_rate'], 2); } else { $attributes['tax'] = mslib_fe::taxDecimalCrop(($attribute_item['price_prefix'] . $attribute_item['options_values_price']) * $product['tax_rate']); } $total_attributes_tax += $attribute_item['price_prefix'] . $attribute_item['tax']; } } } // loading the attributes eof /*foreach ($product['attributes'] as &$attributes) { $total_attributes_price+=($attributes['options_values_price']); $attributes['tax']=mslib_fe::taxDecimalCrop($attributes['options_values_price']*$product['tax_rate']); $total_attributes_tax+=$attributes['price_prefix'].$attributes['tax']; }*/ } if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { $product['final_price_including_vat'] = $product['final_price'] + $product['tax']; $product['total_price_including_vat'] = ($product['final_price'] + $product['tax'] + ($total_attributes_price + $total_attributes_tax)) * $product['qty']; } else { $product['final_price_including_vat'] = mslib_fe::taxDecimalCrop($product['final_price'] * (1 + $product['tax_rate'])); $product['total_price_including_vat'] = mslib_fe::taxDecimalCrop(($product['final_price'] + $total_attributes_price) * $product['qty'] * (1 + $product['tax_rate'])); } $product['total_price'] = ($product['final_price'] + $total_attributes_price) * $product['qty']; $this->cart['summarize']['sub_total'] += $product['total_price']; $this->cart['summarize']['sub_total_including_vat'] += $product['total_price_including_vat']; } if ($redirect_to_cart_page) { $redirect_to_cart_page = false; $link = mslib_fe::typolink($this->shoppingcart_page_pid, '&tx_multishop_pi1[page_section]=shopping_cart', 1); if ($link) { //header("Location: " . $this->FULL_HTTP_URL . $link); //exit(); } } } // rounding was needed to fix 1 cents grand total difference // adjusted 25/11/2014 14:02 CET // shipping cost bugfix because of the fractions, changed from 2 decimal to 14 $this->cart['user']['shipping_method_costs'] = round($this->cart['user']['shipping_method_costs'], 14); $this->cart['user']['payment_method_costs'] = round($this->cart['user']['payment_method_costs'], 14); // get shipping tax rate $shipping_method = mslib_fe::getShippingMethod($this->cart['user']['shipping_method'], 's.code', $iso_customer['cn_iso_nr']); $tax_rate = mslib_fe::taxRuleSet($shipping_method['tax_id'], 0, $iso_customer['cn_iso_nr'], 0); if ($this->ms['MODULES']['DISABLE_VAT_RATE']) { $tax_rate['total_tax_rate'] = 0; } $shipping_tax_rate = $tax_rate['total_tax_rate'] / 100; // get payment tax rate $payment_method = mslib_fe::getPaymentMethod($this->cart['user']['payment_method'], 'p.code', $iso_customer['cn_iso_nr']); $tax_rate = mslib_fe::taxRuleSet($payment_method['tax_id'], 0, $iso_customer['cn_iso_nr'], 0); if ($this->ms['MODULES']['DISABLE_VAT_RATE']) { $tax_rate['total_tax_rate'] = 0; } $payment_tax_rate = $tax_rate['total_tax_rate'] / 100; if ($shipping_tax_rate > 0) { if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { //$shipping_tax=mslib_fe::taxDecimalCrop($this->cart['user']['shipping_method_costs']*$shipping_tax_rate, 2, false); $shipping_tax = round($this->cart['user']['shipping_method_costs'] * $shipping_tax_rate, 2); } else { $shipping_tax = $this->cart['user']['shipping_method_costs'] * $shipping_tax_rate; } } if ($payment_tax_rate > 0) { if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { //$payment_tax=mslib_fe::taxDecimalCrop($this->cart['user']['payment_method_costs']*$payment_tax_rate, 2, false); $payment_tax = round($this->cart['user']['payment_method_costs'] * $payment_tax_rate, 2); } else { $payment_tax = $this->cart['user']['payment_method_costs'] * $payment_tax_rate; } } if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { $this->cart['user']['shipping_method_costs_including_vat'] = $this->cart['user']['shipping_method_costs'] + $shipping_tax; $this->cart['user']['payment_method_costs_including_vat'] = $this->cart['user']['payment_method_costs'] + $payment_tax; } else { $this->cart['user']['shipping_method_costs_including_vat'] = round($this->cart['user']['shipping_method_costs'] + $this->cart['user']['shipping_method_costs'] * $shipping_tax_rate, 2); $this->cart['user']['payment_method_costs_including_vat'] = round($this->cart['user']['payment_method_costs'] + $this->cart['user']['payment_method_costs'] * $payment_tax_rate, 2); } // discount if (!$this->cart['discount'] and !$GLOBALS["TSFE"]->fe_user->user['uid'] and $this->cart['user']['email']) { // check if guest user is already in the database and if so add possible group discount $user_check = mslib_fe::getUser($this->cart['user']['email'], 'email'); if ($user_check['uid']) { $discount_percentage = mslib_fe::getUserGroupDiscount($user_check['uid']); if ($discount_percentage) { $this->cart['coupon_code'] = ''; $this->cart['discount'] = $discount_percentage; $this->cart['discount_type'] = 'percentage'; } } } if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { $subtotal = $this->cart['summarize']['sub_total']; } else { $subtotal = $this->cart['summarize']['sub_total_including_vat']; } $subtotal_tax = $this->cart['summarize']['sub_total_including_vat'] - $this->cart['summarize']['sub_total']; if ($this->cart['discount']) { switch ($this->cart['discount_type']) { case 'percentage': $discount_percentage = $this->cart['discount']; if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { $discount_price = round($this->cart['summarize']['sub_total'] / 100 * $discount_percentage, 2); $subtotal = $this->cart['summarize']['sub_total'] / 100 * (100 - $discount_percentage); } else { $discount_price = round($this->cart['summarize']['sub_total_including_vat'] / 100 * $discount_percentage, 2); $subtotal = $this->cart['summarize']['sub_total_including_vat'] / 100 * (100 - $discount_percentage); } if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $subtotal_tax = round((1 - $discount_price / $this->cart['summarize']['sub_total_including_vat']) * ($this->cart['summarize']['sub_total_including_vat'] - $this->cart['summarize']['sub_total']), 2); } else { $subtotal_tax = ($this->cart['summarize']['sub_total_including_vat'] - $this->cart['summarize']['sub_total']) / 100 * (100 - $discount_percentage); } $this->cart['discount_amount'] = $discount_price; $this->cart['discount_percentage'] = $discount_percentage; break; case 'price': $discount_price = $this->cart['discount']; if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { $discount_percentage = $this->cart['discount'] / $this->cart['summarize']['sub_total'] * 100; $subtotal = $this->cart['summarize']['sub_total'] / 100 * (100 - $discount_percentage); } else { $discount_percentage = $this->cart['discount'] / $this->cart['summarize']['sub_total_including_vat'] * 100; $subtotal = $this->cart['summarize']['sub_total_including_vat'] / 100 * (100 - $discount_percentage); } if ($this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT']) { $subtotal_tax = round((1 - $discount_price / $this->cart['summarize']['sub_total_including_vat']) * ($this->cart['summarize']['sub_total_including_vat'] - $this->cart['summarize']['sub_total']), 2); } else { $subtotal_tax = ($this->cart['summarize']['sub_total_including_vat'] - $this->cart['summarize']['sub_total']) / 100 * (100 - $discount_percentage); } $this->cart['discount_amount'] = $discount_price; $this->cart['discount_percentage'] = $discount_percentage; break; } } //error_log(print_r($this->cart['products'],1)); // custom hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_cart.php']['getCartPostCalc'])) { $params = array('cart' => &$this->cart, 'subtotal' => &$subtotal, 'subtotal_tax' => &$subtotal_tax); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_cart.php']['getCartPostCalc'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } //echo "<pre>"; //echo $subtotal."<br/>".$subtotal_tax; //print_r($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_cart.php']['getCartPostCalc']); //print_r($product); //die(); // custom hook that can be controlled by third-party plugin eof // calculate totals /*echo $subtotal."<br/>"; echo $subtotal_tax."<br/>"; echo $this->cart['user']['shipping_method_costs_including_vat']."<br/>"; echo $this->cart['user']['payment_method_costs_including_vat']."<br/><br/>"; echo $subtotal_tax."<br/>"; echo $payment_tax."<br/>"; echo $shipping_tax; die();*/ if (!$this->ms['MODULES']['SHOW_PRICES_INCLUDING_VAT'] || $this->ms['MODULES']['FORCE_CHECKOUT_SHOW_PRICES_INCLUDING_VAT']) { $this->cart['summarize']['grand_total_excluding_vat'] = $subtotal + $this->cart['user']['shipping_method_costs'] + $this->cart['user']['payment_method_costs']; $this->cart['summarize']['grand_total'] = $subtotal + $subtotal_tax + ($this->cart['user']['shipping_method_costs_including_vat'] + $this->cart['user']['payment_method_costs_including_vat']); } else { $this->cart['summarize']['grand_total_excluding_vat'] = $subtotal - $subtotal_tax + $this->cart['user']['shipping_method_costs'] + $this->cart['user']['payment_method_costs']; $this->cart['summarize']['grand_total'] = $subtotal + ($this->cart['user']['shipping_method_costs_including_vat'] + $this->cart['user']['payment_method_costs_including_vat']); } // to make sure the floatings numbers are not infinite $this->cart['summarize']['grand_total'] = number_format($this->cart['summarize']['grand_total'], 14, '.', ''); //var_dump($this->cart['summarize']['grand_total']); //$this->cart['summarize']['grand_total_vat']=($this->cart['summarize']['grand_total']-$this->cart['summarize']['grand_total_excluding_vat']); $this->cart['summarize']['grand_total_vat'] = $subtotal_tax + $payment_tax + $shipping_tax; // b2b mode 1 cent bugfix: 2013-05-09 cbc // I have fixed the b2b issue by updating all the products prices in the database to have max 2 decimals // therefore I disabled below bugfix, cause thats a ducktape solution that can break b2c sites //$this->cart['summarize']['grand_total']=round($this->cart['summarize']['grand_total_excluding_vat'],2) + round($this->cart['summarize']['grand_total_vat'],2); //print_r($this->cart); } } // custom hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_cart.php']['getCartPreSave'])) { $params = array('cart' => &$this->cart); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_cart.php']['getCartPreSave'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } // custom hook that can be controlled by third-party plugin eofq tx_mslib_cart::storeCart($this->cart); //if (is_array($this->cart['products']) && count($this->cart['products'])) { //tx_mslib_cart::storeCart($this->cart); //} //$GLOBALS['TSFE']->fe_user->setKey('ses', $this->cart_page_uid, $this->cart); //$GLOBALS['TSFE']->fe_user->storeSessionData(); return $this->cart; }
<?php if (!defined('TYPO3_MODE')) { die('Access denied.'); } require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('multishop') . 'pi1/classes/class.tx_mslib_cart.php'; $content = '0%'; // first check group discount if ($GLOBALS["TSFE"]->fe_user->user['uid']) { $discount_percentage = mslib_fe::getUserGroupDiscount($GLOBALS["TSFE"]->fe_user->user['uid']); if ($discount_percentage) { $mslib_cart = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_mslib_cart'); $mslib_cart->init($this); $cart = $mslib_cart->getCart(); $cart['coupon_code'] = ''; $cart['discount'] = $discount_percentage; $cart['discount_type'] = 'percentage'; //$GLOBALS['TSFE']->fe_user->setKey('ses', $this->cart_page_uid, $cart); //$GLOBALS['TSFE']->fe_user->storeSessionData(); tx_mslib_cart::storeCart($cart); $content = number_format($discount_percentage) . '%'; } } //if(!$discount_percentage) if (!empty($_POST['code']) && $_POST['code'] != 'undefined') { $code = mslib_fe::RemoveXSS(mslib_befe::strtolower($_POST['code'])); $time = time(); $str = "SELECT * from tx_multishop_coupons where code = '" . addslashes($code) . "' and status = 1 and (page_uid=0 or page_uid='" . $this->showCatalogFromPage . "') and (startdate <= '" . $time . "' and enddate >= '" . $time . "')"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry);