Jump to content
mrhaha

[SOLVED] Per Item Shipping

Recommended Posts

I just fond Prestashop last week. it is really a good product! Easy to use & Fast!

after i uploaded all my products, i only discovered that the shipping charges function only has By Price/ By Weight. :(

What i need is set by Item. each item has it own shipping fee.

i tried to google on the internet, i still not able to find the solution.

anyone hav this Shipping Fee Per Item?

pls help me! my business is hanging now!


thanks in advance!!!!!

Share this post


Link to post
Share on other sites

The easiest way I know to do this is to enter the per-item shipping cost in the weight field of each product, then modify classes/Carrier.php and change:

   /**
    * Get delivery prices for a given order
    *
    * @param floatval $totalWeight Order total weight
    * @param integer $id_zone Zone id (for customer delivery address)
    * @return float Delivery price
    */
   public function getDeliveryPriceByWeight($totalWeight, $id_zone)
   {
       if (isset(self::$priceByWeight[$this->id]))
           return self::$priceByWeight[$this->id];
       $result = Db::getInstance()->getRow('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON (d.`id_range_weight` = w.`id_range_weight`)
       WHERE d.`id_zone` = '.intval($id_zone).'
       AND '.floatval($totalWeight).' <= w.`delimiter2`
       AND d.`id_carrier` = '.intval($this->id).'
       ORDER BY w.`delimiter1` ASC');
       if (!isset($result['price']))
           return $this->getMaxDeliveryPriceByWeight($id_zone);
       return $result['price'];
   }

   static public function checkDeliveryPriceByWeight($id_carrier, $totalWeight, $id_zone)
   {
       $result = Db::getInstance()->getRow('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
       WHERE d.`id_zone` = '.intval($id_zone).'
       AND '.floatval($totalWeight).' <= w.`delimiter2`
       AND d.`id_carrier` = '.intval($id_carrier).'
       ORDER BY w.`delimiter1` ASC');
       if (!isset($result['price']))
           return false;
       return true;
   }

   public function getMaxDeliveryPriceByWeight($id_zone)
   {
       $result = Db::getInstance()->ExecuteS('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
       WHERE d.`id_zone` = '.intval($id_zone).'
       AND d.`id_carrier` = '.intval($this->id).'
       ORDER BY w.`delimiter2` DESC LIMIT 1');
       if (!isset($result[0]['price']))
           return false;
       return $result[0]['price'];
   }



to:

   /**
    * Get delivery prices for a given order
    *
    * @param floatval $totalWeight Order total weight
    * @param integer $id_zone Zone id (for customer delivery address)
    * @return float Delivery price
    */
   public function getDeliveryPriceByWeight($totalWeight, $id_zone)
   {
/*        if (isset(self::$priceByWeight[$this->id]))
           return self::$priceByWeight[$this->id];
       $result = Db::getInstance()->getRow('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON (d.`id_range_weight` = w.`id_range_weight`)
       WHERE d.`id_zone` = '.intval($id_zone).'
       AND '.floatval($totalWeight).' <= w.`delimiter2`
       AND d.`id_carrier` = '.intval($this->id).'
       ORDER BY w.`delimiter1` ASC');
       if (!isset($result['price']))
           return $this->getMaxDeliveryPriceByWeight($id_zone);
       return $result['price'];
*/
       return $totalWeight;
   }

   static public function checkDeliveryPriceByWeight($id_carrier, $totalWeight, $id_zone)
   {
/*        $result = Db::getInstance()->getRow('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
       WHERE d.`id_zone` = '.intval($id_zone).'
       AND '.floatval($totalWeight).' <= w.`delimiter2`
       AND d.`id_carrier` = '.intval($id_carrier).'
       ORDER BY w.`delimiter1` ASC');
       if (!isset($result['price']))
           return false;
*/        return true;
   }

   public function getMaxDeliveryPriceByWeight($id_zone)
   {
/*        $result = Db::getInstance()->ExecuteS('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
       WHERE d.`id_zone` = '.intval($id_zone).'
       AND d.`id_carrier` = '.intval($this->id).'
       ORDER BY w.`delimiter2` DESC LIMIT 1');
       if (!isset($result[0]['price']))
           return false;
       return $result[0]['price'];
*/        return 1000000;
   }



This will make the shipping cost the total weight of the cart. Make sure that on the Shipping tab, you have Billing set to "According to total weight". You can also go to Tools > Translations, select Back Office Translations, click a Flag, then change every instance of "Weight" to "Shipping cost" to make it more obvious in the Back Office that weight is now shipping cost.

Note that this will cause all carriers to have the same shipping prices. If you will need different carriers to have different per-item shipping costs, it won't work. I'll add a Shipping module to my list of modules to do in the future.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Rocky

Thanks for this.
Is there any way to include a 'Pick Up At Store' option on the 'Shipping' step page which would remove the 'per item shipping charge'?

Share this post


Link to post
Share on other sites

I don't think you can do that, since the getDeliveryPriceByWeight function doesn't include an $id_carrier parameter.

Share this post


Link to post
Share on other sites

You can give each of your items same weight and charge shipping by weight in increments in admin panel.

Share this post


Link to post
Share on other sites

Hi Rocky

I need the Weight Property for something else when exporting the Invoices.

Is there a way to get the value from another texbox from the product page. For Example lets say LOCATION ?

Share this post


Link to post
Share on other sites

hi

thanks for this, what is the line it starts on in carrier.php, ive tried looking but theres lines in there that look the same to me, also what line will it round about finish.....just so i dont mess anything up

Thanks

Andy.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More