/**
  * @static
  * @param $method
  * @param $country
  * @return array|null
  */
 static function countryData($method, $country)
 {
     $countriesData = self::countriesData();
     $lower_country = strtolower($country);
     if (array_key_exists(strtoupper($country), $countriesData)) {
         $cData = $countriesData[strtoupper($country)];
         $eid = 'klarna_merchantid_' . $lower_country;
         $secret = 'klarna_sharedsecret_' . $lower_country;
         $invoice_fee = 'klarna_invoicefee_' . $lower_country;
         $min_amount = 'klarna_min_amount_part_' . $lower_country;
         $payment_activated = 'klarna_payments_' . $lower_country;
         $active = 'klarna_active_' . $lower_country;
         $cData['eid'] = $method->{$eid};
         $cData['secret'] = $method->{$secret};
         $cData['invoice_fee'] = (double) $method->{$invoice_fee};
         $cData['country_code_3'] = $country;
         $cData['virtuemart_currency_id'] = ShopFunctions::getCurrencyIDByName($cData['currency_code']);
         $cData['virtuemart_country_id'] = ShopFunctions::getCountryIDByName($country);
         $cData['mode'] = KlarnaHandler::getKlarnaMode($method, $country);
         $cData['min_amount'] = $method->{$min_amount};
         $cData['active'] = $method->{$active};
         if (empty($method->{$payment_activated})) {
             $method->{$payment_activated} = array('invoice', 'part');
         }
         $cData['payments_activated'] = $method->{$payment_activated};
         if (!class_exists('VirtueMartModelVendor')) {
             require VMPATH_ADMIN . DS . 'models' . DS . 'vendor.php';
         }
         $vendor_id = 1;
         $cData['vendor_currency'] = VirtueMartModelVendor::getVendorCurrency($vendor_id)->vendor_currency;
         return $cData;
     } else {
         return NULL;
     }
 }
 static function countryData($method, $country)
 {
     $countriesData = self::countriesData();
     $lower_country = strtolower($country);
     if (array_key_exists(strtoupper($country), $countriesData)) {
         $cData = $countriesData[strtoupper($country)];
         $eid = 'klarna_merchantid_' . $lower_country;
         $secret = 'klarna_sharedsecret_' . $lower_country;
         $invoice_fee = 'klarna_invoicefee_' . $lower_country;
         $min_amount = 'klarna_min_amount_part_' . $lower_country;
         $active = 'klarna_active_' . $lower_country;
         $cData['eid'] = $method->{$eid};
         $cData['secret'] = $method->{$secret};
         $cData['invoice_fee'] = (double) $method->{$invoice_fee};
         $cData['country_code_3'] = $country;
         $cData['virtuemart_currency_id'] = ShopFunctions::getCurrencyIDByName($cData['currency_code']);
         $cData['virtuemart_country_id'] = ShopFunctions::getCountryIDByName($country);
         $cData['mode'] = $method->klarna_mode;
         $cData['min_amount'] = $method->{$min_amount};
         $cData['active'] = $method->{$active};
         return $cData;
     } else {
         return NULL;
     }
 }
