Example #1
0
    /**
     * Write the order header record
     *
     * @author Oscar van Eijk
     * @param object $_cart The cart data
     * @param object $_usr User object
     * @param array $_prices Price data
     * @return integer The new ordernumber
     */
    private function _createOrder($_cart, $_usr, $_prices)
    {
        //		TODO We need tablefields for the new values:
        //		Shipment:
        //		$_prices['shipmentValue']		w/out tax
        //		$_prices['shipmentTax']			Tax
        //		$_prices['salesPriceShipment']	Total
        //
        //		Payment:
        //		$_prices['paymentValue']		w/out tax
        //		$_prices['paymentTax']			Tax
        //		$_prices['paymentDiscount']		Discount
        //		$_prices['salesPricePayment']	Total
        $_orderData = new stdClass();
        $_orderData->virtuemart_order_id = null;
        $_orderData->virtuemart_user_id = $_usr->get('id');
        $_orderData->virtuemart_vendor_id = $_cart->vendorId;
        $_orderData->customer_number = $_cart->customer_number;
        //Note as long we do not have an extra table only storing addresses, the virtuemart_userinfo_id is not needed.
        //The virtuemart_userinfo_id is just the id of a stored address and is only necessary in the user maintance view or for choosing addresses.
        //the saved order should be an snapshot with plain data written in it.
        //		$_orderData->virtuemart_userinfo_id = 'TODO'; // $_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete?
        $_orderData->order_total = $_prices['billTotal'];
        $_orderData->order_salesPrice = $_prices['salesPrice'];
        $_orderData->order_billTaxAmount = $_prices['billTaxAmount'];
        $_orderData->order_billDiscountAmount = $_prices['billDiscountAmount'];
        $_orderData->order_discountAmount = $_prices['discountAmount'];
        $_orderData->order_subtotal = $_prices['priceWithoutTax'];
        $_orderData->order_tax = $_prices['taxAmount'];
        $_orderData->order_shipment = $_prices['shipmentValue'];
        $_orderData->order_shipment_tax = $_prices['shipmentTax'];
        $_orderData->order_payment = $_prices['paymentValue'];
        $_orderData->order_payment_tax = $_prices['paymentTax'];
        if (!empty($_cart->cartData['VatTax'])) {
            $taxes = array();
            foreach ($_cart->cartData['VatTax'] as $k => $VatTax) {
                $taxes[$k]['virtuemart_calc_id'] = $k;
                $taxes[$k]['calc_name'] = $VatTax['calc_name'];
                $taxes[$k]['calc_value'] = $VatTax['calc_value'];
                $taxes[$k]['result'] = $VatTax['result'];
            }
            $_orderData->order_billTax = json_encode($taxes);
        }
        if (!empty($_cart->couponCode)) {
            $_orderData->coupon_code = $_cart->couponCode;
            $_orderData->coupon_discount = $_prices['salesPriceCoupon'];
        }
        $_orderData->order_discount = $_prices['discountAmount'];
        // discount order_items
        $_orderData->order_status = 'P';
        $_orderData->order_currency = $this->getVendorCurrencyId($_orderData->virtuemart_vendor_id);
        if (isset($_cart->pricesCurrency)) {
            $_orderData->user_currency_id = $_cart->paymentCurrency;
            //$this->getCurrencyIsoCode($_cart->pricesCurrency);
            $currency = CurrencyDisplay::getInstance($_orderData->user_currency_id);
            if ($_orderData->user_currency_id != $_orderData->order_currency) {
                $_orderData->user_currency_rate = $currency->convertCurrencyTo($_orderData->user_currency_id, 1.0, false);
            } else {
                $_orderData->user_currency_rate = 1.0;
            }
        }
        $_orderData->virtuemart_paymentmethod_id = $_cart->virtuemart_paymentmethod_id;
        $_orderData->virtuemart_shipmentmethod_id = $_cart->virtuemart_shipmentmethod_id;
        $_filter = JFilterInput::getInstance(array('br', 'i', 'em', 'b', 'strong'), array(), 0, 0, 1);
        $_orderData->customer_note = $_filter->clean($_cart->customer_comment);
        $_orderData->order_language = $_cart->order_language;
        $_orderData->ip_address = $_SERVER['REMOTE_ADDR'];
        /*if(!empty( $_cart->order_number)){
        			$_orderData->order_number = $_cart->order_number;
        		} else {*/
        $_orderData->order_number = '';
        $_orderData->order_pass = '';
        //}
        $maskIP = VmConfig::get('maskIP', 'last');
        if ($maskIP == 'last') {
            $rpos = strrpos($_orderData->ip_address, '.');
            $_orderData->ip_address = substr($_orderData->ip_address, 0, $rpos + 1) . 'xx';
        }
        $orderTable = $this->getTable('orders');
        if ($_cart->_inConfirm) {
            $order = false;
            $db = JFactory::getDbo();
            $q = 'SELECT * FROM `#__virtuemart_orders` ';
            if (!empty($_cart->virtuemart_order_id)) {
                $db->setQuery($q . ' WHERE `virtuemart_order_id`= "' . $_cart->virtuemart_order_id . '" AND `order_status` = "P"');
                $order = $db->loadAssoc();
                if (!$order) {
                    $_cart->virtuemart_order_id = null;
                    vmdebug('This should not happen (but does due some payments deleting the order in the cancel case), there is a cart with virtuemart_order_id, but not order stored');
                }
            }
            if (VmConfig::get('reuseorders', true) and !$order) {
                $jnow = JFactory::getDate();
                $jnow->sub(new DateInterval('PT1H'));
                $minushour = $jnow->toMySQL();
                $q .= ' WHERE `customer_number`= "' . $_orderData->customer_number . '" ';
                $q .= '	AND `order_status` = "P"
				AND `created_on` > "' . $minushour . '" ';
                $db->setQuery($q);
                $order = $db->loadAssoc();
                if (!$order) {
                    $_cart->virtuemart_order_id = null;
                }
            }
            if ($order) {
                $_orderData->virtuemart_order_id = $order['virtuemart_order_id'];
                //We do not keep the order_number anylonger, makes too much trouble.
                /*if(!empty($order['order_number'])){
                			$_orderData->order_number = $order['order_number'];
                			$_orderData->order_pass = $order['order_pass'];
                		}*/
                //Dirty hack
                $this->removeOrderItems($order['virtuemart_order_id']);
            }
        }
        JPluginHelper::importPlugin('vmshopper');
        $dispatcher = JDispatcher::getInstance();
        $plg_datas = $dispatcher->trigger('plgVmOnUserOrder', array(&$_orderData));
        foreach ($plg_datas as $plg_data) {
            // 				$data = array_merge($plg_data,$data);
        }
        if (empty($_orderData->order_number)) {
            $_orderData->order_number = $this->generateOrderNumber($_usr->get('id'), 4, $_orderData->virtuemart_vendor_id);
        }
        if (empty($_orderData->order_pass)) {
            $_orderData->order_pass = '******' . substr(md5((string) time() . rand(1, 1000) . $_orderData->order_number), 0, 5);
        }
        $orderTable->bindChecknStore($_orderData);
        $errors = $orderTable->getErrors();
        foreach ($errors as $error) {
            vmError($error);
        }
        if (!empty($_cart->couponCode)) {
            //set the virtuemart_order_id in the Request for 3rd party coupon components (by Seyi and Max)
            JRequest::setVar('virtuemart_order_id', $orderTable->virtuemart_order_id);
            // If a gift coupon was used, remove it now
            //CouponHelper::RemoveCoupon($_cart->couponCode);
            CouponHelper::setInUseCoupon($_cart->couponCode, true);
        }
        // the order number is saved into the session to make sure that the correct cart is emptied with the payment notification
        $_cart->order_number = $orderTable->order_number;
        $_cart->virtuemart_order_id = $orderTable->virtuemart_order_id;
        $_cart->setCartIntoSession();
        return $orderTable->virtuemart_order_id;
    }
