by
KK » Thu Jun 13, 2013 5:56 am
Thanks.
As promised, here is a possible solution:
There could be two ways of looking at your situation -
1.
a. Everybody pays $100 as shipping unless the cart amount is greater than $1000 at which point shipping gets free.
b. 'Discovery Bay and Tung Chung' always gets free shipping.
2.
a. Everybody gets free shipping.
b. Except 'Hong Kong Island and Kowloon' which gets to pay $100 unless the cart amount is greater than $1000.
Begin with adding the following form to 'checkout.php'
- Code: Select all
<cms:form method="post" anchor='0'>
<cms:if k_success >
<cms:set_session name='selected_shipping_location' value=frm_shipping_location />
<cms:pp_refresh_cart />
<cms:redirect k_page_link />
</cms:if>
<div class="styled">
<cms:input type="dropdown"
name="shipping_location"
opt_values="
Choose Shipping Location = 0 |
Discovery Bay and Tung Chung (free) = 1 |
Hong Kong Island and Kowloon (100HK$) = 2 "
opt_selected = "<cms:get_session 'selected_shipping_location' />"
onchange="this.form.submit()"
/>
</div>
</cms:form>
The form above simply shows the two shipping regions (you can add a note below this to show that shopping of more than $1000 will be free).
Upon selection of a region, the form stores the selection in session as a variable named 'selected_shipping_location' (the values could be 0, 1 or 2 depending on the choice) and calls cms:pp_refresh_cart which causes the cart to redo all calculations.
The shipping calculation routine in 'cart_ex.php' can now make use of this variable to do the appropriate calculation.
The next steps will differ a bit depending on which scenario we are using (i.e. everybody free or everybody $100 as discussed above).
First scenario:a. Everybody pays $100 as shipping unless the cart amount is greater than $1000 at which point shipping gets free.This can be easily done by setting the following in cart/config.php -
- Code: Select all
$pp['shipping_by_order_total'] = '[ 0=100 | 1000=0 ]';
The setting above simply states (see documentation if not clear) that orders of value between $0 t0 $1000 will have a charge of $100. Anything above $1000 will have a shipping charge of $0 (i.e. free).
b. 'Discovery Bay and Tung Chung' always gets free shipping.This can be done by adding the following to get_shipping() function in cart_ex.php
function get_shipping(){
global $KSESSION;
$cost = 0;
$items = $this->count_shippable_items;
if( !$items ) return 0; // No item in the cart that needs shipping
// Check if a free shipping location is selected
if( $KSESSION->get_var('selected_shipping_location') == '1' ){ // Discovery Bay and Tung Chung is '1'
return 0;
}
// First check if a discount coupon provides free shipping
if( $KSESSION->get_var('coupon_found') &&
...
I think it is easy to see that the code is simply checking if the selected location is '1' (i.e. Discovery Bay and Tung Chung) and if it is, returning a charge of 0.
Second scenario:a. Everybody gets free shipping.Nothing needs to be done for this. This is the default.
b. Except 'Hong Kong Island and Kowloon' which gets to pay $100 unless the cart amount is greater than $1000.This can be done by adding the following to get_shipping() function in cart_ex.php
function get_shipping(){
global $KSESSION;
$cost = 0;
$items = $this->count_shippable_items;
if( !$items ) return 0; // No item in the cart that needs shipping
// Check if location needs shipping charges
if( $KSESSION->get_var('selected_shipping_location') == '2' ){ // Hong Kong Island and Kowloon is '2'
if( $this->sub_total_discounted < 1000 ){
$cost = 100; // add 100 if cart value less than 1000
}
}
// First check if a discount coupon provides free shipping
if( $KSESSION->get_var('coupon_found') &&
...
Hope this helps.
Please let me know if I missed something.
Thanks.