Exemple #3
0
 /**
  * This event is fired after the payment method has been selected. It can be used to store
  * additional payment info in the cart.
  * @author Valérie isaksen
  *
  * @param VirtueMartCart $cart: the actual cart
  * @return null if the payment was not selected, true if the data is valid, error message if the data is not vlaid
  *
  */
 public function plgVmOnSelectCheckPayment(VirtueMartCart $cart)
 {
     if (!$this->selectedThisByMethodId($cart->virtuemart_paymentmethod_id)) {
         return NULL;
         // Another method was selected, do nothing
     }
     if (!($method = $this->getVmPluginMethod($cart->virtuemart_paymentmethod_id))) {
         return NULL;
         // Another method was selected, do nothing
     }
     if (!class_exists('KlarnaAddr')) {
         require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'api' . DS . 'klarnaaddr.php';
     }
     $session = JFactory::getSession();
     $sessionKlarna = new stdClass();
     //$post = JRequest::get('post');
     $klarnaData_paymentmethod = JRequest::getVar('klarna_paymentmethod', '');
     if ($klarnaData_paymentmethod == 'klarna_invoice') {
         $klarnaData_payment = "klarna_invoice";
         $sessionKlarna->klarna_option = 'invoice';
     } elseif ($klarnaData_paymentmethod == 'klarna_partPayment') {
         $klarnaData_payment = "klarna_partpay";
         $sessionKlarna->klarna_option = 'part';
     } elseif ($klarnaData_paymentmethod == 'klarna_speccamp') {
         $klarnaData_payment = "klarna_speccamp";
         $sessionKlarna->klarna_option = 'spec';
     } else {
         return NULL;
     }
     // Store payment_method_id so we can activate the
     // right payment in case something goes wrong.
     $sessionKlarna->virtuemart_payment_method_id = $cart->virtuemart_paymentmethod_id;
     $sessionKlarna->klarna_paymentmethod = $klarnaData_paymentmethod;
     $this->_getCartAddressCountryCode($cart, $country3, $countryId, 'country_3_code');
     // $country2=  strtolower($country2);
     if (empty($country3)) {
         $country3 = "SWE";
         $countryId = ShopFunctions::getCountryIDByName($country3);
     }
     $cData = KlarnaHandler::countryData($method, strtoupper($country3));
     $klarnaData = KlarnaHandler::getDataFromEditPayment();
     $klarnaData['country'] = $cData['country_code'];
     //$country = $cData['country_code']; //KlarnaHandler::convertCountry($method, $country2);
     //$lang = $cData['language_code']; //KlarnaHandler::getLanguageForCountry($method, $country);
     // Get the correct data
     //Removes spaces, tabs, and other delimiters.
     // If it is a swedish customer we use the information from getAddress
     if (strtolower($cData['country_code']) == "se") {
         if (empty($klarnaData['socialNumber'])) {
             VmInfo('VMPAYMENT_KLARNA_MUST_VALID_PNO');
             return false;
         }
         $swedish_addresses = klarnaHandler::getAddresses($klarnaData['socialNumber'], $cData, $method);
         if (empty($swedish_addresses)) {
             VmInfo('VMPAYMENT_KLARNA_NO_GETADDRESS');
             return false;
         }
         //This example only works for GA_GIVEN.
         foreach ($swedish_addresses as $address) {
             if ($address->isCompany) {
                 $klarnaData['company_name'] = $address->getCompanyName();
             } else {
                 $klarnaData['first_name'] = $address->getFirstName();
                 $klarnaData['last_name'] = $address->getLastName();
             }
             $klarnaData['street'] = $address->getStreet();
             $klarnaData['zip'] = $address->getZipCode();
             $klarnaData['city'] = $address->getCity();
             $klarnaData['country'] = $address->getCountryCode();
             $countryId = $klarnaData['virtuemart_country_id'] = shopFunctions::getCountryIDByName($klarnaData['country']);
         }
         foreach ($klarnaData as $key => $value) {
             $klarnaData[$key] = mb_convert_encoding($klarnaData[$key], 'UTF-8', 'ISO-8859-1');
         }
     } elseif (!KlarnaHandler::checkDataFromEditPayment($klarnaData)) {
         //VmInfo('VMPAYMENT_KLARNA_MISSING_DATA');
         //return false;
     }
     $st = $this->getCartAddress($cart, $address_type, true);
     if ($address_type == 'BT') {
         $prefix = '';
     } else {
         $prefix = 'shipto_';
     }
     // Update the Shipping Address to what is specified in the register.
     $update_data = array($prefix . 'address_type_name' => 'Klarna', $prefix . 'company' => $klarnaData['company_name'], $prefix . 'first_name' => $klarnaData['first_name'], $prefix . 'middle_name' => $st['middle_name'], $prefix . 'last_name' => $klarnaData['last_name'], $prefix . 'address_1' => $klarnaData['street'], $prefix . 'address_2' => $klarnaData['house_ext'], $prefix . 'house_no' => $klarnaData['house_no'], $prefix . 'zip' => html_entity_decode($klarnaData['zip']), $prefix . 'city' => $klarnaData['city'], $prefix . 'virtuemart_country_id' => $countryId, $prefix . 'state' => '', $prefix . 'phone_1' => $klarnaData['phone'], $prefix . 'phone_2' => $st['phone_2'], $prefix . 'fax' => $st['fax'], $prefix . 'birthday' => empty($klarnaData['birthday']) ? $st['birthday'] : $klarnaData['birthday'], $prefix . 'social_number' => empty($klarnaData['pno']) ? $klarnaData['socialNumber'] : $klarnaData['pno'], 'address_type' => $address_type);
     if ($address_type == 'BT') {
         $update_data['email'] = $klarnaData['email'];
     }
     // save address in cart if different
     // 	if (false) {
     $cart->saveAddressInCart($update_data, $update_data['address_type'], true);
     //vmdebug('plgVmOnSelectCheckPayment $cart',$cart);
     //vmInfo(JText::_('VMPAYMENT_KLARNA_ADDRESS_UPDATED_NOTICE'));
     // 	}
     //}
     // Store the Klarna data in a session variable so
     // we can retrevie it later when we need it
     //$klarnaData['pclass'] = ($klarnaData_paymentmethod == 'klarna_invoice' ? -1 : intval(JRequest::getVar($kIndex . "paymentPlan")));
     $klarnaData['pclass'] = $klarnaData_paymentmethod == 'klarna_invoice' ? -1 : intval(JRequest::getVar("klarna_paymentPlan"));
     $sessionKlarna->KLARNA_DATA = $klarnaData;
     // 2 letters small
     //$settings = KlarnaHandler::getCountryData($method, $cart_country2);
     try {
         $address = new KlarnaAddr($klarnaData['email'], $klarnaData['phone'], "", $klarnaData['first_name'], $klarnaData['last_name'], '', $klarnaData['street'], $klarnaData['zip'], $klarnaData['city'], $klarnaData['country'], $klarnaData['house_no'], $klarnaData['house_ext']);
     } catch (Exception $e) {
         VmInfo($e->getMessage());
         return false;
         //KlarnaHandler::redirectPaymentMethod('message', $e->getMessage());
     }
     if (isset($errors) && count($errors) > 0) {
         $msg = JText::_('VMPAYMENT_KLARNA_ERROR_TITLE_1');
         foreach ($errors as $error) {
             $msg .= "<li> -" . $error . "</li>";
         }
         $msg .= JText::_('VMPAYMENT_KLARNA_ERROR_TITLE_2');
         unset($errors);
         VmError($msg);
         return false;
         //KlarnaHandler::redirectPaymentMethod('error', $msg);
     }
     $session->set('Klarna', serialize($sessionKlarna), 'vm');
     return true;
 }
