Prestashop shipping cost by state

2019-05-22 21:08发布

Is there by any chance a way to set shipping cost by state in a carrier in prestashop?

i.e. let's say i want a different shipping cost to send in Alabama than in Alaska with the same carrier

Thanks

2条回答
Emotional °昔
2楼-- · 2019-05-22 21:43

There are a couple ways of doing this. You can purchase an external module, such as this one, or create an override like so:

1) Copy "classes/Address.php" to "override/classes/Address.php".

2) In line 28 change class name from AddressCore to Address

3) Before function getZoneById, paste this new function

/**
* Return postcode of address
*
* @param $id_address Address id
* @return integer postcode
*/
public static function getPostcodeByAddress($id_address){
    $row = Db::getInstance()->getRow('
    SELECT `postcode`
    FROM '._DB_PREFIX_.'address a
    WHERE a.`id_address` = '.(int)($id_address));
    return $row['postcode'];
}

4) Add before first line of function getZoneById this:

$postcode=self::getPostcodeByAddress($id_address); 

if(in_array($postcode,array(your list of postcodes))){
    return id-of-your-zone;
}
查看更多
爷、活的狠高调
3楼-- · 2019-05-22 21:49

This worked for me:

  1. Go to Localization->Zones
  2. Created new different Zones according to State. eg. Zone name = "NSW"
  3. Go to Localization->States
  4. Choose state and change it's new zone. eg. "New South Wales" now changed into "NSW" zone.
  5. Go to Shipping->Carriers
  6. Click on "Edit" on shipping method.
  7. Click on "Shipping Locations and Costs"
  8. Now change shipping cost by each zone which has now related states.
查看更多
登录 后发表回答