Jump to content

[Solved] Allow Google Checkout to calculate shipping by carrier.


Recommended Posts

Since Prestashop does not have a very friendly method for calculating shipping costs, I wanted to use Google Checkout for this purpose. I am running into a problem though. It seems that the weight for each item is not being sent to Google Checkout and there for the automatic calculation of shipping at Google Checkout can not take place.

[HOW TO FIX]

The first issue is that Google will automatically use the cost of your shipping in the cart. Since Prestashop at present always send at the least the cost you have listed in "Fees by carrier, geographical zone, and ranges" under the shipping tab, Google Checkout will ALWAYS list this as you cost for shipping. So we need to stop presta shop from sending any shipping info to the cart. We will need to edit the following line in modules/gcheckout/gcheckout.php
Look around line 136 for:

$googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency)));



We need to comment this out by adding // as seen below

//$googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency)));



You should now be able to see you Carrier charges you have setup in Google Checkout on the purchase page. It may not yet show carrier Calculated shipping from Google. If you only have carrier calculated shipping setup in Google, test to make sure the fist step worked, by adding a "flat rate" shipping method in your Google Checkout settings. Go through your order process again and you should see the flat rate option in your Google Checkout window now.

Now we need to make sure Google Checkout is receiving your product weight. I believe at present Google checkout will only accept LB so we need to make sure prestashops default measurement under Preferences > Localization is "LB".
Next we need to edit the gcheckout.php file under, modules/gcheckout/gcheckout.php again.
Look around line 131 for:

$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency)));



Now change it to this

$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency), strtoupper(Configuration::get('PS_WEIGHT_UNIT')), $product['weight']));



Now make your way through your cart again and you should see the carrier calculated shipping at Google Checkout now.


A BIG thanks to rocky for helping me though this!

Link to comment
Share on other sites

You are right. For some reason, the product weight isn't included when adding the product to the Google cart. Try changing line 131 of modules/gcheckout/gcheckout.php from:

$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency)));



to:

$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency), strtoupper(Configuration::get('PS_WEIGHT_UNIT')), $product['weight']));



This should add the product's weight to the cart and whatever weight unit (kg or lb) that is specified on the Preferences > Localization tab.

Link to comment
Share on other sites

Well I made the changes to the code and found that the issue is still present. I decided to do a little test. I made a free shipping method for local friends, ie a Pickup in store, in the google merchant account. I then proceeded to make my way to the cart though my store again. Once I was at the purchase section of Google Checkout it again said free and did not give the option to choose "In-Store" from the shipping drop down. This proves that it is not caused by an issue of not getting the weight from prestashop as I had previously believed.

I did a little looking around in the shipping section of Google Checkouts setting and found the following quote.

These shipping settings will only be applied to cart posts that do not already specify shipping methods.


GREAT!!! So now the problem is that I cant get rid of the shipping option in Prestashop.

Any Ideas?
Link to comment
Share on other sites

UPDATE...

By commenting out the following code in gcheckout.php at line 136 I have managed to get In-Store mentioned above as an option in the dropdown on the Google Checkout page.

//$googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency)));


The carrier calculated shipping is still not showing up. It looks like it is NOW having an issue with receiving unit weights. Im not sure what to do now.

Any ideas?
Link to comment
Share on other sites

Did you try deleting the two parameters I suggested that you add so that the product weights aren't sent?


Yes, I tried that right after the In-Store started showing, but its had no effect on getting the calculated shipping.

BTW should I have "PS_WEIGHT_UNIT" as you have written out in your code, or should i fill in OZ, oz in that field instead.
In truth I have tried both ways, but it still does not work.
Link to comment
Share on other sites

I don't think Google Checkout supports "OZ" as the weight unit. I think it only accepts "KG" or "LB". You should use one of those weight units.


Still no change. I tried changing the default unit in Prestacart back end and gchechout.php to "LB", "LBS", "lb", "lbs" but I end up with the same issue. I also tried leaving the code in gcheckout.php at default and with "PS_WEIGHT_UNIT" in place of "lbs".

