function saveShippingMethod() { global $osC_Language, $osC_ShoppingCart, $osC_Shipping, $toC_Json, $osC_Customer, $osC_Payment, $osC_Currencies; $errors = array(); // load all enabled shipping modules if (class_exists('osC_Shipping') === false) { require_once 'includes/classes/shipping.php'; } $osC_Shipping = new osC_Shipping(); // if no shipping method has been selected, automatically select the cheapest method. // if ($osC_ShoppingCart->hasShippingMethod() === false) { // $osC_ShoppingCart->setShippingMethod($osC_Shipping->getCheapestQuote()); // } if (!empty($_POST['shipping_comments'])) { $_SESSION['comments'] = osc_sanitize_string($_POST['shipping_comments']); } if ($osC_Shipping->hasQuotes()) { if (isset($_REQUEST['shipping_mod_sel']) && strpos($_REQUEST['shipping_mod_sel'], '_')) { list($module, $method) = explode('_', $_REQUEST['shipping_mod_sel']); $module = 'osC_Shipping_' . $module; if (is_object($GLOBALS[$module]) && $GLOBALS[$module]->isEnabled()) { $quote = $osC_Shipping->getQuote($_REQUEST['shipping_mod_sel']); if (isset($quote['error'])) { $osC_ShoppingCart->resetShippingMethod(); $errors[] = $quote['error']; } else { $osC_ShoppingCart->setShippingMethod($quote); } } else { $osC_ShoppingCart->resetShippingMethod(); } } } else { $osC_ShoppingCart->resetShippingMethod(); } //gift wrapping if (isset($_POST['gift_wrapping']) && $_POST['gift_wrapping'] == 'true') { $osC_ShoppingCart->setGiftWrapping(true); if (!empty($_POST['gift_wrapping_comments'])) { $_SESSION['gift_wrapping_comments'] = osc_sanitize_string($_POST['gift_wrapping_comments']); } } else { $osC_ShoppingCart->setGiftWrapping(false); unset($_SESSION['gift_wrapping_comments']); } if (sizeof($errors) > 0) { $response = array('success' => false, 'errors' => $errors); } else { $form = self::_getPaymentMethodForm(); $response = array('success' => true, 'form' => $form['form'], 'javascript' => $form['javascript']); } echo $toC_Json->encode($response); }
function saveShippingMethod() { global $toC_Json, $osC_Language, $osC_Shipping, $osC_ShoppingCart, $osC_Weight, $osC_Tax, $osC_Currencies; $osC_ShoppingCart = new toC_ShoppingCart_Adapter($_REQUEST['orders_id']); $osC_Shipping = new osC_Shipping(); $osC_Tax = new osC_Tax_Admin(); $osC_Weight = new osC_Weight(); $osC_Currencies = new osC_Currencies(); if ($osC_Shipping->hasQuotes()) { if (isset($_REQUEST['code']) && strpos($_REQUEST['code'], '_')) { list($module, $method) = explode('_', $_REQUEST['code']); $module = 'osC_Shipping_' . $module; if (is_object($GLOBALS[$module]) && $GLOBALS[$module]->isEnabled()) { $quote = $osC_Shipping->getQuote($_REQUEST['code']); if (isset($quote['error'])) { $osC_ShoppingCart->resetShippingMethod(); } else { $osC_ShoppingCart->setShippingMethod($quote); } } else { $osC_ShoppingCart->resetShippingMethod(); } } } $osC_ShoppingCart->updateOrderTotal(); $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed')); echo $toC_Json->encode($response); }
function _get_express_checkout_details($params) { global $osC_ShoppingCart, $osC_Currencies, $osC_Language, $osC_Database, $osC_Tax, $messageStack, $osC_Customer, $osC_Session; // if there is nothing in the customers cart, redirect them to the shopping cart page if (!$osC_ShoppingCart->hasContents()) { osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'SSL', true, true, true)); } $params['VERSION'] = $this->api_version; $params['METHOD'] = 'GetExpressCheckoutDetails'; $params['TOKEN'] = $_GET['token']; $post_string = ''; foreach ($params as $key => $value) { $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&'; } $post_string = substr($post_string, 0, -1); $response = $this->sendTransactionToGateway($this->api_url, $post_string); $response_array = array(); parse_str($response, $response_array); if ($response_array['ACK'] == 'Success' || $response_array['ACK'] == 'SuccessWithWarning') { $force_login = false; // Begin: check if e-mail address exists in database and login or create customer account if ($osC_Customer->isLoggedOn() == false) { $force_login = true; if (class_exists('osC_Account') == false) { require_once 'includes/classes/account.php'; } $email_address = $response_array['EMAIL']; $Qcheck = $osC_Database->query('select * from :table_customers where customers_email_address = :email_address limit 1'); $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcheck->bindValue(':email_address', $email_address); $Qcheck->execute(); if ($Qcheck->numberOfRows() > 0) { $check = $Qcheck->toArray(); $customer_id = $check['customers_id']; $osC_Customer->setCustomerData($customer_id); } else { $data = array('firstname' => $response_array['FIRSTNAME'], 'lastname' => $response_array['LASTNAME'], 'email_address' => $email_address, 'password' => osc_rand(ACCOUNT_PASSWORD, max(ACCOUNT_PASSWORD, 8))); osC_Account::createEntry($data); } $Qcheck->freeResult(); if (SERVICE_SESSION_REGENERATE_ID == '1') { $osC_Session->recreate(); } } // End: check if e-mail address exists in database and login or create customer account // Begin: Add shipping and billing address from paypal to the shopping cart if ($force_login == true) { $country_query = $osC_Database->query('select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format from :table_countries where countries_iso_code_2 = :country_iso_code_2'); $country_query->bindTable(':table_countries', TABLE_COUNTRIES); $country_query->bindValue(':country_iso_code_2', $response_array['SHIPTOCOUNTRYCODE']); $country_query->execute(); $country = $country_query->toArray(); $zone_name = $response_array['SHIPTOSTATE']; $zone_id = 0; $zone_query = $osC_Database->query('select zone_id, zone_name from :table_zones where zone_country_id = :zone_country_id and zone_code = :zone_code'); $zone_query->bindTable(':table_zones', TABLE_ZONES); $zone_query->bindInt(':zone_country_id', $country['countries_id']); $zone_query->bindValue(':zone_code', $response_array['SHIPTOSTATE']); $zone_query->execute(); if ($zone_query->numberOfRows()) { $zone = $zone_query->toArray(); $zone_name = $zone['zone_name']; $zone_id = $zone['zone_id']; } $sendto = array('firstname' => substr($response_array['SHIPTONAME'], 0, strpos($response_array['SHIPTONAME'], ' ')), 'lastname' => substr($response_array['SHIPTONAME'], strpos($response_array['SHIPTONAME'], ' ') + 1), 'company' => '', 'street_address' => $response_array['SHIPTOSTREET'], 'suburb' => '', 'email_address' => $response_array['EMAIL'], 'postcode' => $response_array['SHIPTOZIP'], 'city' => $response_array['SHIPTOCITY'], 'zone_id' => $zone_id, 'zone_name' => $zone_name, 'country_id' => $country['countries_id'], 'country_name' => $country['countries_name'], 'country_iso_code_2' => $country['countries_iso_code_2'], 'country_iso_code_3' => $country['countries_iso_code_3'], 'address_format_id' => $country['address_format_id'] > 0 ? $country['address_format_id'] : '1'); $osC_ShoppingCart->setRawShippingAddress($sendto); $osC_ShoppingCart->setRawBillingAddress($sendto); $osC_ShoppingCart->setBillingMethod(array('id' => $this->getCode(), 'title' => $this->getMethodTitle())); } // End: Add shipping and billing address from paypal to the shopping cart //Begin: Add the shipping if ($osC_ShoppingCart->getContentType() != 'virtual') { if ($osC_ShoppingCart->hasShippingMethod() === false) { if (class_exists('osC_Shipping') === false) { include_once 'includes/classes/shipping.php'; } $osC_Shipping = new osC_Shipping(); if ($osC_Shipping->hasQuotes()) { $shipping_set = false; // get all available shipping quotes $quotes = $osC_Shipping->getQuotes(); if (isset($response_array['SHIPPINGOPTIONNAME']) && isset($response_array['SHIPPINGOPTIONAMOUNT'])) { foreach ($quotes as $quote) { if (!isset($quote['error'])) { foreach ($quote['methods'] as $rate) { if ($response_array['SHIPPINGOPTIONNAME'] == $quote['module'] . ' (' . $rate['title'] . ')') { if ($response_array['SHIPPINGOPTIONAMOUNT'] == $osC_Currencies->formatRaw($rate['cost'] + $quote['cost'] * $quote['tax'] / 100)) { $shipping = $quote['id'] . '_' . $rate['id']; $module = 'osC_Shipping_' . $quote['module']; if (is_object($GLOBALS[$module]) && $GLOBALS[$module]->isEnabled()) { $quote = $osC_Shipping->getQuote($shipping); if (isset($quote['error'])) { $osC_ShoppingCart->resetShippingMethod(); $errors[] = $quote['error']; } else { $osC_ShoppingCart->setShippingMethod($quote); $shipping_set = true; } } else { $osC_ShoppingCart->resetShippingMethod(); } break 2; } } } } } } if ($shipping_set == false) { // select cheapest shipping method $osC_ShoppingCart->setShippingMethod($osC_Shipping->getCheapestQuote()); } } } } if (!isset($_SESSION['ppe_token'])) { $_SESSION['ppe_token'] = $response_array['TOKEN']; } if (!isset($_SESSION['ppe_payerid'])) { $_SESSION['ppe_payerid'] = $response_array['PAYERID']; } if (!isset($_SESSION['ppe_payerstatus'])) { $_SESSION['ppe_payerstatus'] = $response_array['PAYERSTATUS']; } if (!isset($_SESSION['ppe_addressstatus'])) { $_SESSION['ppe_addressstatus'] = $response_array['ADDRESSSTATUS']; } osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'process', 'SSL')); } else { $messageStack->add_session('shopping_cart', $osC_Language->get('payment_paypal_express_error_title') . ' <strong>' . stripslashes($response_array['L_LONGMESSAGE0']) . '</strong>'); osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'SSL')); } }