monstermaker Posted February 19, 2019 Share Posted February 19, 2019 Hi I am developing a module that provides a way of collecting information for an optical prescription for a glasses site. I did this many years ago in an old version of PrestaShop before it moved to MVC architecture. I am working on version 1.7.4.2 but I am having trouble passing information from one file to another. My approach is this: 1. I have created a new module with a controller that creates a new table in the database to hold the information, creates/registers a displayPrescription hook as well as using the ActionCartSave hook. 2. I have created a template file to display the new form fields, using the new hook, on the product page. 3. I have used the ActionCartSave hook to write the database field values. I assumed that I could then add the "$myvar = Tools::getValue('Myfield');" line in the ActionCartSave hook code to get the field values and assign to a variable to pass to the database function when the 'add to cart' button is pressed. This does not work though. Here is my hook info: public function hookActionCartSave($params) { $rightSphere = (int)Tools::getValue('rightSphere'); Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'prescription` (`id`, `cart_id`, `user_id`, `image_id`, `purpose`, `rightSphere`, `rightCylinder`, `rightAxis`, `leftSphere`, `leftCylinder`, `leftAxis`, `rightAdd`, `leftAdd`, `prism`, `base`, `pupilaryDistance`, `lenseType`, `package`) VALUES (NULL, NULL, NULL, NULL, "Computer",'. $rightSphere.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "0", NULL, NULL, NULL);'); } What I want to do is pass each of the fields from the form on the template to a variable. Then I can use that to add to the database. If you are wondering why I don't use the built in attribute/customisation fields, it is because it creates 1000's of variations and causes 500 errors. Has anybody any idea how to solve this? What am I missing? Do I need to add a save button instead, like on the customisation options? If a save button is required, where will its action go? I am fine with PHP and smarty, but new to MVC. Thanks for your help. Link to comment Share on other sites More sharing options...
Geimsdin Posted July 27, 2019 Share Posted July 27, 2019 Hi monstermaker, I'm pretty much stucked in the same situation, did you finally solve it? Can you please share some info? Thanks a lot, Simone Link to comment Share on other sites More sharing options...
Geimsdin Posted July 28, 2019 Share Posted July 28, 2019 @andiyatsi I did solve it executing an ajax call that submits the form again to a php file I created. In this case all the input inside the form are posted by tha call. I used Prestashop.on('updatecart', function()... Hope it helps, Simone 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