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; }
function getBTfields(&$obj, $unlg = false, $no_wrapper = false) { include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; $default_shipping_country = OPCloader::getDefaultCountry($cart); // $default_shipping_country $islogged = OPCloader::logged($obj->cart); if ($islogged && empty($unlg)) { return $this->getUserInfoBT($obj); } else { if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } if (!empty($obj->cart)) { $cart =& $obj->cart; } else { $cart = VirtueMartCart::getCart(); } $type = 'BT'; $this->address_type = 'BT'; // for unlogged $virtuemart_userinfo_id = 0; $this->virtuemart_userinfo_id = 0; $new = 1; if (!empty($unlg)) { $new = false; } $fieldtype = $type . 'address'; if (empty($cart->BT)) { $cart->BT = array(); } $user = JFactory::getUser(); $uid = $user->get('id'); // PPL Express address: $moveBT = false; $count = 0; if (!empty($cart->savedST)) { if (!$islogged) { foreach ($cart->savedST as $key => $val) { if ($key == 'virtuemart_country_id') { continue; } if ($key == 'virtuemart_state_id') { continue; } if (substr($key, 0, 7) === 'shipto_') { continue; } if (empty($cart->BT[$key]) && !empty($val)) { $count++; } else { if (!empty($cart->BT[$key]) && $val != $cart->BT[$key]) { $count--; } } } if ($count > 0) { if ($cart->savedST['virtuemart_country_id'] != $cart->BT['virtuemart_country_id']) { $cart->BT['virtuemart_state_id'] = 0; } foreach ($cart->savedST as $key => $val) { if (!empty($val)) { $cart->BT[$key] = $val; } } } } } if (empty($cart->BT['virtuemart_country_id'])) { if (!empty($default_shipping_country) && is_numeric($default_shipping_country)) { $cart->BT['virtuemart_country_id'] = $default_shipping_country; } else { // let's set a default country $vendor = $this->getVendorInfo($cart); $cart->BT['virtuemart_country_id'] = $vendor['virtuemart_country_id']; } } /* if (!empty($cart->BT) && (count($cart->BT)>2)) $new = false; if (empty($cart->BT)) $new = true; */ $type = 'BT'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php'; OPCUserFields::populateCart($cart, $type, true); OPCloader::setRegType(); $op_disable_shipto = OPCloader::getShiptoEnabled($cart); if (!class_exists('VirtuemartModelUserfields')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'userfields.php'; } $corefields = VirtueMartModelUserfields::getCoreFields(); $userFields = $cart->{$fieldtype}; if (isset($cart->BTaddress) && isset($cart->BTaddress['fields']) && isset($cart->BTaddress['fields']['virtuemart_country_id']) && !empty($cart->BTaddress['fields']['virtuemart_country_id']['value'])) { if (is_numeric($cart->BTaddress['fields']['virtuemart_country_id']['value'])) { $cart->BT['virtuemart_country_id'] = $cart->BTaddress['fields']['virtuemart_country_id']['value']; } } // unset corefields $onlyf = array(); if (empty($bt_fields_from)) { $q = 'select name from #__virtuemart_userfields where published=1 and registration = 1'; $db = JFactory::getDBO(); $db->setQuery($q); $onlyf2 = $db->loadAssocList(); foreach ($onlyf2 as $k => $v) { $onlyf[] = $v['name']; } } if (!empty($userFields['fields'])) { foreach ($userFields['fields'] as $key => $uf) { // disable fields that are not marked for registration if (!empty($onlyf)) { if (!in_array($uf['name'], $onlyf)) { unset($userFields['fields'][$key]); continue; } } $userFields['fields'][$key]['formcode'] = str_replace('vm-chzn-select', '', $userFields['fields'][$key]['formcode']); OPCloader::$fields_names[$key] = $userFields['fields'][$key]['title']; if ($userFields['fields'][$key]['type'] == 'delimiter') { unset($userFields['fields'][$key]); continue; } foreach ($corefields as $f) { if ($f == $uf['name']) { // will move the email to bt section if (empty($no_login_in_template) || $unlg) { if ($f == 'email') { if (empty($opc_email_in_bt)) { if (!$this->isNoLogin()) { unset($userFields['fields'][$key]); } } } else { unset($userFields['fields'][$key]); } continue; } } } if (empty($custom_rendering_fields)) { $custom_rendering_fields = array(); } if (!empty($custom_rendering_fields)) { if (in_array($uf['name'], $custom_rendering_fields)) { unset($userFields['fields'][$key]); continue; } } if ($key == 'name') { if (!empty($op_no_display_name)) { if (!empty($userFields['fields']['name'])) { unset($userFields['fields']['name']); } } } } } // end of for each require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php'; $skipreorder = array('email'); OPCUserFields::getUserFields($userFields, $this, $cart, array(), array(), $skipreorder); // logic reversed, if email is not in BT, remove it if (!((!empty($opc_email_in_bt) || $this->isNoLogin()) && !empty($double_email))) { unset($userFields['fields']['email2']); // email is in BT, let's check for double mail } $skipreorder = array(); if (!empty($opc_email_in_bt) || $this->isNoLogin()) { $skipreorder[] = 'email'; if (!empty($opc_check_email)) { if (!OPCloader::logged($cart) && empty($uid)) { if (!empty($userFields['fields']['email'])) { $un = $userFields['fields']['email']['formcode']; if (stripos($un, 'id="email_already_exists"') === false) { //if (!$double_email) $un = str_replace('id=', ' onblur="javascript: Onepage.email_check(this);" id=', $un); $un .= '<span class="email_already_exist" style="display: none; position: relative; color: red; font-size: 10px; background: none; border: none; padding: 0; margin: 0;" id="email_already_exists">'; $un .= OPCLang::sprintf('COM_ONEPAGE_EMAIL_ALREADY_EXISTS', OPCLang::_('COM_VIRTUEMART_USER_FORM_EMAIL')); $un .= '</span>'; $userFields['fields']['email']['formcode'] = $un; } } } } } require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'userfields.php'; OPCUserFields::reorderFields($userFields, $skipreorder); require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; $this->_model = OPCmini::getModel('user'); //new VirtuemartModelUser(); $layout = 'default'; $hidden = array(); $hidden_html = ''; if (!empty($userFields['fields'])) { foreach ($userFields['fields'] as $key => $val) { if (!empty($val['hidden'])) { $hidden[] = $val; $hidden_html .= $val['formcode']; unset($userFields['fields'][$key]); } } } $vars = array('rowFields' => $userFields, 'cart' => $obj, 'is_logged' => $unlg); $html = $this->fetch($this, 'list_user_fields.tpl', $vars); $hidden_html = str_replace('"required"', '""', $hidden_html); $html .= $hidden_html; $html = $this->addListeners($html); if (empty($custom_rendering_fields)) { $custom_rendering_fields = array(); } if (in_array('virtuemart_country_id', $custom_rendering_fields)) { $html .= '<input type="hidden" id="virtuemart_country_id" name="virtuemart_country_id" value="' . $default_shipping_country . '" />'; } if (in_array('virtuemart_state_id', $custom_rendering_fields)) { $html .= '<input type="hidden" id="virtuemart_state_id" name="virtuemart_state_id" value="0" />'; } return $html; } }
function checkEnabledShipto() { $op_disable_shipto = OPCloader::getShiptoEnabled($this->cart); }