Problems, need help? Have a tip or advice? Post it here.
20 posts Page 1 of 2
Here goes, my client ships to some areas for free, and for some it is payed(100HKD-Hong Kong Dollars). Also, if the customer that is in the payed area buys items for more than 1000HKD, then the shipment will be free.

What would be the easiest logic to implement this?
Hi,

It will require some custom coding in the 'cart_ex.php' get_shipping function.

The logic could go something like this (it is a variation of how we've implemented 'coupon' logic in the tutorial) -
Somewhere on the site (maybe on the checkout page), use a separate Couch form to show the customer a list of the locations you ship to. In the success condition of this form's submission, set the selected shipping location in a session variable.

The get_shipping function can now be modified to get the shipping location from session and do the needful calculation (the value of the cart is already known to it).

Does this help?
Thanks KK! I understand it to some extent, but I think I'll need some hand holding here:)
I am halway through creating the cart and all the stuff necessary. I'll buy the licence tomorrow for the domain, will put the website online and then I will come back here for any help I may need in doing the steps you provided.

What about this approach; A product options dropdown with only the +100$ option for payed shipment. There would be a little disclaimer about who qualifies for free shipping, so that those people can select this option if they need to pay it.

The only thing is that it should be added only once for whole shopping session, so maybe a little message saying "Add shipping costs only for one item added" or something like that.
But I guess this is bad user experinece:((
No worries :)

I think it'd be better to go with the accepted way of setting shipping based on location (coupled with the cart value).

Could you please provide me with the dropdown (HTML code will do) that shows the user the locations you'll ship to along with the associated costs?

I'll try and post a working sample of how to integrate it with shipping. Might be helpful to others also.

Thanks.
No problem, here is the HTML for it. It is basically a regular select element wrapped in a div, so that at least some styling can be applied without using JS or having any other dependancies.

Code: Select all
  <div class="styled">
   <select>
<option>Discovery Bay and Tung Chung(free)</option>
<option>Hong Kong Island and Kowloon(100HK$)</option>
<option>Hong Kong Island and Kowloon(free)*purchase over 1000HK$</option>
     </select>
   </div>
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.
Thanks KK! It works really well, I opted for the second option, because it seemed more natural to me.
But there are still some quirks, I guess I can't do everything right even if it is all nicely explained to me:)

First of all, I can't continue to PayPal from the checkout page, it sends me to cart.php.
I used the code from the tutorial, but I guess it is some stupid mistake from my side.

And the second thing is that I can't AJAX-ify the cart, I tried with a few solutions, but it just wont work.
Maybe the problem is that I am already using AJAX to load all pages(content) on this website, maybe some kind of conflict. The JS files that you are calling in index.php in the tutorial, I am calling in the wines.php, and the wines.php is called by AJAX from index.php.

Upon inspection with firebug, it seems that none of the javascript files is loaded when loading wines.php, this really baffles me.

And the third thing, my cart remembers eveyrthing from previous sessions, even after reloading the page. I think this is not the desired behaviour, or is it?

Anyway, the link is www.jadedpalates.com, if you could please have a look, I'll be really grateful:)
First of all, I can't continue to PayPal from the checkout page, it sends me to cart.php.
I used the code from the tutorial, but I guess it is some stupid mistake from my side.

Could you please PM me the checkout.php template? I had a look at the site and I think there a little mistake somewhere in your implementation - the checkout form doesn't look right to me.

And the second thing is that I can't AJAX-ify the cart, .. Maybe the problem is that I am already using AJAX to load all pages(content) on this website, maybe some kind of conflict.

The main site is already heavily AJAXified so, yes, there must be some kind of conflict here.
JS, unfortunately, is not my forte. Maybe @cheesypoof could take a look at the problem. I'm sure he'll be able to spot the problem (please try PMing him).

third thing, my cart remembers eveyrthing from previous sessions, even after reloading the page. I think this is not the desired behaviour, or is it?

It is in our control to clear the session data. The appropriate place to do it is when we redirect the visitor to PayPal during checkout
Code: Select all
<cms:pp_payment_gateway 
    shipping_address="<cms:if "<cms:pp_count_shippable_items />" >1<cms:else />0</cms:if>"
    empty_cart='0'
/>

- setting the 'empty_cart' to '1' will clear all data (in our tutorial we've set it to '1' for ease of repeated testing).

In your case, this checkout code is not executing at all so we'll come to that when the checkout problem is resolved.
Thanks, I'll PM you right away with all you need. @cheesypoof also crossed my mind, due to the fact that is the author of all thing JS related in the cart!
1. The 'Add to Cart' forms need to have class="cart-form" otherwise the modal window script will not handle submissions and you will be taken directly to cart.php.

2. I think you should move the modal cart HTML and JavaScript to the bottom of your index.php template so you won't have to deal with dynamically loading JS.

3. The cart_link JS variable is empty. Have you setup the cart-modal.php template yet?
20 posts Page 1 of 2
cron