Jump to content
monstermaker

Getting information from custom fields in front end

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More