Exemple #1
0
 function osC_Checkout_Shipping()
 {
     global $osC_Database, $osC_ShoppingCart, $osC_Customer, $osC_Services, $osC_Language, $osC_NavigationHistory, $osC_Breadcrumb, $osC_Shipping;
     if ($osC_Customer->isLoggedOn() === false) {
         $osC_NavigationHistory->setSnapshot();
         osc_redirect(osc_href_link(FILENAME_ACCOUNT, 'login', 'SSL'));
     }
     if ($osC_ShoppingCart->hasContents() === false) {
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, null, 'SSL'));
     }
     // if the order contains only virtual products, forward the customer to the billing page as
     // a shipping address is not needed
     if ($osC_ShoppingCart->getContentType() == 'virtual') {
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'payment', 'SSL'));
     }
     $this->_page_title = $osC_Language->get('shipping_method_heading');
     if ($osC_Services->isStarted('breadcrumb')) {
         $osC_Breadcrumb->add($osC_Language->get('breadcrumb_checkout_shipping'), osc_href_link(FILENAME_CHECKOUT, $this->_module, 'SSL'));
     }
     if ($osC_Customer->hasDefaultAddress() === false) {
         $this->_page_title = $osC_Language->get('shipping_address_heading');
         $this->_page_contents = 'checkout_shipping_address.php';
         $this->addJavascriptFilename('templates/' . $this->getCode() . '/javascript/checkout_shipping_address.js');
         $this->addJavascriptPhpFilename('includes/form_check.js.php');
     } else {
         $this->addJavascriptFilename('templates/' . $this->getCode() . '/javascript/checkout_shipping.js');
         // if no shipping destination address was selected, use the customers own address as default
         if ($osC_ShoppingCart->hasShippingAddress() === false) {
             $osC_ShoppingCart->setShippingAddress($osC_Customer->getDefaultAddressID());
         } else {
             // verify the selected shipping address
             $Qcheck = $osC_Database->query('select address_book_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id limit 1');
             $Qcheck->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
             $Qcheck->bindInt(':address_book_id', $osC_ShoppingCart->getShippingAddress('id'));
             $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
             $Qcheck->execute();
             if ($Qcheck->numberOfRows() !== 1) {
                 $osC_ShoppingCart->setShippingAddress($osC_Customer->getDefaultAddressID());
             }
         }
         // load all enabled shipping modules
         if (class_exists('osC_Shipping') === false) {
             include '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 ($_GET[$this->_module] == 'process') {
         $this->_process();
     }
 }