Exemple #4
0
 /**
  * Check if the payment conditions are fulfilled for this payment method
  *
  * @author: Valerie Isaksen
  *
  * @param $cart_prices : cart prices
  * @param $payment
  * @return true: if the conditions are fulfilled, false otherwise
  *
  */
 protected function checkConditions($cart, $method, $cart_prices)
 {
     $this->convert_condition_amount($method);
     $amount = $this->getCartAmount($cart_prices);
     $address = $cart->ST == 0 ? $cart->BT : $cart->ST;
     $amount_cond = ($amount >= $method->min_amount and $amount <= $method->max_amount or $method->min_amount <= $amount and $method->max_amount == 0);
     $countries[0] = ShopFunctions::getCountryIDByName('NL');
     // probably did not gave his BT:ST address
     if (!is_array($address)) {
         $address = array();
         $address['virtuemart_country_id'] = 0;
     }
     if (!isset($address['virtuemart_country_id'])) {
         $address['virtuemart_country_id'] = 0;
     }
     if (in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) {
         if ($amount_cond) {
             return TRUE;
         }
     }
     return FALSE;
 }
 function storeAddresses()
 {
     $this->cart = VirtueMartCart::getCart();
     $addressST = $addressBT = array();
     if ($this->response['SHIPTONAME'] == $this->response['FIRSTNAME'] . ' ' . $this->response['LASTNAME']) {
         $firstName = $this->response['FIRSTNAME'];
         $lastName = $this->response['LASTNAME'];
     } else {
         $shipToName = explode(' ', $this->response['SHIPTONAME']);
         $firstName = $shipToName[0];
         $lastName = '';
         if (count($shipToName) > 1) {
             $lastName = str_replace($firstName . ' ', '', $this->response['SHIPTONAME']);
         }
     }
     $usersModel = VmModel::getModel('user');
     $validateUserData = $usersModel->validateUserData($this->cart->BT, 'BT');
     if ($validateUserData !== true) {
         $addressBT['email'] = $this->response['EMAIL'];
         $addressBT['first_name'] = $firstName;
         $addressBT['last_name'] = $lastName;
         $addressBT['address_1'] = $this->response['SHIPTOSTREET'];
         $addressBT['city'] = $this->response['SHIPTOCITY'];
         $addressBT['zip'] = $this->response['SHIPTOZIP'];
         $addressBT['virtuemart_state_id'] = ShopFunctions::getStateIDByName($this->response['SHIPTOSTATE']);
         $addressBT['virtuemart_country_id'] = ShopFunctions::getCountryIDByName($this->response['SHIPTOCOUNTRYCODE']);
         $this->cart->saveAddressInCart($addressBT, 'BT', true);
     }
     $addressST['shipto_address_type_name'] = 'PayPal Account';
     $addressST['shipto_first_name'] = $firstName;
     $addressST['shipto_last_name'] = $lastName;
     $addressST['shipto_address_1'] = $this->response['SHIPTOSTREET'];
     $addressST['shipto_city'] = $this->response['SHIPTOCITY'];
     $addressST['shipto_zip'] = $this->response['SHIPTOZIP'];
     $addressST['shipto_virtuemart_state_id'] = ShopFunctions::getStateIDByName($this->response['SHIPTOSTATE']);
     $addressST['shipto_virtuemart_country_id'] = ShopFunctions::getCountryIDByName($this->response['SHIPTOCOUNTRYCODE']);
     $this->cart->STsameAsBT = 0;
     $this->cart->setCartIntoSession();
     $this->cart->saveAddressInCart($addressST, 'ST', true);
 }