Please have a look at the code you sent me originally. I am not a coder by any stretch most of it is just flat out Latin to me.
However something looks out of place with regards to the ")" symbols at the end of the code string. Also from working my way through building this page and editing parts of it in dreamweaver, I have learned that the php files call up info from the tpl files. Is it possible that info in one of the tpl files needs to be changed or a new tpl file created?

As I said most of this is Latin to me and Im just shooting in the dark. If I am way off base please forgive my ignorance and let me extend my thanks for your help so far.
Link to comment
Share on other sites

You're right. I made a mistake in my code here. I've fixed it.


Oh hell yea! Thank you so much.

Seems to be functioning properly now. I will edit the the original post with [sOLVED] and the changes to the two lines of coded needed to make it function.
Link to comment
Share on other sites

  • 5 months later...
Since Prestashop does not have a very friendly method for calculating shipping costs, I wanted to use Google Checkout for this purpose. I am running into a problem though. It seems that the weight for each item is not being sent to Google Checkout and there for the automatic calculation of shipping at Google Checkout can not take place.

[HOW TO FIX]

The first issue is that Google will automatically use the cost of your shipping in the cart. Since Prestashop at present always send at the least the cost you have listed in "Fees by carrier, geographical zone, and ranges" under the shipping tab, Google Checkout will ALWAYS list this as you cost for shipping. So we need to stop presta shop from sending any shipping info to the cart. We will need to edit the following line in modules/gcheckout/gcheckout.php
Look around line 136 for:

$googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency)));



We need to comment this out by adding // as seen below

//$googleCart->AddShipping(new GooglePickUp($this->l('Shipping costs'), Tools::convertPrice($params['cart']->getOrderShippingCost($params['cart']->id_carrier), $currency)));



You should now be able to see you Carrier charges you have setup in Google Checkout on the purchase page. It may not yet show carrier Calculated shipping from Google. If you only have carrier calculated shipping setup in Google, test to make sure the fist step worked, by adding a "flat rate" shipping method in your Google Checkout settings. Go through your order process again and you should see the flat rate option in your Google Checkout window now.

Now we need to make sure Google Checkout is receiving your product weight. I believe at present Google checkout will only accept LB so we need to make sure prestashops default measurement under Preferences > Localization is "LB".
Next we need to edit the gcheckout.php file under, modules/gcheckout/gcheckout.php again.
Look around line 131 for:

$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency)));



Now change it to this

$googleCart->AddItem(new GoogleItem(utf8_decode($product['name']), utf8_decode($product['description_short']), intval($product['cart_quantity']), Tools::convertPrice($product['price_wt'], $currency), strtoupper(Configuration::get('PS_WEIGHT_UNIT')), $product['weight']));



Now make your way through your cart again and you should see the carrier calculated shipping at Google Checkout now.


A BIG thanks to rocky for helping me though this!




Indeed, yes! A big "thank you" to you both. I am endlessly amazed at the generous way folks share knowledge in these forums, so I'm hoping somebody can share a little bit more to help me out!

I now have Google Checkout calculating both shipping and tax for my store and everything is working perfectly, except for one thing. The calculated shipping value is not being returned to the Prestashop back office.

The order shows up, but the shipping is $0, which is the value I have applied for my default carrier because I don't want Prestashop to calculate the order for me. The carrier seems to be required for the checkout process to work (no carrier gets the 'There is no carrier....etc.' error and stops the process). I know it is the default value showing up because, if I change the carrier default to $10, this is the value that shows up in the back office orders irrespective of what shipping has been calculated by Google.

I have checked the xml being returned by Google (in googlemessage.log) and it includes the correct calculated shipping method and cost (e.g. 10.052).

So - it seems to me that there must be a way to pull this data into the back office instead of the default shipping fee. I just can't find out where or how to do it.

This is my last big obstacle to having the store fully functional and I've spend most of today trying to work it out. Can anyone help?
Thanks in advance,
Yun
Link to comment
Share on other sites

  • 3 months later...

This fix had originally solved this for me. However a few days ago I updated to PrestaShop version 1.4.0.17. Even though the new Google Checkout module in the back office gives an option to "Use Google shipping fees" I am no longer able to do so every since I installed the update.

I compared the source code of the new Google Checkout Module to the old one. I believe that the problem lies here...with the upgraded Google Checkout module product weights are no longer being sent to Google Checkout...

Can anyone assist?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...