Example #2
0
 /**
  * PaymentUserCancel()
  * From the payment page, the user has cancelled the order. The order previousy created is deleted.
  * The cart is not emptied, so the user can reorder if necessary.
  * then delete the order
  *
  */
 function pluginUserPaymentCancel()
 {
     if (!class_exists('vmPSPlugin')) {
         require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
     }
     if (!class_exists('VirtueMartCart')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
     }
     $cart = VirtueMartCart::getCart();
     $cart->prepareCartData();
     if (!empty($cart->couponCode)) {
         if (!class_exists('CouponHelper')) {
             require VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php';
         }
         CouponHelper::setInUseCoupon($cart->couponCode, false);
     }
     JPluginHelper::importPlugin('vmpayment');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('plgVmOnUserPaymentCancel', array());
     // return to cart view
     $view = $this->getView('cart', 'html');
     $layoutName = vRequest::getCmd('layout', 'default');
     $view->setLayout($layoutName);
     // Display it all
     $view->display();
 }
Example #3
0
 /**
  * Write the order header record
  *
  * @author Oscar van Eijk
  * @param object $_cart The cart data
  * @param object $_usr User object
  * @param array $_prices Price data
  * @return integer The new ordernumber
  */
 private function _createOrder($_cart, $_usr, $_prices)
 {
     //		TODO We need tablefields for the new values:
     //		Shipment:
     //		$_prices['shipmentValue']		w/out tax
     //		$_prices['shipmentTax']			Tax
     //		$_prices['salesPriceShipment']	Total
     //
     //		Payment:
     //		$_prices['paymentValue']		w/out tax
     //		$_prices['paymentTax']			Tax
     //		$_prices['paymentDiscount']		Discount
     //		$_prices['salesPricePayment']	Total
     $_orderData = new stdClass();
     $_orderData->virtuemart_order_id = null;
     $_orderData->virtuemart_user_id = $_usr->get('id');
     $_orderData->virtuemart_vendor_id = $_cart->vendorId;
     $_orderData->customer_number = $_cart->customer_number;
     //Note as long we do not have an extra table only storing addresses, the virtuemart_userinfo_id is not needed.
     //The virtuemart_userinfo_id is just the id of a stored address and is only necessary in the user maintance view or for choosing addresses.
     //the saved order should be an snapshot with plain data written in it.
     //		$_orderData->virtuemart_userinfo_id = 'TODO'; // $_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete?
     $_orderData->order_total = $_prices['billTotal'];
     $_orderData->order_salesPrice = $_prices['salesPrice'];
     $_orderData->order_billTaxAmount = $_prices['billTaxAmount'];
     $_orderData->order_billDiscountAmount = $_prices['billDiscountAmount'];
     $_orderData->order_discountAmount = $_prices['discountAmount'];
     $_orderData->order_subtotal = $_prices['priceWithoutTax'];
     $_orderData->order_tax = $_prices['taxAmount'];
     $_orderData->order_shipment = $_prices['shipmentValue'];
     $_orderData->order_shipment_tax = $_prices['shipmentTax'];
     $_orderData->order_payment = $_prices['paymentValue'];
     $_orderData->order_payment_tax = $_prices['paymentTax'];
     if (!empty($_cart->cartData['VatTax'])) {
         $taxes = array();
         foreach ($_cart->cartData['VatTax'] as $k => $VatTax) {
             $taxes[$k]['virtuemart_calc_id'] = $k;
             $taxes[$k]['calc_name'] = $VatTax['calc_name'];
             $taxes[$k]['calc_value'] = $VatTax['calc_value'];
             $taxes[$k]['result'] = $VatTax['result'];
         }
         $_orderData->order_billTax = json_encode($taxes);
     }
     if (!empty($_cart->couponCode)) {
         $_orderData->coupon_code = $_cart->couponCode;
         $_orderData->coupon_discount = $_prices['salesPriceCoupon'];
     }
     $_orderData->order_discount = $_prices['discountAmount'];
     // discount order_items
     $_orderData->order_status = 'P';
     $_orderData->order_currency = $this->getVendorCurrencyId($_orderData->virtuemart_vendor_id);
     if (isset($_cart->pricesCurrency)) {
         $_orderData->user_currency_id = $_cart->paymentCurrency;
         //$this->getCurrencyIsoCode($_cart->pricesCurrency);
         $currency = CurrencyDisplay::getInstance($_orderData->user_currency_id);
         if ($_orderData->user_currency_id != $_orderData->order_currency) {
             $_orderData->user_currency_rate = $currency->convertCurrencyTo($_orderData->user_currency_id, 1.0, false);
         } else {
             $_orderData->user_currency_rate = 1.0;
         }
     }
     $_orderData->virtuemart_paymentmethod_id = $_cart->virtuemart_paymentmethod_id;
     $_orderData->virtuemart_shipmentmethod_id = $_cart->virtuemart_shipmentmethod_id;
     $_filter = JFilterInput::getInstance(array('br', 'i', 'em', 'b', 'strong'), array(), 0, 0, 1);
     $_orderData->customer_note = $_filter->clean($_cart->customer_comment);
     $_orderData->order_language = $_cart->order_language;
     $_orderData->ip_address = $_SERVER['REMOTE_ADDR'];
     $_orderData->order_number = '';
     JPluginHelper::importPlugin('vmshopper');
     $dispatcher = JDispatcher::getInstance();
     $plg_datas = $dispatcher->trigger('plgVmOnUserOrder', array(&$_orderData));
     foreach ($plg_datas as $plg_data) {
         // 				$data = array_merge($plg_data,$data);
     }
     if (empty($_orderData->order_number)) {
         $_orderData->order_number = $this->generateOrderNumber($_usr->get('id'), 4, $_orderData->virtuemart_vendor_id);
     }
     if (empty($_orderData->order_pass)) {
         $_orderData->order_pass = '******' . substr(md5((string) time() . rand(1, 1000) . $_orderData->order_number), 0, 5);
     }
     $orderTable = $this->getTable('orders');
     $orderTable->bindChecknStore($_orderData);
     $errors = $orderTable->getErrors();
     foreach ($errors as $error) {
         vmError($error);
     }
     $db = JFactory::getDBO();
     $_orderID = $db->insertid();
     if (!empty($_cart->couponCode)) {
         //set the virtuemart_order_id in the Request for 3rd party coupon components (by Seyi and Max)
         JRequest::setVar('virtuemart_order_id', $_orderData->virtuemart_order_id);
         // If a gift coupon was used, remove it now
         //CouponHelper::RemoveCoupon($_cart->couponCode);
         CouponHelper::setInUseCoupon($_cart->couponCode, true);
     }
     // the order number is saved into the session to make sure that the correct cart is emptied with the payment notification
     $_cart->order_number = $_orderData->order_number;
     $_cart->setCartIntoSession();
     return $_orderID;
 }
 public static function onAfterDispatch()
 {
     $is_ajax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
     $is_ajax_from_minicart_pro = (int) JRequest::getVar('vm_minicart_ajax', 0);
     if ($is_ajax && $is_ajax_from_minicart_pro) {
         if (!class_exists('VmConfig')) {
             require JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php';
         }
         VmConfig::loadConfig();
         if (!class_exists('calculationHelper')) {
             require JPATH_VM_SITE . '/helpers/cart.php';
         }
         switch (JRequest::getCmd('minicart_task')) {
             case 'setcoupon':
                 $coupon_code = JRequest::getVar('coupon_code', '');
                 $cart = VirtueMartCart::getCart(false);
                 $viewName = vRequest::getString('view', 0);
                 if ($viewName == 'cart') {
                     $checkAutomaticPS = true;
                 } else {
                     $checkAutomaticPS = false;
                 }
                 $cart->prepareAjaxData($checkAutomaticPS);
                 $result = new stdClass();
                 if ($cart) {
                     $msg = $cart->setCouponCode($coupon_code);
                     if (empty($msg)) {
                         $result->status = 0;
                         $result->message = $msg;
                     } else {
                         $result->status = 1;
                         $result->message = $cart->couponCode;
                     }
                 } else {
                     $result->status = 0;
                     $result->message = 'no cart';
                 }
                 if ($coupon_code == 'null') {
                     $cart->couponCode = '';
                     $cart->setCartIntoSession();
                 }
                 die(json_encode($result));
                 break;
             case 'update':
                 $cart_virtuemart_product_id = JRequest::getVar('cart_virtuemart_product_id', array(), 'POST', 'array');
                 $quantity_post = JRequest::getVar('quantity', array(), 'POST', 'array');
                 $cart = VirtueMartCart::getCart(false);
                 $cartProductsData = $cart->cartProductsData;
                 $result = new stdClass();
                 if (!empty($cartProductsData)) {
                     $count1 = 0;
                     $count2 = 0;
                     $quantity = array();
                     $product_indexs = JRequest::getVar('product_index', array(), 'POST', 'array');
                     foreach ($product_indexs as $i => $pro) {
                         if (isset($cartProductsData[$pro]) && isset($quantity_post[$i])) {
                             $cartProductsData[$pro]['quantity'] = $quantity_post[$i];
                         }
                         $quantity[$pro] = $cartProductsData[$pro]['quantity'];
                     }
                     JRequest::setVar('quantity', $quantity);
                     $msg = $cart->updateProductCart();
                     $result->status = '1';
                     $result->message = 'Update success update.';
                 } else {
                     $result->status = 0;
                     $result->message = 'no cart';
                 }
                 die(json_encode($result));
                 break;
             case 'refresh':
                 ob_start();
                 $db = JFactory::getDbo();
                 $db->setQuery('SELECT * FROM #__modules WHERE id=' . JRequest::getInt('minicart_modid'));
                 $result = $db->loadObject();
                 if (isset($result->module)) {
                     echo JModuleHelper::renderModule($result);
                 }
                 $list_html = ob_get_contents();
                 ob_end_clean();
                 $cart = VirtueMartCart::getCart(false);
                 if (self::$_coupon_code == 'null') {
                     CouponHelper::setInUseCoupon($cart->couponCode, false);
                     die('fffffffffff');
                 }
                 $viewName = vRequest::getString('view', 0);
                 if ($viewName == 'cart') {
                     $checkAutomaticPS = true;
                 } else {
                     $checkAutomaticPS = false;
                 }
                 $cart->prepareAjaxData($checkAutomaticPS);
                 $vm_currency_display = CurrencyDisplay::getInstance();
                 $lang = JFactory::getLanguage();
                 $extension = 'com_virtuemart';
                 $lang->load($extension);
                 $cart->billTotal = ' - <strong>' . $vm_currency_display->priceDisplay($cart->cartPrices['billTotal']) . '</strong>';
                 $cart->billTotal_Footer = $lang->_('COM_VIRTUEMART_CART_TOTAL') . ' : <strong>' . $vm_currency_display->priceDisplay($cart->cartPrices['billTotal']) . '</strong>';
                 $result = new stdClass();
                 $result->list_html = $list_html;
                 $result->billTotal = $cart->billTotal;
                 $result->billTotal_Footer = $cart->billTotal_Footer;
                 $result->length = count($cart->products);
                 die(json_encode($result));
                 break;
             case 'delete':
                 $cart_virtuemart_product_id = JRequest::getVar('cart_virtuemart_product_id');
                 $cart = VirtueMartCart::getCart(false);
                 $result = new stdClass();
                 $cartProductsData = $cart->cartProductsData;
                 if (!empty($cartProductsData)) {
                     $quantity = array();
                     foreach ($cartProductsData as $key => $cartpro) {
                         if ($cartProductsData[$key]['virtuemart_product_id'] == $cart_virtuemart_product_id) {
                             $cartProductsData[$key]['quantity'] = 0;
                         }
                         $quantity[$key] = $cartProductsData[$key]['quantity'];
                     }
                     JRequest::setVar('quantity', $quantity);
                     $msg = $cart->updateProductCart();
                     $result->status = 1;
                     $result->message = 'success delete';
                 } else {
                     $result->status = 0;
                     $result->message = 'no cart';
                 }
                 die(json_encode($result));
                 break;
             default:
                 die('invalid task');
                 break;
         }
         die;
     }
 }