Exemple #6
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     $this->prepareContinueLink();
     if (VmConfig::get('use_as_catalog', 0)) {
         vmInfo('This is a catalogue, you cannot access the cart');
         $app->redirect($this->continue_link);
     }
     $pathway = $app->getPathway();
     $document = JFactory::getDocument();
     $document->setMetaData('robots', 'NOINDEX, NOFOLLOW, NOARCHIVE, NOSNIPPET');
     $this->addTemplatePath(dirname(__FILE__) . DS . 'tmpl' . DS);
     $path = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/plg_content_onepage_generic/';
     $this->addTemplatePath($path);
     $layoutName = $this->getLayout();
     if (!$layoutName) {
         $layoutName = vRequest::getCmd('layout', 'default');
     }
     $this->assignRef('layoutName', $layoutName);
     $format = vRequest::getCmd('format');
     if (!class_exists('VirtueMartCart')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
     }
     $cart = VirtueMartCart::getCart();
     $cart->prepareVendor();
     $this->cart = $cart;
     //Why is this here, when we have view.raw.php
     if ($format == 'raw') {
         vRequest::setVar('layout', 'mini_cart');
         $this->setLayout('mini_cart');
         $this->prepareContinueLink();
     }
     if ($layoutName == 'select_shipment') {
         $cart->prepareCartData();
         $this->lSelectShipment();
         $pathway->addItem(vmText::_('COM_VIRTUEMART_CART_OVERVIEW'), JRoute::_('index.php?option=com_virtuemart&view=cart', FALSE));
         $pathway->addItem(vmText::_('COM_VIRTUEMART_CART_SELECTSHIPMENT'));
         $document->setTitle(vmText::_('COM_VIRTUEMART_CART_SELECTSHIPMENT'));
     } else {
         if ($layoutName == 'select_payment') {
             $cart->prepareCartData();
             $this->lSelectPayment();
             $pathway->addItem(vmText::_('COM_VIRTUEMART_CART_OVERVIEW'), JRoute::_('index.php?option=com_virtuemart&view=cart', FALSE));
             $pathway->addItem(vmText::_('COM_VIRTUEMART_CART_SELECTPAYMENT'));
             $document->setTitle(vmText::_('COM_VIRTUEMART_CART_SELECTPAYMENT'));
         } else {
             if ($layoutName == 'order_done') {
                 VmConfig::loadJLang('com_virtuemart_shoppers', true);
                 $this->lOrderDone();
                 $pathway->addItem(vmText::_('COM_VIRTUEMART_CART_THANKYOU'));
                 $document->setTitle(vmText::_('COM_VIRTUEMART_CART_THANKYOU'));
             } else {
                 VmConfig::loadJLang('com_virtuemart_shoppers', true);
                 $this->renderCompleteAddressList();
                 if (!class_exists('VirtueMartModelUserfields')) {
                     require VMPATH_ADMIN . DS . 'models' . DS . 'userfields.php';
                 }
                 $userFieldsModel = VmModel::getModel('userfields');
                 $userFieldsCart = $userFieldsModel->getUserFields('cart', array('captcha' => true, 'delimiters' => true), array('delimiter_userinfo', 'user_is_vendor', 'username', 'password', 'password2', 'agreed', 'address_type'));
                 $this->userFieldsCart = $userFieldsModel->getUserFieldsFilled($userFieldsCart, $cart->cartfields);
                 if (!class_exists('CurrencyDisplay')) {
                     require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
                 }
                 $this->currencyDisplay = CurrencyDisplay::getInstance($cart->pricesCurrency);
                 $currency = $this->currencyDisplay;
                 $customfieldsModel = VmModel::getModel('Customfields');
                 $this->assignRef('customfieldsModel', $customfieldsModel);
                 $this->lSelectCoupon();
                 $totalInPaymentCurrency = $this->getTotalInPaymentCurrency();
                 $checkoutAdvertise = $this->getCheckoutAdvertise();
                 if ($cart->getDataValidated()) {
                     if ($cart->_inConfirm) {
                         $pathway->addItem(vmText::_('COM_VIRTUEMART_CANCEL_CONFIRM_MNU'));
                         $document->setTitle(vmText::_('COM_VIRTUEMART_CANCEL_CONFIRM_MNU'));
                         $text = vmText::_('COM_VIRTUEMART_CANCEL_CONFIRM');
                         $this->checkout_task = 'cancel';
                     } else {
                         $pathway->addItem(vmText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU'));
                         $document->setTitle(vmText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU'));
                         $text = vmText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU');
                         $this->checkout_task = 'confirm';
                     }
                 } else {
                     $pathway->addItem(vmText::_('COM_VIRTUEMART_CART_OVERVIEW'));
                     $document->setTitle(vmText::_('COM_VIRTUEMART_CART_OVERVIEW'));
                     $text = vmText::_('COM_VIRTUEMART_CHECKOUT_TITLE');
                     $this->checkout_task = 'checkout';
                 }
                 $this->checkout_link_html = '<button type="submit"  id="checkoutFormSubmit" name="' . $this->checkout_task . '" value="1" class="vm-button-correct" ><span>' . $text . '</span> </button>';
                 if (!class_exists('vmPSPlugin')) {
                     require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
                 }
                 JPluginHelper::importPlugin('vmshipment');
                 JPluginHelper::importPlugin('vmpayment');
                 vmdebug('cart view oncheckout_opc ');
                 $this->lSelectShipment();
                 $this->lSelectPayment();
                 if (VmConfig::get('oncheckout_opc', 1)) {
                 } else {
                     $this->checkPaymentMethodsConfigured();
                     $this->checkShipmentMethodsConfigured();
                 }
                 if ($cart->virtuemart_shipmentmethod_id) {
                     $shippingText = vmText::_('COM_VIRTUEMART_CART_CHANGE_SHIPPING');
                 } else {
                     $shippingText = vmText::_('COM_VIRTUEMART_CART_EDIT_SHIPPING');
                 }
                 $this->assignRef('select_shipment_text', $shippingText);
                 if ($cart->virtuemart_paymentmethod_id) {
                     $paymentText = vmText::_('COM_VIRTUEMART_CART_CHANGE_PAYMENT');
                 } else {
                     $paymentText = vmText::_('COM_VIRTUEMART_CART_EDIT_PAYMENT');
                 }
                 $this->assignRef('select_payment_text', $paymentText);
                 $cart->prepareAddressFieldsInCart();
                 $layoutName = $cart->layout;
                 //set order language
                 $lang = JFactory::getLanguage();
                 $order_language = $lang->getTag();
                 $this->assignRef('order_language', $order_language);
             }
         }
     }
     $this->useSSL = VmConfig::get('useSSL', 0);
     $this->useXHTML = false;
     $this->assignRef('totalInPaymentCurrency', $totalInPaymentCurrency);
     $this->assignRef('checkoutAdvertise', $checkoutAdvertise);
     if (!class_exists('VmTemplate')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'vmtemplate.php';
     }
     VmTemplate::setVmTemplate($this, 0, 0, $layoutName);
     //We never want that the cart is indexed
     $document->setMetaData('robots', 'NOINDEX, NOFOLLOW, NOARCHIVE, NOSNIPPET');
     if ($cart->_inConfirm) {
         vmInfo('COM_VIRTUEMART_IN_CONFIRM');
     }
     if ($cart->layoutPath) {
         $this->addTemplatePath($cart->layoutPath);
     }
     if (isset($_POST["tos"])) {
         $_POST["agreed"] = $_POST["tos"];
     } else {
         $_POST["agreed"] = 0;
     }
     $current = JFactory::getUser();
     $this->allowChangeShopper = false;
     $this->adminID = false;
     if (VmConfig::get('oncheckout_change_shopper')) {
         if ($current->authorise('core.admin', 'com_virtuemart') or $current->authorise('vm.user', 'com_virtuemart')) {
             $this->allowChangeShopper = true;
         } else {
             $this->adminID = JFactory::getSession()->get('vmAdminID', false);
             if ($this->adminID) {
                 if (!class_exists('vmCrypt')) {
                     require VMPATH_ADMIN . DS . 'helpers' . DS . 'vmcrypt.php';
                 }
                 $this->adminID = vmCrypt::decrypt($this->adminID);
                 $adminIdUser = JFactory::getUser($this->adminID);
                 if ($adminIdUser->authorise('core.admin', 'com_virtuemart') or $adminIdUser->authorise('vm.user', 'com_virtuemart')) {
                     $this->allowChangeShopper = true;
                 }
             }
         }
     }
     if ($this->allowChangeShopper) {
         $this->userList = $this->getUserList();
     }
     $task = $input->getString("vmtask");
     if (file_exists(dirname(__FILE__) . "/" . $task . ".php")) {
         require_once dirname(__FILE__) . "/" . $task . ".php";
     }
     if ($task == "completecheckout") {
         require_once dirname(__FILE__) . "/updatecartaddress.php";
         $checkout = $cart->checkoutData(false);
         $app = JFactory::getApplication();
         $messageQueue = $app->getMessageQueue();
         $return_error = "";
         if (count($messageQueue) > 0) {
             foreach ($messageQueue as $message) {
                 $return_error .= $message['message'];
             }
         }
         $returnarray = array();
         if ($checkout) {
             $returnarray["success"] = 1;
         } else {
             $returnarray["success"] = 0;
         }
         $returnarray['message'] = $return_error;
         echo json_encode($returnarray);
         exit;
     }
     if ($task == "ajaxshipment") {
         $this->lSelectShipment();
         echo json_encode($this->shipments_shipment_rates);
         exit;
     }
     if ($task == "ajaxpayment") {
         $this->lSelectPayment();
         echo json_encode($this->paymentplugins_payments);
         exit;
     }
     if ($task == "setsession") {
         $payid = JRequest::getVar("payid", 0);
         if ($payid > 0) {
             $cart->setPaymentMethod(false, false, $payid);
             $cart->setCartIntoSession();
         }
         echo "success";
         exit;
     }
     if ($task == "klarnaupdate") {
         $post = JRequest::get("post");
         $address = array();
         $address['shipto_address_type_name'] = 'ST';
         if (!empty($post['given_name'])) {
             $address['shipto_first_name'] = $post['given_name'];
         }
         if (!empty($post['family_name'])) {
             $address['shipto_last_name'] = $post['family_name'];
         }
         if (!empty($post['street_address'])) {
             $address['shipto_address_1'] = $post['street_address'];
         }
         if (!empty($post['street_address2'])) {
             $address['shipto_address_2'] = $post['street_address2'];
         }
         if (!empty($post['postal_code'])) {
             $address['shipto_zip'] = $post['postal_code'];
         }
         if (!empty($post['city'])) {
             $address['shipto_city'] = $post['city'];
         }
         if (!empty($post['country'])) {
             $address['shipto_virtuemart_country_id'] = ShopFunctions::getCountryIDByName($post['country']);
         } else {
             if (!empty($cart->BT['virtuemart_country_id'])) {
                 $address['shipto_virtuemart_country_id'] = $cart->BT['virtuemart_country_id'];
             }
         }
         if (!empty($post['region'])) {
             $address['shipto_virtuemart_state_id'] = ShopFunctions::getStateIDByName($post['region']);
         }
         if (!empty($post['phone'])) {
             $address['shipto_phone_1'] = $post['phone'];
         }
         $address['tos'] = 1;
         $cart->saveAddressInCart($address, 'ST', true, 'shipto_');
         $cart->setCartIntoSession(false, true);
         $return = array();
         $return['response'] = "success";
         echo json_encode($return);
         exit;
     }
     $cart->setCartIntoSession();
     parent::display($tpl);
 }