X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Free shipping on selected products but keep other shipping drop down box (https://forum.x-cart.com/showthread.php?t=36896)

ExoZed 01-21-2008 07:43 AM

Free shipping on selected products but keep other shipping drop down box
 
I wanted to have free shipping on selected products, and don't have any real time shipping. We only use Royal mail 1st second and ANC.


But unfortunately I could not find the exact solution to my question on any thread.
I asked my question on this http://forum.x-cart.com/showthread.php?t=36780 thread but nobody replied.

I did not want to do it through special offers module, since ours is heavily customized by someone an does not do this free shipping properly. (some bugs in it)

I am quite new to xcart so this may not be the right way please give me some feedback to improve this. I am still testing it on my testing server (4.0.14-gold_upgrade ).

* This is not fully tested so please test it in a dev site first. I am not responsible if anything goes wrong.

Basically I have used the idea and codes from joltedpixel
on this thread so please read it first http://forum.x-cart.com/showthread.php?t=33947&highlight=Free+Ground+Shipp ing+Mod (Free Ground Shipping Mod) lots of thanks and credits to joltedpixel

1) Create a shipping method with zero charge. Mine is called FREE (Royal Mail 2nd Class UK)
2) Get the shipping charge ID number this can be found by viewing the source on the shipping charges page. You should get a two digit number or three digit number that will be in the value of the check box for that shipping charge. Mine was 138 and you can see that in the code later.

Step 1:
On the cart.php after this
Code:

} else {
$cart["delivery"] = "";
$cart["shippingid"] = 0;
}

add the follwing code and change the ids for your free shipping method and the default shippng accordingly.

Code:

#check products' shipping
$free_uk = true;
foreach ($products as $product) { // Runs through all products in Cart

                if ($product['free_shipping'] !='F' ){ // Counts
                $free_uk = false;
                }
}

if($free_uk == false){
        $shipping_new = ""; #ca
        foreach ($shipping as $sh ) { // Runs through all shipping
       
                if ($sh['shippingid'] != 138){ // Counts
                $shipping_new[] = $sh;
               
                }
        }
        #if threre is no free shipping item in the cart
        #change the free shipping back to default shipping  Royal Mail 2nd Class with id  127
        if($cart['shippingid'] == 138){
                $cart['delivery'] =  'Royal Mail 2nd Class';
                $cart['shippingid'] = 127 ;
                $cart['shipping_cost'] = 2.15;
        }
        #overwrite the prevouse assignment of $shipping variables
        $smarty->assign("shipping", $shipping_new);

}
#change the cart if a free shipping item is remained in the cart and non-free shipping itmes o deleted  id 127 is our default shipping method which is a second Royal Mail 2nd Class 2.15
elseif (($cart['shippingid'] == 138 || $cart['shippingid'] == 127 )&& $free_uk == true) {
        $cart['delivery'] =  'FREE (Royal Mail 2nd Class) ';
        $cart['shippingid'] = 138 ;
        $cart['shipping_cost'] = 0;

}


Step 2: please follow step 3 to the end of (value=’G'{if $product.free_shipping eq ‘G’}) is used 'F' instead of 'G'
joltedpixel from http://forum.x-cart.com/showthread.php?t=33947&highlight=Free+Ground+Shipp ing+Mod


All times are GMT -8. The time now is 06:29 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.