Difference between revisions of "Draft:Developer's FAQ"

From X-Cart 4 Classic
Jump to: navigation, search
(Created page with '===Is there an easy way to grab domestic shipping rates other than using the "func_get_shipping_methods_list" function?=== '''I'm attempting to use the "func_get_shipping_method…')
 
(Is there an easy way to grab domestic shipping rates other than using the "func_get_shipping_methods_list" function?)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
===Is there an easy way to grab domestic shipping rates other than using the "func_get_shipping_methods_list" function?===
+
===Is there an easy way to grab domestic shipping rates overriding the default destination address?===
  
'''I'm attempting to use the "func_get_shipping_methods_list" function anyway, but I can't figure out how to override the destination address, even though I'm passing it to the function. We need to override the destination so that we calculate the shipping from the company address to our warehouse, rather than from the company address to the user's address.'''
+
To achieve your objective, you will have to use the func_get_shipping_methods_list function. The function returns a PHP array.
  
You should use func_get_shipping_methods_list function to reach this aim.
+
In your case, the key setting is $config['General']['apply_default_country']. The 'Override destination address before shipping calculated' task is implemented here:
func_get_shipping_methods_list returns PHP array
 
  
The key setting in your case is $config['General']['apply_default_country'].
+
<source>[~/www/xcart_4_4_x]$ grep -r --include='*.php' "apply_default_country.*Y" *|grep -v '=='|grep -v '!='
 
 
The 'Override destination address before shipping calculated' task is realized here
 
<source>[~/www/xcart_4_4_x]$ grep -r --include='*.php' "apply_default_country.*Y" *|g -v '=='|g -v '!='
 
 
modules/Amazon_Checkout/func.php: $config['General']['apply_default_country'] = 'Y';
 
modules/Amazon_Checkout/func.php: $config['General']['apply_default_country'] = 'Y';
 
modules/Google_Checkout/gcheckout_callback.php: $config['General']['apply_default_country'] = 'Y';
 
modules/Google_Checkout/gcheckout_callback.php: $config['General']['apply_default_country'] = 'Y';
 
</source>
 
</source>
  
This is code from modules/Amazon_Checkout/func.php
+
Here is the code from modules/Amazon_Checkout/func.php
  
 
<source>
 
<source>
Line 20: Line 16:
 
{
 
{
 
...
 
...
// Option adjustment to avoid empty($userinfo) checking
+
  // Option adjustment to avoid empty($userinfo) checking
// $userinfo will be provided by Amazon in callback
+
  // $userinfo will be provided by Amazon in callback
$config['Shipping']['enable_all_shippings'] = 'Y';
+
  $config['Shipping']['enable_all_shippings'] = 'Y';
$userinfo = $cart['userinfo'];
+
  $userinfo = $cart['userinfo'];
$products = func_products_in_cart($cart, (!empty($user_account['membershipid']) ? $user_account['membershipid'] : ''));
+
  $products = func_products_in_cart($cart, (!empty($user_account['membershipid']) ? $user_account['membershipid'] : ''));
  
$_need_shipping = func_cart_is_need_shipping($cart, $products, $userinfo, 'dont_check_free_ship_coupons');
+
  $_need_shipping = func_cart_is_need_shipping($cart, $products, $userinfo, 'dont_check_free_ship_coupons');
  
if (empty($_need_shipping)) {
+
  if (empty($_need_shipping)) {
$result_cache[$md5_args] = false;
+
    $result_cache[$md5_args] = false;
return false;
+
  return false;
 
}
 
}
  
Line 56: Line 52:
 
Or use the code from <u>modules/Google_Checkout/gcheckout_callback.php</u>
 
Or use the code from <u>modules/Google_Checkout/gcheckout_callback.php</u>
  
[quote]If I wanted to grab the coupon codes being used on a specific order, where should I be looking? Is this included in the $cart data?[/quote]
+
===If I wanted to grab the coupon codes being used on a specific order, where should I be looking? Is this included in the $cart data?===
 +
 
 +
This variable stores the coupon code applied to the cart after cart recalculation:
  
This variable keeps coupon code applied in the cart after cart recalculation
+
<source>
[code]
 
 
$cart['coupon']
 
$cart['coupon']
[/code]
+
</source>
 
 
The same field has sql xcart_orders table
 
 
 
[quote]Developer:
 
 
 
Elijah Boston
 
 
 
Elijah.boston@bongous.com[/quote]
 
  
Thank you.
+
The same field is available in the sql xcart_orders table.

Latest revision as of 13:37, 26 January 2012

Is there an easy way to grab domestic shipping rates overriding the default destination address?

To achieve your objective, you will have to use the func_get_shipping_methods_list function. The function returns a PHP array.

In your case, the key setting is $config['General']['apply_default_country']. The 'Override destination address before shipping calculated' task is implemented here:

[~/www/xcart_4_4_x]$ grep -r --include='*.php' "apply_default_country.*Y" *|grep -v '=='|grep -v '!='
modules/Amazon_Checkout/func.php: $config['General']['apply_default_country'] = 'Y';
modules/Google_Checkout/gcheckout_callback.php: $config['General']['apply_default_country'] = 'Y';

Here is the code from modules/Amazon_Checkout/func.php

function func_amazon_get_shipping_methods12($cart)
{
...
  // Option adjustment to avoid empty($userinfo) checking
  // $userinfo will be provided by Amazon in callback
  $config['Shipping']['enable_all_shippings'] = 'Y';
  $userinfo = $cart['userinfo'];
  $products = func_products_in_cart($cart, (!empty($user_account['membershipid']) ? $user_account['membershipid'] : ''));

  $_need_shipping = func_cart_is_need_shipping($cart, $products, $userinfo, 'dont_check_free_ship_coupons');

  if (empty($_need_shipping)) {
    $result_cache[$md5_args] = false;
  return false;
}

// Some options require adjustment
$config['Shipping']['enable_all_shippings'] = 'N';

// Emulate the 'apply_default_country' option enabled
$config['General']['apply_default_country'] = 'Y';
$config['General']['default_country'] = $userinfo['b_country'];
$config['General']['default_zipcode'] = $userinfo['b_zipcode'];
$config['General']['default_state'] = $userinfo['b_state'];
$config['General']['default_city'] = $userinfo['b_city'];

$intershipper_recalc = 'Y';

x_load('shipping');
// Get list of all shipping methods that are potentially available for customers
$shipping_methods = func_get_shipping_methods_list($cart, $products, $userinfo);
...
}

Adjust $userinfo['b_*'] according to your warehouse address

Or use the code from modules/Google_Checkout/gcheckout_callback.php

If I wanted to grab the coupon codes being used on a specific order, where should I be looking? Is this included in the $cart data?

This variable stores the coupon code applied to the cart after cart recalculation:

$cart['coupon']

The same field is available in the sql xcart_orders table.