Everseeker Posted February 7, 2013 Share Posted February 7, 2013 Hello I've been struggling for a while trying to set the default carrier based on language. Prestashop 1.4.9 Problem: A new costumer from any part of the world visits shop and always gets the shipping cost calculated based on default carrier. After login price shows accordingly. Sugestion: Connect the language_id chosen to a carrier_id witch can be overriden after login/registration What i have so far: I connected my language to currency in classes/tools.php /** * Set cookie id_lang */ static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //usa $cookie->id_currency = 2; //change the currency too, the currency that has the id 2 self::setCurrency(); break; case 2: //franca $cookie->id_currency = 1; self::setCurrency(); break; case 3: // espanha $cookie->id_currency = 1; self::setCurrency(); break; case 4: // alemanha $cookie->id_currency = 1; self::setCurrency(); break; case 5: //Italia $cookie->id_currency = 1; self::setCurrency(); break; case 10: // wordwide $cookie->id_currency = 2; self::setCurrency(); break; } } } I've noticed that the default carrier is used when none is specified in classes/cart.php function getOrderShippingCost($id_carrier = NULL, $useTax = true) { global $defaultCountry; if ($this->isVirtualCart()) return 0; // Checking discounts in cart $products = $this->getProducts(); $discounts = $this->getDiscounts(true); if ($discounts) foreach ($discounts as $id_discount) if ($id_discount['id_discount_type'] == 3) { if ($id_discount['minimal'] > 0) { $total_cart = 0; $categories = Discount::getCategories((int)$id_discount['id_discount']); if (sizeof($categories)) foreach ($products as $product) if (Product::idIsOnCategoryId((int)$product['id_product'], $categories)) $total_cart += $product['total_wt']; if ($total_cart >= $id_discount['minimal']) return 0; } else return 0; } // Order total in default currency without fees $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if ($order_total <= 0 AND !(int)(self::getNbProducts($this->id))) return $shipping_cost; // Get id zone if (isset($this->id_address_delivery) AND $this->id_address_delivery AND Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) $id_zone = Address::getZoneById((int)($this->id_address_delivery)); else { // This method can be called from the backend, and $defaultCountry won't be defined if (!Validate::isLoadedObject($defaultCountry)) $defaultCountry = new Country(_PS_COUNTRY_DEFAULT_, _PS_LANG_DEFAULT_); $id_zone = (int)$defaultCountry->id_zone; } // If no carrier, select default one if (!$id_carrier) $id_carrier = $this->id_carrier; if ($id_carrier && !$this->isCarrierInRange($id_carrier, $id_zone)) $id_carrier = ''; if (empty($id_carrier) && $this->isCarrierInRange(Configuration::get('PS_CARRIER_DEFAULT'), $id_zone)) $id_carrier = (int)(Configuration::get('PS_CARRIER_DEFAULT')); if (empty($id_carrier)) { if ((int)($this->id_customer)) { $customer = new Customer((int)($this->id_customer)); $result = Carrier::getCarriers((int)(_PS_LANG_DEFAULT_), true, false, (int)($id_zone), $customer->getGroups()); unset($customer); } ... Question Is it possible to connect the language_id to a carrier_id and pass it as a cookie as its done with currency? Here is what i have so far but doesn't works /** * Set cookie id_lang */ static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; $cookie->id_carrier = $id_carrier; switch($id_lang) { case 1: //usa $cookie->id_currency = 2; //change the currency too, the currency that has the id 2 $carrier->id_carrier = 15; self::setCurrency(); break; case 2: //france $cookie->id_currency = 1; $carrier->id_carrier = 15; self::setCurrency(); break; case 3: // espana $cookie->id_currency = 1; $carrier->id_carrier = 21; self::setCurrency(); break; case 4: // germany $cookie->id_currency = 1; $carrier->id_carrier = 21; self::setCurrency(); break; case 5: //Italy $cookie->id_currency = 1; $carrier->id_carrier = 21; self::setCurrency(); break; case 6: //Portugal $cookie->id_currency = 1; $carrier->id_carrier = 15; self::setCurrency(); break; } } } My hint is i miss something to be able to pass carrier_id as a cookie. Any help would be great Link to comment Share on other sites More sharing options...
El Patron Posted February 7, 2013 Share Posted February 7, 2013 (edited) deleted..my geo targeting pro supports all 1.4 and 1.5 except 1.4.9... Edited February 7, 2013 by elpatron (see edit history) Link to comment Share on other sites More sharing options...
dformica Posted February 7, 2013 Share Posted February 7, 2013 (edited) deleted..my geo targeting pro supports all 1.4 and 1.5 except 1.4.9... @elpatron Do you know how I could set detault carriers to all my products? Currently they don't have any carrier assigned. I really can't go one by one product and assign carriers, it would take me forever. Thanks! Edited February 7, 2013 by dformica (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted February 7, 2013 Share Posted February 7, 2013 do you assign carries by country? try this fallback you code...save it put back native.... turn on the prestashop geolocation....follow the installation instructions...the problem will be that you will not be able to test from different IP's unless you patch the geolocation routine in FrontContoller.php, see where it gets the realip address and subsitue that with an ip from the country you want to test from. You can do this on localhost..on a test machine... Link to comment Share on other sites More sharing options...
El Patron Posted February 7, 2013 Share Posted February 7, 2013 yes, you can set one default shipping method for all products...I'm no expert at shipping as I only sell virtual goods and have set it up for a couple folks... the key is to use native prestashop's support for catalog by country, the problem is unlogged visitors get the default shop country...what you want to try an accomplish, with geolocation, is the setting of the vistiors cookie by their IP... we never could get our geo targeting pro to work on 1.4.9...and I tried...otherwise this would be a snap...assuming you use the native prestashop support catalog by country support.... Link to comment Share on other sites More sharing options...
dformica Posted February 7, 2013 Share Posted February 7, 2013 do you assign carries by country? try this fallback you code...save it put back native.... turn on the prestashop geolocation....follow the installation instructions...the problem will be that you will not be able to test from different IP's unless you patch the geolocation routine in FrontContoller.php, see where it gets the realip address and subsitue that with an ip from the country you want to test from. You can do this on localhost..on a test machine... I have my carriers from USPS assigned to all countries, all enabled. I add one product to the shopping cart, then when I reach step#4 Shipping, I get: There is 1 error There are no carriers that deliver to the address you selected. <<back So I assigned some carriers to one of my products to test and they show up. So what are my options to assign carriers to all my products? Link to comment Share on other sites More sharing options...
El Patron Posted February 7, 2013 Share Posted February 7, 2013 I have never seen where a product was assigned a carrier (again no expert)...the carrier is assigned to zone...I may be confusing the situation more than I am helping... and I have no clue why you are trying to assign a carried by language...if I am in the US but am using your site in Spanish, you would want the shipping for US, not based on Spanish. Link to comment Share on other sites More sharing options...
dformica Posted February 7, 2013 Share Posted February 7, 2013 @elpatron You are correct, each carrier has zones assigned. I assigned all zones to make sure It wasn't a geolocation glitch. If you go to a product then shipping. There you get to assign carriers to each product. In my case I installed the USPS module after I loaded all my product. So now, none of my products have a carrier assigned. How do I assign at least a default carrier to all my products? Or site-wide default carrier? Link to comment Share on other sites More sharing options...
El Patron Posted February 7, 2013 Share Posted February 7, 2013 I'm sorry but I do not see a product then shipping...so you lose me when you tell me you assign a carrier to a product...sorry I need a nap...and stepped in it with this thread..jajajaja where we are now is a lot different than where we started out...i.e. assign a carrier by language....etc... maybe think about a brand new thread...without posting code...that I don't think you need... I go for a nap...check back later Link to comment Share on other sites More sharing options...
dformica Posted February 7, 2013 Share Posted February 7, 2013 @elpatron Thanks for trying to help. 1 Link to comment Share on other sites More sharing options...
dformica Posted February 7, 2013 Share Posted February 7, 2013 I found another thread that will fit better my topic of discussion http://www.prestashop.com/forums/topic/213971-there-are-no-carriers-that-deliver-to-the-address-you-selected/page__hl__if+no+carrier+selected%2C+all+carriers+could+be+used+to+ship+this+product__fromsearch__1 Thanks. Link to comment Share on other sites More sharing options...
Everseeker Posted February 8, 2013 Author Share Posted February 8, 2013 Back to topic then Is there anyone who could point me in the right direction please? Please? 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