Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

shipping price fixed in admin, but need additional costs for international deleveries


Go to End


3 Posts   1992 Views

Avatar
neilos

Community Member, 19 Posts

13 January 2011 at 2:44am

Hi all,

I have SS 2.3.5 with the ecommerce module on.
The module is heavily customised so upgrading will be extremly time consuming.

What I have is, in the admin section there is a shipping costs field where the admin can assign different costs for shipping on a product by product basis.
I have added an extra field for the international costs but can't implement it to work as required.

The code i have from code > products > Product.php;

    function UnitShipping_Cost() {  
    
        global $country;
        
        if     ($country == "GB" ) 
                {
                    if ($this->Product()->Shipping_Cost) return $this->Product()->Shipping_Cost;
                }
        else        
                {
                    if ($this->Product()->Int_Shipping_Cost) return $this->Product()->Int_Shipping_Cost;
                }
             
    }

Currently what happens is the $country is being ignored and the international shipping rate is being applied.
How do I find the $country first to add teh relevant shipping amount?

Hanx in advance

Nels

Avatar
patjnr

Community Member, 102 Posts

17 January 2011 at 6:28am

Hi Neilos

With e-commerce you can get every logged in member country as this is also used on billing address.
The simplest way of getting user's Country is by using EcommerceRole::findCountry() aslo with your UnitShipping_Cost method, if this condition is not met ($country == "GB" ), then nothing was happening.

	function UnitShipping_Cost() {
		$country = EcommerceRole::findCountry();
		if($country == "United Kingdom"){
			return ($this->Product()->Shipping_Cost) ? $this->Product()->Shipping_Cost : $this->Product()->Int_Shipping_Cost;
		}
		return $this->Product()->Int_Shipping_Cost;
	}	

Can you post you Product.php as your modifications might help many people.

thx

PJ

Avatar
neilos

Community Member, 19 Posts

17 January 2011 at 11:22pm

Hi PAt Jnr,

Thanks for looking at this.
You can view all of Product.php here, I hope someone else finds it useful:
http://pastie.org/1469295

I have added your function, but it still doesn't alter the shipping costs at checkout for UK or non-UK orders.

FYI;

In that function, if I use

if($country == "United Kingdom")

It uses the value for "Shipping_Cost" regardless of country selected
And if I use
if($country != "United Kingdom")

It uses the value for "Int_Shipping_Cost" regardless of country selected.

Regards

Nels