Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
     }
 }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
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;
         }
     }
 }
Exemplo n.º 5
0
 /**
  *
  *  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);
 }
Exemplo n.º 6
0
 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;
 }