Example #5
0
    /**
     * Write the order header record
     *
     * @author Oscar van Eijk
     * @param object $_cart The cart data
     * @param object $_usr User object
     * @param array $_prices Price data
     * @return integer The new ordernumber
     */
    private function _createOrder($_cart, $_usr)
    {
        //		TODO We need tablefields for the new values:
        //		Shipment:
        //		$_prices['shipmentValue']		w/out tax
        //		$_prices['shipmentTax']			Tax
        //		$_prices['salesPriceShipment']	Total
        //
        //		Payment:
        //		$_prices['paymentValue']		w/out tax
        //		$_prices['paymentTax']			Tax
        //		$_prices['paymentDiscount']		Discount
        //		$_prices['salesPricePayment']	Total
        $_orderData = new stdClass();
        $_orderData->virtuemart_order_id = null;
        $_orderData->virtuemart_user_id = $_usr->get('id');
        $_orderData->virtuemart_vendor_id = $_cart->vendorId;
        $_orderData->customer_number = $_cart->customer_number;
        $_prices = $_cart->cartPrices;
        //Note as long we do not have an extra table only storing addresses, the virtuemart_userinfo_id is not needed.
        //The virtuemart_userinfo_id is just the id of a stored address and is only necessary in the user maintance view or for choosing addresses.
        //the saved order should be an snapshot with plain data written in it.
        //		$_orderData->virtuemart_userinfo_id = 'TODO'; // $_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete?
        $_orderData->order_total = $_prices['billTotal'];
        $_orderData->order_salesPrice = $_prices['salesPrice'];
        $_orderData->order_billTaxAmount = $_prices['billTaxAmount'];
        $_orderData->order_billDiscountAmount = $_prices['billDiscountAmount'];
        $_orderData->order_discountAmount = $_prices['discountAmount'];
        $_orderData->order_subtotal = $_prices['priceWithoutTax'];
        $_orderData->order_tax = $_prices['taxAmount'];
        $_orderData->order_shipment = $_prices['shipmentValue'];
        $_orderData->order_shipment_tax = $_prices['shipmentTax'];
        $_orderData->order_payment = $_prices['paymentValue'];
        $_orderData->order_payment_tax = $_prices['paymentTax'];
        if (!empty($_cart->cartData['VatTax'])) {
            $taxes = array();
            foreach ($_cart->cartData['VatTax'] as $k => $VatTax) {
                $taxes[$k]['virtuemart_calc_id'] = $k;
                $taxes[$k]['calc_name'] = $VatTax['calc_name'];
                $taxes[$k]['calc_value'] = $VatTax['calc_value'];
                $taxes[$k]['result'] = $VatTax['result'];
            }
            $_orderData->order_billTax = json_encode($taxes);
        }
        if (!empty($_cart->couponCode)) {
            $_orderData->coupon_code = $_cart->couponCode;
            $_orderData->coupon_discount = $_prices['salesPriceCoupon'];
        }
        $_orderData->order_discount = $_prices['discountAmount'];
        // discount order_items
        $_orderData->order_status = 'P';
        $_orderData->order_currency = $this->getVendorCurrencyId($_orderData->virtuemart_vendor_id);
        if (!class_exists('CurrencyDisplay')) {
            require VMPATH_ADMIN . '/helpers/currencydisplay.php';
        }
        if (isset($_cart->pricesCurrency)) {
            $_orderData->user_currency_id = $_cart->paymentCurrency;
            //$this->getCurrencyIsoCode($_cart->pricesCurrency);
            $currency = CurrencyDisplay::getInstance($_orderData->user_currency_id);
            if ($_orderData->user_currency_id != $_orderData->order_currency) {
                $_orderData->user_currency_rate = $currency->convertCurrencyTo($_orderData->user_currency_id, 1.0, false);
            } else {
                $_orderData->user_currency_rate = 1.0;
            }
        }
        $_orderData->virtuemart_paymentmethod_id = $_cart->virtuemart_paymentmethod_id;
        $_orderData->virtuemart_shipmentmethod_id = $_cart->virtuemart_shipmentmethod_id;
        //Some payment plugins need a new order_number for any try
        $_orderData->order_number = '';
        $_orderData->order_pass = '';
        $_orderData->order_language = $_cart->order_language;
        $_orderData->ip_address = $_SERVER['REMOTE_ADDR'];
        $maskIP = VmConfig::get('maskIP', 'last');
        if ($maskIP == 'last') {
            $rpos = strrpos($_orderData->ip_address, '.');
            $_orderData->ip_address = substr($_orderData->ip_address, 0, $rpos + 1) . 'xx';
        }
        if ($_cart->_inConfirm) {
            $order = false;
            $db = JFactory::getDbo();
            $q = 'SELECT * FROM `#__virtuemart_orders` ';
            if (!empty($_cart->virtuemart_order_id)) {
                $db->setQuery($q . ' WHERE `order_number`= "' . $_cart->virtuemart_order_id . '" AND `order_status` = "P" ');
                $order = $db->loadAssoc();
                if (!$order) {
                    vmdebug('This should not happen, there is a cart with order_number, but not order stored ' . $_cart->virtuemart_order_id);
                }
            }
            if (VmConfig::get('reuseorders', true) and !$order) {
                $jnow = JFactory::getDate();
                $jnow->sub(new DateInterval('PT1H'));
                $minushour = $jnow->toSQL();
                $q .= ' WHERE `customer_number`= "' . $_orderData->customer_number . '" ';
                $q .= '	AND `order_status` = "P"
				AND `created_on` > "' . $minushour . '" ';
                $db->setQuery($q);
                $order = $db->loadAssoc();
            }
            if ($order) {
                if (!empty($order['virtuemart_order_id'])) {
                    $_orderData->virtuemart_order_id = $order['virtuemart_order_id'];
                }
                //Dirty hack
                $this->removeOrderItems($order['virtuemart_order_id']);
            }
        }
        //lets merge here the userdata from the cart to the order so that it can be used
        if (!empty($_cart->BT)) {
            foreach ($_cart->BT as $k => $v) {
                $_orderData->{$k} = $v;
            }
        }
        JPluginHelper::importPlugin('vmshopper');
        JPluginHelper::importPlugin('vmextended');
        $dispatcher = JDispatcher::getInstance();
        $plg_datas = $dispatcher->trigger('plgVmOnUserOrder', array(&$_orderData));
        foreach ($plg_datas as $plg_data) {
            // 				$data = array_merge($plg_data,$data);
        }
        if (empty($_orderData->order_number)) {
            $_orderData->order_number = $this->genStdOrderNumber($_orderData->virtuemart_vendor_id);
        }
        if (empty($_orderData->order_pass)) {
            $_orderData->order_pass = $this->genStdOrderPass();
        }
        if (empty($_orderData->order_create_invoice_pass)) {
            $_orderData->order_create_invoice_pass = $this->genStdCreateInvoicePass();
        }
        $orderTable = $this->getTable('orders');
        $orderTable->bindChecknStore($_orderData);
        $db = JFactory::getDBO();
        if (!empty($_cart->couponCode)) {
            //set the virtuemart_order_id in the Request for 3rd party coupon components (by Seyi and Max)
            vRequest::setVar('virtuemart_order_id', $orderTable->virtuemart_order_id);
            // If a gift coupon was used, remove it now
            CouponHelper::setInUseCoupon($_cart->couponCode, true);
        }
        // the order number is saved into the session to make sure that the correct cart is emptied with the payment notification
        $_cart->order_number = $orderTable->order_number;
        $_cart->order_pass = $_orderData->order_pass;
        $_cart->virtuemart_order_id = $orderTable->virtuemart_order_id;
        $_cart->setCartIntoSession();
        return $orderTable->virtuemart_order_id;
    }