Jump to content

Creating new methods in module controller


TommyS

Recommended Posts

Hi, guys!
I need to add new functionality to 'ps_emailsubscription' module.
When the 'register for newsletter' button is clicked two things have to happen:

  • a new one-use-only 5% discount voucher has to be created and assigned only to that specific email, even if the user is not registered (Prestashop only allows to assign vouchers to registered users, so I added the 'email_user_unregistered' column to the 'ps_cart_rule' table in the database),
  • the modal box appears (I've already created it in JS) and displays the voucher.


Of course then I'd have to write the code that checks whether the correct user is using the correct email, but that's a problem for another time.

I've found the functions that can help me accomplish my task:

  • modules\ps_emailsubscription\ps_emailsubscription.php --> getSubscribers()
  • classes\CartRule.php --> add()
  • and others from classes\db


But to be honest, I'm a Prestashop newbie. I know that I should create a new function in the module controller that calls methods from classes mentioned above, but I have no clue how to do this properly (how to link the classes, call these functions, where and how to call the function on click etc.).

I really could use some help guys. If I see how it's done now, then I shouldn't have any more problems in the future. You know how complicated a Prestashop template can be.

Thanks in advance,
Thomas

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