Jump to content

how to customize the selection carrier [SOLVED]


l.zuccarini

Recommended Posts

Dear guys,

let me explain my problem.

I have 2 carriers that have different price or each state, sometime the carrier A it's cheaper for a state, and sometime the carrier B it's cheaper for other state. Both carriers can reach all states. At the moment the selection carrier it's based on cheaper. All works fine. I'd like leave to my customer the possibility to purchase my product without delivery. Therefore I created one more carrier named "pick-up in my store" that it's free. I added this last carrier to all states, but now, automatically all purchasing has the "free shipping" carrier, and only before complete order, the user can know the delivery cost.

Now I wanna modify the code of my prestashop in order to exclude the carrier "pick-up in my store" during the carrier calculation.

Have someone some idea, some suggestion? wich file I have to modify? I have medium experience in php, sql, html languages...

 

I know that one way should be to assign only the cheaper carrier for each state (about 120 states and every state has 11 weight delimeters.

Therofer I prefer not keep this way, because in case of changing pricing or carrier company I should have many data to manage.

 

 

 

Thank you in advance.

Edited by l.zuccarini (see edit history)
Link to comment
Share on other sites

Hi guys, I tried to modify the file /storename/classes/Carrier.php

 

public static function getCarriersForOrder($id_zone, $groups = null, $cart = null)

 

I am not sure if it's the right function to modify.

Anyway let me explain my idea...

 

Ordering the carrier by prices, the first carrier choosen it's the "pick-up in my store".

Near the line 590

  if (Configuration::get('PS_CARRIER_DEFAULT_ORDER') == Carrier::SORT_BY_ASC)
   array_multisort($prices, SORT_ASC, SORT_NUMERIC, $results_array);
  else
   array_multisort($prices, SORT_DESC, SORT_NUMERIC, $results_array);
 }

 $temp1 = array_shift($results_array); //Remove the first carrier (free shipping) on $result_array
 $results_array[] = $temp1;  //Add at the end the most cheaper carrier (free shipping).
 return $results_array;
}

 

Where I am in wrong?

Link to comment
Share on other sites

Solved... /classes/Cart.php

 

code modify from:

// Foreach carriers of the package, calculate his price, check if it the best price, position and grade
foreach ($package['carrier_list'] as $id_carrier)
{
 if (!isset($carriers_instance[$id_carrier]))
  $carriers_instance[$id_carrier] = new Carrier($id_carrier);
 $price_with_tax = $this->getPackageShippingCost($id_carrier, true, $country, $package['product_list']);
 $price_without_tax = $this->getPackageShippingCost($id_carrier, false, $country, $package['product_list']);
 if (is_null($best_price) || $price_with_tax < $best_price)
 {
  $best_price = $price_with_tax;
  $best_price_carrier = $id_carrier;
 }
 $carriers_price[$id_address][$id_package][$id_carrier] = array(
  'without_tax' => $price_without_tax,
  'with_tax' => $price_with_tax);

 

 

to:

 

// Foreach carriers of the package, calculate his price, check if it the best price, position and grade
foreach ($package['carrier_list'] as $id_carrier)
{
 if (!isset($carriers_instance[$id_carrier]))
  $carriers_instance[$id_carrier] = new Carrier($id_carrier);
 $price_with_tax = $this->getPackageShippingCost($id_carrier, true, $country, $package['product_list']);
 $price_without_tax = $this->getPackageShippingCost($id_carrier, false, $country, $package['product_list']);
 if (is_null($best_price) || $price_with_tax < $best_price)
 {
  $best_price = $price_with_tax;
  $best_price_carrier = $id_carrier;
  if ($best_price == 0)   //if the price it's 0, means carrier "pick-up in store"
   $best_price = 1000000;  //Set the $best_price to a very high value in order to be sure that next carrier will be cheaper
 }

 $carriers_price[$id_address][$id_package][$id_carrier] = array(
  'without_tax' => $price_without_tax,
  'with_tax' => $price_with_tax);

 

It's not a elegant solution, but it's a solution! :)

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

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...