Jump to content

per category shipping cost


bobster001

Recommended Posts

Hi,

 

I am looking for a way to have a per category shipping cost?

 

for example:

 

I have category shoes. If a customer adds any product from category shoes an extra shipping cost should be added to the shipping total. However it must add it only once. So no matter how many items of category shoes are added the category shipping cost are added only once.

 

So far my searches turned up nothing of the sort. Any help appreciated

 

Thanks

Link to comment
Share on other sites

To make sure I understand your question, for EVERY category a customer chooses one or more products there must be added some fixed 'per category' price, yes? So if you choose x products from Cat C1, and y products from Category C2, you need to add 1xC1 carrier price + 1xC2 carrier price, right?

 

How many Categories do we talk about?

 

What PrestaShop version do you use?

Link to comment
Share on other sites

Thanks for the reply.

 

Yes you understand it correctly in your first reply.

 

Currently it will be only for 1 category and the products in there is not associated with other categories. However there are sub categories. The delivery charge should be for any product in the main category.

 

I am currently using prestashop 1.4.5.1 but will be upgrading to 1.5 next month.

Link to comment
Share on other sites

  • 1 year later...

Hi devtex,

 

If you have a fixed category you want to add a shipping cost for, (or fixed categories, but you want the shipping for this group of categories one time only), you can do something like this: (Example code of PrestaShop 1.6.0.8)

 

First let's add some field where we can add the shipping cost. This is easy to add to the shipping configuration screen:

 

Edit the file: controllers/admin/AdminShippingController.php  (Make backup!!!, or even better, make an override of the controller. See developers guide how to do this, or search the forum...)

- http://doc.prestashop.com/display/PS15/Diving+into+PrestaShop+Core+development#DivingintoPrestaShopCoredevelopment-Overridingacontroller

http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingacontroller

 

 

In this file, go to the function __construct():

Here you will find the code below:

...
				'fields' =>	array(
					'PS_SHIPPING_HANDLING' => array(
						'title' => $this->l('Handling charges'),
						'suffix' => $this->context->currency->getSign().' '.$this->l('(tax excl.)'),
						'cast' => 'floatval',
						'type' => 'text',
						'validation' => 'isPrice'),
/* ADD THIS CODE, SHOW BELOW*/
					'PS_SHIPPING_HANDLING_FOR_CATEGORY' => array(
						'title' => $this->l('Category specific handling charges'),
						'suffix' => $this->context->currency->getSign().' '.$this->l('(tax excl.)'),
						'cast' => 'floatval',
						'type' => 'text',
						'validation' => 'isPrice'),

You see, I added a field "Category specific handling charges", which value will be stored in the ps_configuration table with the name 'PS_SHIPPING_HANDLING_FOR_CATEGORY'

 

save the file and go to the shipping->configuration screen, and you will see the field, where you can add a number, just like the general 'shipping charges'.

 

 

To make it useful, we need to add these charges to the shipping costs. This function is defined in /classes/Cart.php.

Again, make a backup!!!, or better, make an override:

http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingaclass

 

 

In this file, go to function:

public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 
and go to the part where they add the fixed shipping charge (search for PS_SHIPPING_HANDLING)
First get the value from ps_configuration:
 
$configuration = Configuration::getMultiple(array(
    'PS_SHIPPING_FREE_PRICE',
    'PS_SHIPPING_HANDLING',
    'PS_SHIPPING_HANDLING_FOR_CATEGORY',   //  <-- add this line
    'PS_SHIPPING_METHOD',
    'PS_SHIPPING_FREE_WEIGHT'
  ));
 
then a little lower, you see this code (add red code):
 
// Adding handling charges
  if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling)
    $shipping_cost += (float)$configuration['PS_SHIPPING_HANDLING'];
 
// Additional Shipping Cost per product
 
  $CatCostAdded = false;  // We want to add category shipping costs only once
  $CatShippingCategories[] = array('id_category' => 3); // Fixed category to add costs for
  $CatShippingCategories[] = array('id_category' => 4); // Optional fixed category to add costs for,
                                                        // if you have a group of categories.
                                                        // add more if needed
 
  foreach ($products as $product) {     // <- don't forget this little bracket...
    if (!$product['is_virtual'])
      $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
 
    if (!$CatCostAdded && isset($configuration['PS_SHIPPING_HANDLING_FOR_CATEGORY'])) {
      if (Product::idIsOnCategoryId($product['id_product'], $CatShippingCategories)) {
        $shipping_cost += (float)$configuration['PS_SHIPPING_HANDLING_FOR_CATEGORY'];
        $CatCostAdded = true;  // !!!Pas, Cat. found, only add costs once
      }
    }
 
  }
 
 

