PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] How to programmatically add extra fee in Prestashop?

 October 27, 2022     prestashop, prestashop-1.6, prestashop-1.7     No comments   

Issue

wonderful community. I need to add an extra fee to the orders in prestashop. I have developed a custom payment module that's working as expected. I just can't find any information on how to add this extra fee (that's configurable in the payment module itself), to the cart, invoice and wherever is needed. All the information I have found, the answers link to buy a module on the marketplace. I can't afford to buy it. So, I'll appreciate if you can shed some light on this issue.

I'm using PS 1.6 and 1.7.x.


Solution

The best way to achieve would be to:

  1. Add a new product to your Catalog, called 'Extra fee'
  2. Select 'Nowhere' for its visibility, and set a price matching the extra fee you are trying to charge
  3. Override the getOrderTotal() method in the Cart class, to add a new condition stating that if the specific payment module has been selected, the 'Extra fee' product should be automatically added to the cart (using $this->updateQty(1, $id_product_extra_fee);)
  4. Make sure to handle the case where the buyer decides to switch to another payment method (then remove this product from their cart)

This will automatically populate the invoice, the confirmation e-mail, the order detail in the admin panel, etc.



Answered By - Bruno Leveque
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing