0

by using commerce customisable products module, I created a custom product line item type to which I added a text field (Machine name field_license_details). By following this excellent video tutorial http://commerceguys.com/blog/commerce-module-tuesday-commerce-customizable-products-screencast

I was able to create a node/page which include the text field I mentioned before. However, what I find impossible to do, is to get the value that the user entered to that field. For example, when the user has entered something in the text field and clicks the add to cart button, I want the text he typed , to be 'placed' to a variable so i can do whatever i like with it for example display it back to the user or write it down to a file etc. I understand that in order to achieve that I would need to write my own module , but I am not sure which hook I should implement, and how exactly extract the string to a variable. As you probably already understood by the nature of the question ,I am just getting started on drupal, so any suggestions would be more than welcome. Thanks in advance PS I am using drupal 7.22 (the latest stable version and I have installed the drupal commerce module, the commerce file and commerce customisable products modules.

  • you can use view module to get that variable. – Ali Nouman Jul 9 '13 at 9:47
  • @Human love Thanks for the suggestion. I will give it a go – user1479847 Jul 9 '13 at 10:08
0

I ended up doing the following :

    function my_Module_form_alter(&$form, &$form_state, $form_id){
           if ($form_id == 'commerce_cart_add_to_cart_form_12'){
                  dpm($form, 'cart form'); //to use with deve module   
                  $form['#submit'][]=('my_Module_commerce_add_to_cart_form_12_submit');
                  }
            } 

       function my_Module_commerce_add_to_cart_form_12_submit($form, &$form_state){

             $user_text_temp=$form_state['values']['line_item_fields']['field_license_details'][LANGUAGE_NONE][0]['value'];
             dpm($user_text_temp, 'extract value is ');
            // whatever else you want to do with that user_text_temp value
          }

I think that's the easiest way to do what i want. I posted it because it may be of use to people new to drupal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.