Save and take a few products, one or more of the category that you added in your shopping cart. then go to the cart summary and see if it works.

 

 

Hope this helps, let me know.

pascal.

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Unfortunatelly, doesnt work for me. Did everything as you wrote, but it adds me regular shipping price and also specific amount for category shipping. So its regular + specific together, which i didnt want. I have PS version 1.6.0.9, is it possible, that is only for 1.6.0.8?

 

I'm really not into php much, but using this variable $CatCostAdded seems a little bit sketchy. But as i said, Im newbie to PHP

Edited by vorisekmartin (see edit history)
Link to comment
Share on other sites

Hi martin,

 

the result you describe is indeed the result the previous poster wanted, so that is what it currently does. Normal and additional per category.

 

Can you describe what you exactly need?

- if only products that are NOT in the specific category, does the normal shipping price apply?

- How to handle the normal shipping price when a product in the specified category is added to the order? (i.e. mixed products in and outside specific category)

- How to handle normal shipping price when ONLY products from the specific category is in the order?

 

- how are your products linked to categories etc/ (only one category per product or more? If more, should it add the specific category shipping price only once or for every category in the group?

 

please let me know in detail, then I can try to find a solution,

pascal.

 

 

 

P.S. the $CatCostAdded variable is only a boolean value that checks if the costs are already added to the shipping price or not, to not add them more than once. (For your info.)

Edited by PascalVG
Added PS (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi,

I need some help with it too... Ver 1.6.09

I need to add $2.5 per day  - - each day is a category , and add it no more than once a day for all the products ordered to that day.

so the Cart will have the products for each day of the week, and the shipping will add $x for each day.

Thanks,

Link to comment
Share on other sites

  • 10 months later...

Hi devtex,

 

If you have a fixed category you want to add a shipping cost for, (or fixed categories, but you want the shipping for this group of categories one time only), you can do something like this: (Example code of PrestaShop 1.6.0.8)

 

First let's add some field where we can add the shipping cost. This is easy to add to the shipping configuration screen:

 

Edit the file: controllers/admin/AdminShippingController.php  (Make backup!!!, or even better, make an override of the controller. See developers guide how to do this, or search the forum...)

- http://doc.prestashop.com/display/PS15/Diving+into+PrestaShop+Core+development#DivingintoPrestaShopCoredevelopment-Overridingacontroller

http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingacontroller

 

 

In this file, go to the function __construct():

Here you will find the code below:

...
				'fields' =>	array(
					'PS_SHIPPING_HANDLING' => array(
						'title' => $this->l('Handling charges'),
						'suffix' => $this->context->currency->getSign().' '.$this->l('(tax excl.)'),
						'cast' => 'floatval',
						'type' => 'text',
						'validation' => 'isPrice'),
/* ADD THIS CODE, SHOW BELOW*/
					'PS_SHIPPING_HANDLING_FOR_CATEGORY' => array(
						'title' => $this->l('Category specific handling charges'),
						'suffix' => $this->context->currency->getSign().' '.$this->l('(tax excl.)'),
						'cast' => 'floatval',
						'type' => 'text',
						'validation' => 'isPrice'),

You see, I added a field "Category specific handling charges", which value will be stored in the ps_configuration table with the name 'PS_SHIPPING_HANDLING_FOR_CATEGORY'

 

save the file and go to the shipping->configuration screen, and you will see the field, where you can add a number, just like the general 'shipping charges'.

 

 

To make it useful, we need to add these charges to the shipping costs. This function is defined in /classes/Cart.php.

Again, make a backup!!!, or better, make an override:

http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingaclass

 

 

In this file, go to function:

public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 
and go to the part where they add the fixed shipping charge (search for PS_SHIPPING_HANDLING)
First get the value from ps_configuration:
 
$configuration = Configuration::getMultiple(array(
    'PS_SHIPPING_FREE_PRICE',
    'PS_SHIPPING_HANDLING',
    'PS_SHIPPING_HANDLING_FOR_CATEGORY',   //  <-- add this line
    'PS_SHIPPING_METHOD',
    'PS_SHIPPING_FREE_WEIGHT'
  ));
 
then a little lower, you see this code (add red code):
 
// Adding handling charges
  if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling)
    $shipping_cost += (float)$configuration['PS_SHIPPING_HANDLING'];
 
// Additional Shipping Cost per product
 
  $CatCostAdded = false;  // We want to add category shipping costs only once
  $CatShippingCategories[] = array('id_category' => 3); // Fixed category to add costs for
  $CatShippingCategories[] = array('id_category' => 4); // Optional fixed category to add costs for,
                                                        // if you have a group of categories.
                                                        // add more if needed
 
  foreach ($products as $product) {     // <- don't forget this little bracket...
    if (!$product['is_virtual'])
      $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
 
    if (!$CatCostAdded && isset($configuration['PS_SHIPPING_HANDLING_FOR_CATEGORY'])) {
      if (Product::idIsOnCategoryId($product['id_product'], $CatShippingCategories)) {
        $shipping_cost += (float)$configuration['PS_SHIPPING_HANDLING_FOR_CATEGORY'];
        $CatCostAdded = true;  // !!!Pas, Cat. found, only add costs once
      }
    }
 
  }
 
 

Save and take a few products, one or more of the category that you added in your shopping cart. then go to the cart summary and see if it works.

 

 

Hope this helps, let me know.

pascal.

 

Thanks,

It works great..

Link to comment
Share on other sites

  • 3 months later...

hello and thanks for this, which works great...

i tried those modifications, i couldn't get it on override, but it works well... but i need something different...

i'm trying using this to set shipping_cost=0, to and only to, the products of this categories, if the cart has products from other categories then it'll have a shipping_cost.

 

any idea how can i get it?

 

thanks.

 

(i'm using PS1.6.0.14 upgraded to PS1.6.1.4)

Edited by Pedro Pinto (see edit history)
Link to comment
Share on other sites

Well there is no need for code adaptations.

 

On the product you can choose the shipping per each product. If you added several shipping companies to your back-office, than you can choose on the product back-office site the ones the customer can choose. If it is only one shipper, than you choose only this one.

 

post-741527-0-35915400-1454663504_thumb.jpg

 

 

Link to comment
Share on other sites

it doesnt work.

i had two carrier options:

 - get on shop (which is free)

 - normal shipping (9€)

i got those for all my products. if i had one third option (free shipping) and i make it associated with some products (the only one available for those products) (and the others products to the two others option), when i add one product with shipping cost (9) and other without shipping cost i get free shipping cost on the total, but i dont want that.

Link to comment
Share on other sites

it doesnt work.

i had two carrier options:

 - get on shop (which is free)

 - normal shipping (9€)

i got those for all my products. if i had one third option (free shipping) and i make it associated with some products (the only one available for those products) (and the others products to the two others option), when i add one product with shipping cost (9) and other without shipping cost i get free shipping cost on the total, but i dont want that.

It is a configuration problem on your carriers. You should configure on the carrier, tab 2, out of range behaviour=disable carrier.

Link to comment
Share on other sites

  • 1 month later...

What if I just want to disable a particular courier to particular products (category). Is that possible?

 

By default, I don't assign any couriers to a particular product, so customer can select any courier they want.

 

For example:

There are couriers A, B, and C.

I have 1000 products (not assigned to any courier so all the couriers are enabled by default), but only 100 products that can be delivered through courier C.

 

The "not so efficient" solution is assigning all of the products to a particular courier & not selecting C in some products in order to disable it.

 

Is there any easier solution for this?

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Same problem here! In fact, I have over 1000 products and 2 carrieres that are usefull depending on the category the product belongs... need to know how to do it in an efficient solution... 

What if I just want to disable a particular courier to particular products (category). Is that possible?

 

By default, I don't assign any couriers to a particular product, so customer can select any courier they want.

 

For example:

There are couriers A, B, and C.

I have 1000 products (not assigned to any courier so all the couriers are enabled by default), but only 100 products that can be delivered through courier C.

 

The "not so efficient" solution is assigning all of the products to a particular courier & not selecting C in some products in order to disable it.

 

Is there any easier solution for this?

Link to comment
Share on other sites

  • 1 year later...

I need to install the following shipping rules:

Product at regular price (Free Shipping)

Product in sales (in category SALES)

    Quebec (10$)

    Canada (20$)

    USA (30$)

   EUROPE (50$)

I'm looking for a module or a programmer that can do it.    I just contacted a programmer in India who's charging me 500 USD to do it...  Very expensive.... Help people! 

[email protected]

Link to comment
Share on other sites

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