DevCimat Posted September 8, 2015 Share Posted September 8, 2015 Hello! I would like to know information about the process of downloads of virtual products, i want to modify the process, to insert information to Prestashop Database in a new table called ps_keyservice, but since it's my first time modifying and working with Prestashop, it's really dificult to achieve it. The use case works like this: 1.- The customer does a purchase of any virtual product. 2.- The system send the mail of download for the client. 3.- The customer clicks the URL of the virtual product. 4.- Before the download the system makes two operations: it validates if the product has been reached the limit of downloads if true, denies the download, if not, updates a table called ps_kerservice and put the reference of the order, the customer id, a date and a key varchar(45) (If this goes wrong, the system send an error message and ends the use case, if not, proceed to step 5). 5.- The system allows to download the virtual product and starts the download process. 6.- The use case ends. As you can see, my modification seems pretty easy, but I don't have idea where the download process starts, so I'm lost and stuck. Can anyone of you be kind to put me on rail? and before hand THANK YOU! Link to comment Share on other sites More sharing options...
bellini13 Posted September 8, 2015 Share Posted September 8, 2015 Everything works like you want it to except for step 4, since you want to add a custom processing step there. There is a controller named GetFIleController which is invoked in step 4. So you can alter or override this controller to add your custom process. There are no hooks in the controller, so you would not be able to use a module for this. Link to comment Share on other sites More sharing options...
DevCimat Posted September 8, 2015 Author Share Posted September 8, 2015 Thanks Bellini13, Since i want to override this controller, do I need to copy paste all code in the overrided controller and add my code? or Do I need to extend my class to use it properlly? Sorry for the dumb question, it's my first time working with prestashop and PHP. Greetings Link to comment Share on other sites More sharing options...
bellini13 Posted September 8, 2015 Share Posted September 8, 2015 Ideally, you want to override the controllers init function, instead of altering the Core controller. However you do not want to copy all of the core code into your override, since that means you would have to then maintain the entire code whenever you upgrade Prestashop. Since the GetFileController is likely to change in future releases. So you would want to perform your custom logic in your init function, and then when you are done, you would call parent::init so that the core coding would get executed. This means in your init function, you need to perform the validation for limit and your custom table update. class GetFileController extends GetFileControllerCore { public function init() { //perform any validation that is required. //Since this validation already occurs in the core code, it means that it would get executed twice //perform your table update //execute the parent function parent::init(); } } Again, this is the ideal world, but reality may prevent this based on your implementation needs. At this point, use the above as a template override and start playing with it and see if it fits your needs Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now