Exemple #2
0
 function listShippingMethods()
 {
     global $toC_Json, $osC_Language, $osC_Currencies, $osC_Tax, $osC_Weight, $osC_ShoppingCart, $osC_Shipping;
     $osC_Language->loadIniFile($_SESSION['module'] . '.php');
     $osC_Currencies = new osC_Currencies_Admin();
     $osC_Tax = new osC_Tax_Admin();
     $osC_Weight = new osC_Weight();
     $osC_ShoppingCart = new toC_ShoppingCart_Adapter($_REQUEST['orders_id']);
     $osC_ShoppingCart->_calculate();
     unset($_SESSION['osC_ShoppingCart_data']['shipping_quotes']);
     $osC_Shipping = new osC_Shipping();
     if ($osC_ShoppingCart->hasShippingMethod() === false) {
         $osC_ShoppingCart->setShippingMethod($osC_Shipping->getCheapestQuote());
     }
     $records = array();
     foreach ($osC_Shipping->getQuotes() as $quotes) {
         $module = $quotes['module'];
         if (isset($quotes['icon']) && !empty($quotes['icon'])) {
             $module .= ' ' . $quotes['icon'];
         }
         $records[] = array('title' => '<b>' . $module . '</b>', 'code' => $quotes['id'], 'price' => '', 'action' => array());
         if (isset($quotes['error'])) {
             $records[] = array('title' => '&nbsp;&nbsp;--&nbsp;<i>' . $quotes['error'] . '</i>', 'code' => $quotes['id'] . '_error', 'price' => '', 'action' => array());
         } else {
             foreach ($quotes['methods'] as $methods) {
                 $records[] = array('title' => '&nbsp;&nbsp;--&nbsp;<i>' . $methods['title'] . '</i>', 'code' => $quotes['id'] . '_' . $methods['id'], 'price' => $osC_Currencies->displayPrice($methods['cost'], $quotes['tax_class_id'], 1, $osC_ShoppingCart->getCurrency()), 'action' => array('class' => 'icon-add-record', 'qtip' => ''));
             }
         }
     }
     $response = array(EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
Exemple #3
0
 function _calculate($set_shipping = true)
 {
     global $osC_Currencies, $osC_Tax, $osC_Weight, $osC_Shipping, $osC_OrderTotal;
     $this->_sub_total = 0;
     $this->_total = 0;
     $this->_weight = 0;
     $this->_tax = 0;
     $this->_tax_groups = array();
     $this->_shipping_boxes_weight = 0;
     $this->_shipping_boxes = 0;
     $this->_shipping_quotes = array();
     $this->_order_totals = array();
     $_SESSION['cartID'] = $this->generateCartID();
     if ($this->hasContents()) {
         foreach ($this->_contents as $data) {
             if ($data['type'] == PRODUCT_TYPE_SIMPLE || $data['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE && $data['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_PHYSICAL) {
                 $products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT);
                 $this->_weight += $products_weight * $data['quantity'];
             }
             $tax = $osC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
             $tax_description = $osC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
             $shown_price = $osC_Currencies->addTaxRateToPrice($data['final_price'], $tax, $data['quantity']);
             $this->_sub_total += $shown_price;
             $this->_total += $shown_price;
             if (DISPLAY_PRICE_WITH_TAX == '1') {
                 $tax_amount = $shown_price - $shown_price / ($tax < 10 ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax));
             } else {
                 $tax_amount = $tax / 100 * $shown_price;
                 //oscommerce 3 bug, no matter the tax is displayed or not, tax should not be add to total
                 $this->_total += $tax_amount;
             }
             $this->_tax += $tax_amount;
             if (isset($this->_tax_groups[$tax_description])) {
                 $this->_tax_groups[$tax_description] += $tax_amount;
             } else {
                 $this->_tax_groups[$tax_description] = $tax_amount;
             }
         }
         $this->_shipping_boxes_weight = $this->_weight;
         $this->_shipping_boxes = 1;
         if (SHIPPING_BOX_WEIGHT >= $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100) {
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT;
         } else {
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100;
         }
         if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) {
             // Split into many boxes
             $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT);
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes;
         }
         if ($set_shipping === true) {
             if (!class_exists('osC_Shipping')) {
                 include 'includes/classes/shipping.php';
             }
             if (!$this->isVirtualCart()) {
                 if (!$this->hasShippingMethod() || $this->getShippingMethod('is_cheapest') === true) {
                     $osC_Shipping = new osC_Shipping();
                     $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false);
                 } else {
                     $osC_Shipping = new osC_Shipping($this->getShippingMethod('id'));
                     $this->setShippingMethod($osC_Shipping->getQuote(), false);
                 }
             } else {
                 //reset shipping address and shipping method
                 $this->_shipping_address = array();
                 $this->_shipping_method = array();
             }
         }
         if (!class_exists('osC_OrderTotal')) {
             include 'includes/classes/order_total.php';
         }
         $osC_OrderTotal = new osC_OrderTotal();
         $this->_order_totals = $osC_OrderTotal->getResult();
     }
 }
 function _calculate($set_shipping = true)
 {
     global $osC_Currencies, $osC_Tax, $osC_Weight, $osC_Shipping, $osC_OrderTotal, $osC_Customer;
     //put the order currency code in the session for order total modules and shipping modules
     $_SESSION['currency'] = $this->getCurrency();
     $this->restoreStoreCredit();
     require_once '../includes/classes/customer.php';
     $osC_Customer = new osC_Customer();
     $osC_Customer->setCustomerData($this->getCustomersID());
     $this->_sub_total = 0;
     $this->_total = 0;
     $this->_weight = 0;
     $this->_tax = 0;
     $this->_tax_groups = array();
     $this->_shipping_boxes_weight = 0;
     $this->_shipping_boxes = 0;
     $this->_shipping_quotes = array();
     $this->_order_totals = array();
     if ($this->hasContents()) {
         foreach ($this->_contents as $products_id => $data) {
             $products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT);
             $this->_weight += $products_weight * $data['quantity'];
             $tax = $osC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
             $tax_description = $osC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
             //update tax to database
             $this->_contents[$products_id]['tax'] = $tax;
             $this->_updateProductTax($this->_contents[$products_id]['orders_products_id'], $tax);
             $shown_price = $osC_Currencies->addTaxRateToPrice($data['final_price'], $tax, $data['quantity']);
             $this->_sub_total += $shown_price;
             $this->_total += $shown_price;
             if (DISPLAY_PRICE_WITH_TAX == '1') {
                 $tax_amount = $shown_price - $shown_price / ($tax < 10 ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax));
             } else {
                 $tax_amount = $tax / 100 * $shown_price;
                 //oscommerce 3 bug, no matter the tax is displayed or not, tax should not be add to total
                 $this->_total += $tax_amount;
             }
             $this->_tax += $tax_amount;
             if (isset($this->_tax_groups[$tax_description])) {
                 $this->_tax_groups[$tax_description] += $tax_amount;
             } else {
                 $this->_tax_groups[$tax_description] = $tax_amount;
             }
         }
         $this->_shipping_boxes_weight = $this->_weight;
         $this->_shipping_boxes = 1;
         if (SHIPPING_BOX_WEIGHT >= $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100) {
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT;
         } else {
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100;
         }
         if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) {
             // Split into many boxes
             $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT);
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes;
         }
         if ($set_shipping === true) {
             unset($_SESSION['osC_ShoppingCart_data']['shipping_quotes']);
             if (!class_exists('osC_Shipping')) {
                 include 'includes/classes/shipping.php';
             }
             //check if this order already have a delivery method
             if (!empty($this->_deliver_module)) {
                 $osC_Shipping = new osC_Shipping($this->_deliver_module);
                 $this->setShippingMethod($osC_Shipping->getQuote(), false);
             } else {
                 if (!$this->hasShippingMethod() || $this->getShippingMethod('is_cheapest') === true) {
                     $osC_Shipping = new osC_Shipping();
                     $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false);
                 } else {
                     $osC_Shipping = new osC_Shipping($this->getShippingMethod('id'));
                     $this->setShippingMethod($osC_Shipping->getQuote(), false);
                 }
             }
         }
     }
     if (!class_exists('osC_OrderTotal')) {
         include 'includes/classes/order_total.php';
     }
     $osC_OrderTotal = new osC_OrderTotal();
     $this->_order_totals = $osC_OrderTotal->getResult();
     if ($this->isUseStoreCredit()) {
         $this->insertStoreCredit();
     }
     unset($_SESSION['currency']);
     unset($_SESSION['osC_Customer_data']);
 }
Exemple #5
0
 function _getShippingMethodForm()
 {
     global $osC_ShoppingCart, $osC_Customer, $osC_Language, $osC_Currencies;
     if (class_exists('osC_Shipping') === false) {
         include '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());
     }
     ob_start();
     //load all order total modules
     if (!class_exists('osC_OrderTotal')) {
         include 'includes/classes/order_total.php';
     }
     $osC_OrderTotal = new osC_OrderTotal();
     include 'includes/modules/shipping_method_form.php';
     $form = ob_get_contents();
     ob_end_clean();
     return $form;
 }
 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'));
     }
 }