Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
0
 /**
  * To set a payment method
  *
  * @author Max Milbers
  * @author Oscar van Eijk
  * @author Valerie Isaksen
  */
 function setpayment(&$cart)
 {
     /* Get the payment id of the cart */
     //Now set the payment rate into the cart
     if ($cart) {
         if (isset($cart->pricesUnformatted['billTotal']) && empty($cart->pricesUnformatted['billTotal'])) {
             return true;
         }
         # seyi_code
         if (!class_exists('vmPSPlugin')) {
             require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
         }
         JPluginHelper::importPlugin('vmpayment');
         //Some Paymentmethods needs extra Information like
         $virtuemart_paymentmethod_id = JRequest::getInt('virtuemart_paymentmethod_id', '0');
         $cart->setPaymentMethod($virtuemart_paymentmethod_id);
         //Add a hook here for other payment methods, checking the data of the choosed plugin
         $_dispatcher = JDispatcher::getInstance();
         $msg = '';
         $_retValues = $_dispatcher->trigger('plgVmOnSelectCheckPaymentOPC', array($cart, &$msg));
         $dataValid = true;
         foreach ($_retValues as $_retVal) {
             if ($_retVal === true) {
                 // Plugin completed succesfull; nothing else to do
                 $cart->setCartIntoSession();
                 // opc mod:
                 return true;
                 break;
             } else {
                 if ($_retVal === false) {
                     $redirectMsg = $msg;
                     /*
                     		  
                     		   $redirectMsg = ''; 
                     		   if (empty($msg))
                     		   $msg = JFactory::getApplication()->getMessageQueue(); 
                     	if (!empty($msg) && (is_array($msg)))
                     	{
                     	  
                     	  foreach ($msg as $line)
                     	  {
                     	  if (is_array($line))
                     	  {
                     	   if (!empty($line['message']))
                     	    $redirectMsg .= $line['message'].'<br />'; 
                     	   }
                     	   else
                     	   {
                     	    $redirectMsg .= $line.'<br />'; 
                     	   }
                     	  }
                     	}
                     	else $redirectMsg = $msg; 
                     */
                     $mainframe = JFactory::getApplication();
                     $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=editpayment', false, $this->useSSL), $redirectMsg);
                     break;
                 }
             }
         }
         //			$cart->setDataValidation();	//Not needed already done in the getCart function
         if ($cart->getInCheckOut()) {
             return true;
             $mainframe = JFactory::getApplication();
             $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=checkout'), $msg);
         }
     }
     return true;
     parent::display();
 }