static function checkVMCoupon($coupon_code, $summ) { if (!class_exists('CouponHelper')) { require VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php'; } $msg = CouponHelper::ValidateCouponCode($coupon_code, $summ); return $msg; }
/** * 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; //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->couponCode)) { $_orderData->coupon_code = $_cart->couponCode; $_orderData->coupon_discount = $_prices['salesPriceCoupon']; } $_orderData->order_discount = $_prices['discountAmount']; // discount order_items $_orderData->order_status = 'P'; if (isset($_cart->pricesCurrency)) { $_orderData->user_currency_id = $_cart->pricesCurrency; //$this->getCurrencyIsoCode($_cart->pricesCurrency); $currency = CurrencyDisplay::getInstance(); if (!empty($currency->exchangeRateShopper)) { $_orderData->user_currency_rate = $currency->exchangeRateShopper; } else { $_orderData->user_currency_rate = 1.0; } } $_orderData->order_currency = $this->getVendorCurrencyId($_orderData->virtuemart_vendor_id); $_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->ip_address = $_SERVER['REMOTE_ADDR']; $_orderData->ip_address = $_SERVER['HTTP_X_REAL_IP']; $_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); } // 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; }
private function checkoutData($redirect = true) { $this->_redirect = $redirect; $this->_inCheckOut = true; $this->tosAccepted = JRequest::getInt('tosAccepted', $this->tosAccepted); $this->STsameAsBT = JRequest::getInt('STsameAsBT', $this->STsameAsBT); $this->customer_comment = JRequest::getVar('customer_comment', $this->customer_comment); $this->order_language = JRequest::getVar('order_language', $this->order_language); // no HTML TAGS but permit all alphabet $value = preg_replace('@<[\\/\\!]*?[^<>]*?>@si', '', $this->customer_comment); //remove all html tags $value = (string) preg_replace('#on[a-z](.+?)\\)#si', '', $value); //replace start of script onclick() onload()... $value = trim(str_replace('"', ' ', $value), "'"); $this->customer_comment = (string) preg_replace('#^\'#si', '', $value); //replace ' at start $this->cartData = $this->prepareCartData(); $this->prepareCartPrice(); if (empty($this->tosAccepted)) { $userFieldsModel = VmModel::getModel('Userfields'); //$required = $userFieldsModel->getIfRequired('agreed'); $agreed = $userFieldsModel->getUserfield('agreed', 'name'); //vmdebug('my new getUserfieldbyName',$agreed->default,$agreed->required); if (!empty($agreed->required) and empty($agreed->default) and !empty($this->BT)) { $redirectMsg = null; // JText::_('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS'); vmInfo('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS', 'COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS'); return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } else { if ($agreed->default) { $this->tosAccepted = $agreed->default; } } } if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) { JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models'); $userModel = JModel::getInstance('user', 'VirtueMartModel'); $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto); $stData = get_object_vars($stData[0]); if ($this->validateUserData('ST', $stData)) { $this->ST = $stData; } } if (count($this->products) == 0) { return $this->redirecter('index.php?option=com_virtuemart', JText::_('COM_VIRTUEMART_CART_NO_PRODUCT')); } else { foreach ($this->products as $product) { $redirectMsg = $this->checkForQuantities($product, $product->quantity); if (!$redirectMsg) { return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } } } // Check if a minimun purchase value is set if (($redirectMsg = $this->checkPurchaseValue()) != null) { return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } //$this->prepareAddressDataInCart(); //But we check the data again to be sure if (empty($this->BT)) { $redirectMsg = ''; return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT', $redirectMsg); } else { $redirectMsg = self::validateUserData(); if (!$redirectMsg) { return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT', ''); } } if ($this->STsameAsBT !== 0) { $this->ST = $this->BT; } else { //Only when there is an ST data, test if all necessary fields are filled if (!empty($this->ST)) { $redirectMsg = self::validateUserData('ST'); if (!$redirectMsg) { return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=ST', ''); } } } if (VmConfig::get('oncheckout_only_registered', 0)) { $currentUser = JFactory::getUser(); if (empty($currentUser->id)) { $redirectMsg = JText::_('COM_VIRTUEMART_CART_ONLY_REGISTERED'); return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT', $redirectMsg); } } vmdebug('ValidateCouponCode ValidateCouponCode ValidateCouponCode', $this->couponCode); // Test Coupon if (!empty($this->couponCode)) { //$prices = $this->getCartPrices(); if (!class_exists('CouponHelper')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php'; } if (!in_array($this->couponCode, $this->_triesValidateCoupon)) { $this->_triesValidateCoupon[] = $this->couponCode; } if (count($this->_triesValidateCoupon) < 8) { $redirectMsg = CouponHelper::ValidateCouponCode($this->couponCode, $this->pricesUnformatted['salesPrice']); } else { $redirectMsg = JText::_('COM_VIRTUEMART_CART_COUPON_TOO_MANY_TRIES'); } if (!empty($redirectMsg)) { $this->couponCode = ''; $this->getCartPrices(); $this->setCartIntoSession(); return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } } $redirectMsg = ''; //Test Shipment and show shipment plugin if (empty($this->virtuemart_shipmentmethod_id)) { return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=edit_shipment', $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmshipment'); //Add a hook here for other shipment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataShipment', array($this)); //vmdebug('plgVmOnCheckoutCheckDataShipment CART', $retValues); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesfull; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=edit_shipment', $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } //Test Payment and show payment plugin if ($this->pricesUnformatted['salesPrice'] > 0.0) { if (empty($this->virtuemart_paymentmethod_id)) { return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=editpayment', $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); //Add a hook here for other payment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataPayment', array($this)); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesful; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=editpayment', $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } } //Show cart and checkout data overview $this->_inCheckOut = false; if ($this->_blockConfirm) { return $this->redirecter('index.php?option=com_virtuemart&view=cart', ''); } else { $this->_dataValidated = true; $this->setCartIntoSession(); return true; } }
/** * 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; }
private function checkoutData($redirect = true) { $this->_redirect = $redirect; $this->_inCheckOut = true; $this->setCartIntoSession(); session_write_close(); session_start(); $this->tosAccepted = JRequest::getInt('tosAccepted', $this->tosAccepted); $this->STsameAsBT = JRequest::getInt('STsameAsBT', $this->STsameAsBT); $this->order_language = JRequest::getVar('order_language', $this->order_language); $this->getFilterCustomerComment(); $this->cartData = $this->prepareCartData(); $this->prepareCartPrice(); if (count($this->products) == 0) { return $this->redirecter('index.php?option=com_virtuemart', JText::_('COM_VIRTUEMART_CART_NO_PRODUCT')); } else { foreach ($this->products as $product) { $redirectMsg = $this->checkForQuantities($product, $product->quantity); if (!$redirectMsg) { return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } } } // Check if a minimun purchase value is set if (($redirectMsg = $this->checkPurchaseValue()) != null) { return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } $validUserDataBT = self::validateUserData(); if (!isset($this->tosAccepted)) { $userFieldsModel = VmModel::getModel('Userfields'); $agreed = $userFieldsModel->getUserfield('agreed', 'name'); $this->tosAccepted = $agreed->default; } if (empty($this->tosAccepted)) { $userFieldsModel = VmModel::getModel('Userfields'); $agreed = $userFieldsModel->getUserfield('agreed', 'name'); if (empty($this->tosAccepted) and !empty($agreed->required) and $validUserDataBT !== -1) { $redirectMsg = null; // JText::_('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS'); $this->tosAccepted = false; vmInfo('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS'); return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } } if ($validUserDataBT !== true) { //Important, we can have as result -1,false and true. return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT', ''); } if ($this->STsameAsBT !== 0) { if ($this->_confirmDone) { $this->ST = $this->BT; } else { $this->ST = 0; } } else { if (($this->selected_shipto = JRequest::getVar('shipto', null)) !== null) { JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models'); $userModel = JModel::getInstance('user', 'VirtueMartModel'); $stData = $userModel->getUserAddressList(0, 'ST', $this->selected_shipto); $stData = get_object_vars($stData[0]); if ($this->validateUserData('ST', $stData) != -1 and $this->validateUserData('ST', $stData) > 0) { $this->ST = $stData; } } //Only when there is an ST data, test if all necessary fields are filled $validUserDataST = self::validateUserData('ST'); if ($validUserDataST !== true) { return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=ST', ''); } } if (VmConfig::get('oncheckout_only_registered', 0)) { $currentUser = JFactory::getUser(); if (empty($currentUser->id)) { $redirectMsg = JText::_('COM_VIRTUEMART_CART_ONLY_REGISTERED'); return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT', $redirectMsg); } } //vmdebug('ValidateCouponCode ValidateCouponCode ValidateCouponCode',$this->couponCode); // Test Coupon if (!empty($this->couponCode)) { //$prices = $this->getCartPrices(); if (!class_exists('CouponHelper')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php'; } if (!in_array($this->couponCode, $this->_triesValidateCoupon)) { $this->_triesValidateCoupon[] = $this->couponCode; } if (count($this->_triesValidateCoupon) < 8) { $redirectMsg = CouponHelper::ValidateCouponCode($this->couponCode, $this->pricesUnformatted['salesPrice']); } else { $redirectMsg = JText::_('COM_VIRTUEMART_CART_COUPON_TOO_MANY_TRIES'); } if (!empty($redirectMsg)) { $this->couponCode = ''; $this->getCartPrices(); $this->setCartIntoSession(); return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } } $redirectMsg = ''; //Test Shipment and show shipment plugin if (empty($this->virtuemart_shipmentmethod_id)) { return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=edit_shipment', $redirectMsg); } else { if ($this->virtuemart_shipmentmethod_id != JRequest::getInt('virtuemart_shipmentmethod_id', $this->virtuemart_shipmentmethod_id)) { $obj = new VirtueMartControllerCart(); $obj->setshipment(); return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmshipment'); //Add a hook here for other shipment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataShipment', array($this)); //vmdebug('plgVmOnCheckoutCheckDataShipment CART', $retValues); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesfull; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=edit_shipment', $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } } //Test Payment and show payment plugin if ($this->pricesUnformatted['salesPrice'] > 0.0) { if (empty($this->virtuemart_paymentmethod_id)) { return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=editpayment', $redirectMsg); } else { if ($this->virtuemart_paymentmethod_id != JRequest::getInt('virtuemart_paymentmethod_id', $this->virtuemart_paymentmethod_id)) { vmdebug('checkoutData $this->virtuemart_paymentmethod_id not equal request', $this->virtuemart_paymentmethod_id); $obj = new VirtueMartControllerCart(); $obj->setpayment(); return $this->redirecter('index.php?option=com_virtuemart&view=cart', $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); //Add a hook here for other payment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataPayment', array($this)); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesful; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) vmdebug('checkoutData payment plugin is missing data, trigger plgVmOnCheckoutCheckDataPayment', $this->virtuemart_paymentmethod_id); return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=editpayment', $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } } } //Show cart and checkout data overview $this->_inCheckOut = false; if ($this->_blockConfirm) { $this->_dataValidated = false; $this->setCartIntoSession(); return $this->redirecter('index.php?option=com_virtuemart&view=cart', ''); } else { $this->_dataValidated = true; $this->setCartIntoSession(); return true; } }
/** * Get coupon details and calculate the value * @author Oscar van Eijk * @param $_code Coupon code */ protected function couponHandler($_code) { JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($_code, &$this->_cartData, &$this->_cartPrices)); if (!empty($returnValues)) { foreach ($returnValues as $returnValue) { if ($returnValue !== null) { return $returnValue; } } } if (!class_exists('CouponHelper')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php'; } if (!($_data = CouponHelper::getCouponDetails($_code))) { return; // TODO give some error here } $_value_is_total = $_data->percent_or_total == 'total'; $this->_cartData['couponCode'] = $_code; $this->_cartData['couponDescr'] = $_value_is_total ? '' : round($_data->coupon_value) . '%'; $this->_cartPrices['salesPriceCoupon'] = $_value_is_total ? $_data->coupon_value * -1 : $this->_cartPrices['salesPrice'] * ($_data->coupon_value / 100) * -1; // TODO Calculate the tax $this->_cartPrices['couponTax'] = 0; $this->_cartPrices['couponValue'] = $this->_cartPrices['salesPriceCoupon'] - $this->_cartPrices['couponTax']; //$this->_cartPrices['billTotal'] -= $this->_cartPrices['salesPriceCoupon']; //if($this->_cartPrices['billTotal'] < 0){ // $this->_cartPrices['billTotal'] = 0.0; //} }
public function checkoutData($redirect = true) { if ($this->_redirected) { $this->_redirect = false; } else { $this->_redirect = $redirect; } $layoutName = $this->getLayoutUrlString(); $this->_inCheckOut = true; //This prevents that people checkout twice $this->setCartIntoSession(false, true); //Either we use here $this->_redirect, or we redirect always directly, atm we check the boolean _redirect if (count($this->cartProductsData) === 0 and $this->_redirect) { $this->_inCheckOut = false; return $this->redirecter('index.php?option=com_virtuemart', vmText::_('COM_VIRTUEMART_CART_NO_PRODUCT')); } // Check if a minimun purchase value is set if (($redirectMsg = $this->checkPurchaseValue()) != null) { $this->_inCheckOut = false; return $this->redirecter('index.php?option=com_virtuemart&view=cart' . $layoutName, $redirectMsg); } $validUserDataBT = self::validateUserData(); if ($validUserDataBT !== true) { //Important, we can have as result -1,false and true. return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT', ''); } $currentUser = JFactory::getUser(); if (!empty($this->STsameAsBT) or !$currentUser->guest and empty($this->selected_shipto)) { //Guest $this->ST = $this->BT; } else { if ($this->selected_shipto > 0) { $userModel = VmModel::getModel('user'); $stData = $userModel->getUserAddressList($currentUser->id, 'ST', $this->selected_shipto); if (isset($stData[0]) and is_object($stData[0])) { $stData = get_object_vars($stData[0]); if ($this->validateUserData('ST', $stData) > 0) { $this->ST = $stData; } } else { $this->selected_shipto = 0; $this->ST = $this->BT; } } //Only when there is an ST data, test if all necessary fields are filled $validUserDataST = self::validateUserData('ST'); if ($validUserDataST !== true) { return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=ST', ''); } } if (VmConfig::get('oncheckout_only_registered', 0)) { if (empty($currentUser->id)) { $redirectMsg = vmText::_('COM_VIRTUEMART_CART_ONLY_REGISTERED'); return $this->redirecter('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT', $redirectMsg); } } // Test Coupon if (!empty($this->couponCode)) { if (!class_exists('CouponHelper')) { require VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php'; } if (!in_array($this->couponCode, $this->_triesValidateCoupon)) { $this->_triesValidateCoupon[] = $this->couponCode; } if (count($this->_triesValidateCoupon) < 8) { $redirectMsg = CouponHelper::ValidateCouponCode($this->couponCode, $this->cartPrices['salesPrice']); } else { $redirectMsg = vmText::_('COM_VIRTUEMART_CART_COUPON_TOO_MANY_TRIES'); } if (!empty($redirectMsg)) { $this->couponCode = ''; $this->_inCheckOut = false; $this->setCartIntoSession(); return $this->redirecter('index.php?option=com_virtuemart&view=cart' . $layoutName, $redirectMsg); } } $redirectMsg = ''; //Test Shipment and show shipment plugin if (empty($this->virtuemart_shipmentmethod_id)) { return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=edit_shipment', $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmshipment'); //Add a hook here for other shipment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataShipment', array($this)); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesfull; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=edit_shipment', $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } //Test Payment and show payment plugin if ($this->cartPrices['salesPrice'] > 0.0) { if (empty($this->virtuemart_paymentmethod_id)) { return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=editpayment', $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); //Add a hook here for other payment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataPayment', array($this)); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesful; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) return $this->redirecter('index.php?option=com_virtuemart&view=cart&task=editpayment', $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } } $validUserDataCart = self::validateUserData('cartfields', $this->cartfields, $this->_redirect); if ($validUserDataCart !== true) { if ($this->_redirect) { $this->_inCheckOut = false; $redirectMsg = null; return $this->redirecter('index.php?option=com_virtuemart&view=cart' . $layoutName, $redirectMsg); } $this->_blockConfirm = true; } else { //Atm a bit dirty. We store this information in the BT order_userinfo, so we merge it here, it gives also //the advantage, that plugins can easily deal with it. //$this->BT = array_merge((array)$this->BT,(array)$this->cartfields); } //Show cart and checkout data overview if ($this->_redirected) { $this->_redirected = false; } else { $this->_inCheckOut = false; } if ($this->_blockConfirm) { $this->_dataValidated = false; $this->_inCheckOut = false; $this->setCartIntoSession(true); return $this->redirecter('index.php?option=com_virtuemart&view=cart' . $layoutName, ''); } else { $this->_dataValidated = true; $this->setCartIntoSession(true); if ($this->_redirect) { $app = JFactory::getApplication(); $app->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart' . $layoutName, FALSE), vmText::_('COM_VIRTUEMART_CART_CHECKOUT_DONE_CONFIRM_ORDER')); } else { return true; } } }
/** * 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(); }
/** * Get coupon details and calculate the value * @author Oscar van Eijk * @param $_code Coupon code */ protected function couponHandler($_code) { JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($_code, &$this->_cart->cartData, &$this->_cart->cartPrices)); if (!empty($returnValues)) { foreach ($returnValues as $returnValue) { if ($returnValue !== null) { return $returnValue; } } } if (!class_exists('CouponHelper')) { require VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php'; } if (!($_data = CouponHelper::getCouponDetails($_code))) { return; // TODO give some error here } vmdebug('my coupon data', $_data); $_value_is_total = $_data->percent_or_total == 'total'; $this->_cart->cartData['couponCode'] = $_code; if ($_value_is_total) { $this->_cart->cartData['couponDescr'] = $this->_currencyDisplay->priceDisplay($_data->coupon_value); } else { $this->_cart->cartData['couponDescr'] = rtrim(rtrim($_data->coupon_value, '0'), '.') . ' %'; } $this->_cart->cartPrices['salesPriceCoupon'] = $_value_is_total ? $_data->coupon_value * -1 : $this->_cart->cartPrices['salesPrice'] * ($_data->coupon_value / 100) * -1; $this->_cart->cartPrices['couponTax'] = 0; $this->_cart->cartPrices['couponValue'] = $this->_cart->cartPrices['salesPriceCoupon'] - $this->_cart->cartPrices['couponTax']; }
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; } }
/** * * ORIGINAL CODE FROM: \components\com_virtuemart\helpers\cart.php * * Validate the coupon code. If ok,. set it in the cart * @param string $coupon_code Coupon code as entered by the user * @author Oscar van Eijk * TODO Change the coupon total/used in DB ? * @access public * @return string On error the message text, otherwise an empty string */ function setCoupon(&$cart) { if (!class_exists('CouponHelper')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php'; } $coupon_code = JRequest::getVar('new_coupon', $cart->couponCode); JRequest::setVar('coupon_code', $coupon_code); // stAn, getCartPrices calls coupon process ! if (isset($cart->cartPrices)) { $prices = $cart->cartPrices; } else { $prices = $cart->getCartPrices(); } $msg = CouponHelper::ValidateCouponCode($coupon_code, $prices['salesPrice']); if (!empty($msg)) { $cart->couponCode = ''; $cart->setCartIntoSession(); JFactory::getApplication()->enqueueMessage($msg); return $msg; } $cart->couponCode = $coupon_code; $cart->setCartIntoSession(); // THIS IS NOT TRUE AS THE COUPON HAS NOT YET BEEN PROCESSED: return 'Virtuemarts cart says: '.OPCLang::_('COM_VIRTUEMART_CART_COUPON_VALID'); /* JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($_code,&$this->_cartData, &$this->_cartPrices)); if(!empty($returnValues)){ foreach ($returnValues as $returnValue) { if ($returnValue !== null ) { return $returnValue; } } } if (method_exists($calc, 'setCartPrices')) $vm2015 = true; else $vm2015 = false; if ($vm2015) $calc->setCartPrices(array()); */ // this will be loaded by OPC further // $calc->getCheckoutPrices( $ref->cart, false); }
function checkoutData($redirect = true) { $cart =& self::$current_cart; $this->_redirect = false; $this->_inCheckOut = true; include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; $cart->_inCheckOut = true; if (!isset($cart->tosAccepted)) { $cart->tosAccepted = 1; } $cart->tosAccepted = JRequest::getInt('tosAccepted', $cart->tosAccepted); if (!isset($cart->customer_comment)) { $cart->customer_comment = ''; } $cart->customer_comment = JRequest::getVar('customer_comment', $cart->customer_comment); if (empty($cart->customer_comment)) { $cart->customer_comment = JRequest::getVar('customer_note', $cart->customer_comment); } $op_disable_shipto = OPCloader::getShiptoEnabled($cart); if (empty($op_disable_shipto)) { $shipto = JRequest::getVar('shipto', null); if ($shipto != 'new') { if (($cart->selected_shipto = $shipto) !== null) { //JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models'); require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; $userModel = OPCmini::getModel('user'); //JModel::getInstance('user', 'VirtueMartModel'); $stData = $userModel->getUserAddressList(0, 'ST', $cart->selected_shipto); if (isset($stData[0])) { $this->validateUserData('ST', $stData[0], $cart); } } } } else { $cart->STsameAsBT = 1; $cart->ST = $cart->BT; } $cart->setCartIntoSession(); $mainframe = JFactory::getApplication(); if (isset($cart->cartProductsData)) { $count = count($cart->cartProductsData); } else { $count = count($cart->products); } if ($count == 0) { $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart', false), JText::_('COM_VIRTUEMART_CART_NO_PRODUCT')); } else { foreach ($cart->products as $product) { $redirectMsg = $this->checkForQuantities($product, $product->quantity); if (!$redirectMsg) { // $this->setCartIntoSession(); $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); } } } include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; //But we check the data again to be sure if (empty($cart->BT)) { $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false))); } else { $redirectMsg = $this->validateUserData('BT', null, $cart); if ($redirectMsg) { $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); } } if ($cart->STsameAsBT !== 0) { $cart->ST = $cart->BT; } else { //Only when there is an ST data, test if all necessary fields are filled if (!empty($cart->ST)) { $redirectMsg = $this->validateUserData('ST', null, $cart); if ($redirectMsg) { // $cart->setCartIntoSession(); $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); } } } // Test Coupon $shipment = $cart->virtuemart_shipmentmethod_id; $payment = $cart->virtuemart_paymentmethod_id; //2.0.144: $prices = $cartClass->getCartPrices(); $cart->virtuemart_shipmentmethod_id = $shipment; $cart->virtuemart_paymentmethod_id = $payment; //2.0.144 added if (!class_exists('calculationHelper')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php'; } $calc = calculationHelper::getInstance(); if (method_exists($calc, 'setCartPrices')) { $vm2015 = true; } else { $vm2015 = false; } if ($vm2015) { $calc->setCartPrices(array()); } // $cart->pricesUnformatted = $prices = $calc->getCheckoutPrices( $cart, false, 'opc'); $cart->pricesUnformatted = $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, 'opc'); //$calc->getCheckoutPrices( $cart, false, 'opc'); // Check if a minimun purchase value is set if (($msg = $this->checkPurchaseValue($prices)) != null) { $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $msg); } if (!empty($prices['billTotal'])) { // special case for zero value orders, do not charge payment fee: if ($prices['billTotal'] == $prices['paymentValue']) { $savedp = $cart->virtuemart_paymentmethod_id; $cart->virtuemart_paymentmethod_id = 0; if (method_exists($calc, 'getCheckoutPricesOPC')) { $prices = $calc->getCheckoutPricesOPC($cart, false); } else { $prices = OPCloader::getCheckoutPrices($cart, false, $vm2015, 'opc'); } $cart->virtuemart_paymentmethod_id = 0; } } //2.0.144:end if (!empty($cart->couponCode)) { if (!class_exists('CouponHelper')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php'; } $redirectMsg2 = CouponHelper::ValidateCouponCode($cart->couponCode, $prices['salesPrice']); /* stAn: OPC will not redirect the customer due to incorrect coupons here if (!empty($redirectMsg)) { $cart->couponCode = ''; // $this->setCartIntoSession(); $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart',$cart->useXHTML,$cart->useSSL), $redirectMsg); } */ } //Test Shipment and show shipment plugin $op_disable_shipping = OPCloader::getShippingEnabled($cart); if (empty($op_disable_shipping)) { if (empty($cart->virtuemart_shipmentmethod_id)) { $redirectMsg = JText::_('COM_VIRTUEMART_CART_NO_SHIPPINGRATE'); $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmshipment'); //Add a hook here for other shipment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataShipment', array($cart)); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesful; nothing else to do } elseif ($retVal === false) { // Missing data, ask for it (again) $redirectMsg = 'OPC2: ' . JText::_('COM_VIRTUEMART_CART_NO_SHIPPINGRATE'); $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } } //echo 'hier '; //Test Payment and show payment plugin $total = (double) $prices['billTotal']; if ($total > 0) { if (empty($cart->virtuemart_paymentmethod_id)) { $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); } else { if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); //Add a hook here for other payment methods, checking the data of the choosed plugin $dispatcher = JDispatcher::getInstance(); $retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataPayment', array($cart)); $session = JFactory::getSession(); $sessionKlarna = $session->get('Klarna', 0, 'vm'); foreach ($retValues as $retVal) { if ($retVal === true) { break; // Plugin completed succesful; nothing else to do } elseif ($retVal === false) { $msg = JFactory::getSession()->get('application.queue'); $msgq1 = JFactory::getApplication()->get('messageQueue', array()); $msgq2 = JFactory::getApplication()->get('_messageQueue', array()); $res = array_merge($msg, $msgg1, $msgg2); $msg = $res; if (!empty($msg) && is_array($msg)) { $redirectMsg = implode('<br />', $msg); } // Missing data, ask for it (again) $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), $redirectMsg); // NOTE: inactive plugins will always return null, so that value cannot be used for anything else! } } } } else { $cart->virtuemart_paymentmethod_id = 0; } if (VmConfig::get('agree_to_tos_onorder', 1)) { if (empty($cart->tosAccepted)) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; $userFieldsModel = OPCmini::getModel('Userfields'); $required = $userFieldsModel->getIfRequired('agreed'); if (!empty($required)) { $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout', false, VmConfig::get('useSSL', false)), JText::_('COM_VIRTUEMART_CART_PLEASE_ACCEPT_TOS')); } } } /* stAn: 2.0.231: registered does not mean logged in, therefore we are going to disable this option with opc, so normal registration would still work when activation is enabled if (empty($GLOBALS['is_dup'])) if(VmConfig::get('oncheckout_only_registered',0)) { $currentUser = JFactory::getUser(); if(empty($currentUser->id)){ $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart', false, VmConfig::get('useSSL', false)), JText::_('COM_VIRTUEMART_CART_ONLY_REGISTERED') ); } } */ //Show cart and checkout data overview $cart->_inCheckOut = false; $cart->_dataValidated = true; $cart->setCartIntoSession(); return true; }
/** * 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; }