rm2kdev Posted April 3, 2011 Share Posted April 3, 2011 Hey everyone,So Ive been using prestashop for about a week now but Ive been unsuccessful in obtaining a UPS Access key so i did some searching around and found some php scripts that do it so ive tried to adapt it to work with prestashop.Now i have no idea how to make a module so.... ive just hacked it into cart.php to test with im a .net developer php is alien to me but so far from reading other code and copy pasting ive slapped this together. $shipping_cost = 0; $cart = new Cart($this->id); $address = new Address(intval($cart->id_address_delivery)); $countries = Country::getCountries(intval($cookie->id_lang), true); $customerPostal = $address->postcode; foreach($countries AS $country) if($address->id_country == $country['id_country']) $customerCountry = $country['iso_code']; echo("Country: $customerCountry Postcode $customerPostal \n"); $rate = new Ups; $rate->upsProduct("STD"); // See upsProduct() function for codes $rate->origin("90210", "US"); // Use ISO country codes! <- lol at the test $rate->dest($customerPostal, $customerCountry); // Use ISO country codes! $rate->rate("RDP"); // See the rate() function for codes $rate->container("CP"); // See the container() function for codes $rate->weight($this->getTotalWeight()); $rate->rescom("RES"); // See the rescom() function for codes $shipping_cost = $rate->getQuote(); This works flawlessly and calculates the shipping by the weight perfectly (When the cart module is set to Ajax off) im getting this error when i set it to (Ajax on) ------------------------------------------------------------- TECHNICAL ERROR: unable to add the product. Details: Text status: parsererror -------------------------------------------------------------- If anyone is willing to help fix this or even help me turn this into a UPS Shipping Calculator Module? im willing to release it completely free i do not wish to make a profit on this i just want to get a simple... ups shipping cost estimator integrated with my cart and i hope this helps with many other peoples carts as from my forum searches many people want shipping estimations but the ups modules suck....why does it have to be so complected with api keys and usernames and blablabla when u can get the shipping rates from ups's api without an api key >.>Kind Regards,Rm2kdev Link to comment Share on other sites More sharing options...
rm2kdev Posted April 3, 2011 Author Share Posted April 3, 2011 All fixed and working.Please find attached my cart script.Barely tested this... but it appears to be working on my 1.4 shop perfectly please reply back with any optimizations and or fixes? this is my first script and i dont code php! so dont expect flawless coding @.@ its mostly copy pasted form various locations to work. 'Lego coding' Cart.php ups.php Link to comment Share on other sites More sharing options...
rm2kdev Posted April 5, 2011 Author Share Posted April 5, 2011 As i said before, id like to turn this into a module but i have no idea how, if anyone wants to assist that would be great! and some CC? or feedback anyone Update 1.0.1-If your shipping to the US it uses 'GND' otherwise it uses 'STD' -Checks if you are logged in you are it uses UPS shipping if not it uses $20 for first KG then + 3 for every kg after.Replace everything between the Begin Rm2kdev Changes and End Rm2kdev Changes with this for the updated functionality.Dont forget to replace 90210 with the postcode of where you are shipping from. /* BEGIN RM2KDEV CHANGES */ global $cookie; $shipping_cost = 0; $address = new Address((int)($this->id_address_delivery)); $countries = Country::getCountries(intval($cookie->id_lang), true); $customerPostal = $address->postcode; foreach($countries AS $country) if($address->id_country == $country['id_country']) $customerCountry = $country['iso_code']; $rate = new Ups; if($customerCountry == "US"){ $rate->upsProduct("GND"); // See upsProduct() function for codes }else{ $rate->upsProduct("STD"); // See upsProduct() function for codes } $rate->origin("90210", "US"); // Use ISO country codes! $rate->dest($customerPostal, $customerCountry); // Use ISO country codes! $rate->rate("RDP"); // See the rate() function for codes $rate->container("CP"); // See the container() function for codes $rate->weight($this->getTotalWeight() * 2.2); $rate->rescom("RES"); // See the rescom() function for codes if ($cookie->isLogged()) { $shipping_cost = $rate->getQuote(); $shipping_cost += 5;//Add $5 just incase we are diffrent to our supplier to cover expenses. } else { $shipping_cost = 20; $shipping_cost += ($this->getTotalWeight() - 1) * 3.0; } /* END RM2kDEV CHANGES */ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now