Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 22nd, 2012  |  syntax: PHP  |  size: 4.11 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /**
  4. * Implementation of hook_form_alter().
  5. */
  6.  
  7. function commerce_dedicatoria_form_alter(&$form, &$form_state, $form_id) {
  8.         if ($form_id == 'commerce_checkout_form_checkout') {
  9.                 drupal_set_message("estoy en commerce_dedicatoria_form_alter ");
  10.                 /*$form['buttons']['continue']['#submit'][] = 'funcion que llame añada el line item';*/
  11.                 dsm($form_id);  // print form ID to messages
  12.                 dsm($form);
  13.   }
  14. }
  15.  
  16.  
  17. /**
  18.  * Implements hook_commerce_line_item_type_info().
  19.  */
  20. function commerce_dedicatoria_commerce_line_item_type_info() {
  21.         drupal_set_message("estoy en commerce_dedicatoria_commerce_line_item_type_info ");
  22.   $line_item_types['dedicatoria'] = array(
  23.     'name' => t('Dedicatoria personalizada'),
  24.     'description' => t('Dedicatoria personalizada que los usuario spodrán seleccionale en el proceso de compra.'),
  25.     'product' => FALSE,
  26.  
  27.     // Here you can change the text in the submit button in the order admin
  28.     // line item add area.
  29.     'add_form_submit_value' => t('Añadir dedicatoria'),
  30.  
  31.     'callbacks' => array(
  32.       'configuration' => 'commerce_dedicatoria_configuration',
  33.       'title' => 'commerce_dedicatoria_title',
  34.       'add_form' => 'commerce_dedicatoria_add_form',
  35.       'add_form_submit' => 'commerce_dedicatoria_add_form_submit',
  36.     ),
  37.   );
  38.  
  39.   return $line_item_types;
  40. }
  41.  
  42. /**
  43.  * Configure the line item with additional fields or whatever.
  44.  *
  45.  * This function is called by the line item module when it is enabled or this
  46.  * module is enabled. It invokes this function using the configuration_callback
  47.  * as specified above. Other modules defining product line item types should
  48.  * use this function to ensure their types have the required fields.
  49.  *
  50.  * @param $line_item_type
  51.  *   The info array of the line item type being configured.
  52.  *
  53.  * @see commerce_product_line_item_configuration()
  54.  */
  55. function commerce_dedicatoria_configuration($line_item_type) {
  56.   $type = $line_item_type['type'];
  57.  
  58.   // Here we could add fields or other configuration.
  59.  
  60. }
  61.  
  62. /**
  63.  * Returns a title for this line item.
  64.  */
  65.  
  66. /* título que aparece en la linea de factura*/
  67.  
  68. function commerce_dedicatoria_title($line_item) {
  69.   return(t('Dedicatoria personalizada'));
  70. }
  71.  
  72. /**
  73.  * Returns the elements necessary to add a product line item through a line item
  74.  * manager widget (on the order form).
  75.  */
  76. function commerce_dedicatoria_add_form($element, &$form_state) {
  77. drupal_set_message("estoy en commerce_dedicatoria_add_form ");
  78.         $form = array();
  79.  
  80.   return $form;
  81. }
  82.  
  83. /**
  84.  * Adds the selected product information to a line item added via a line item
  85.  *   manager widget (on the admin order page).
  86.  *
  87.  * @param $line_item
  88.  *   The newly created line item object.
  89.  * @param $element
  90.  *   The array representing the widget form element.
  91.  * @param $form_state
  92.  *   The present state of the form upon the latest submission.
  93.  * @param $form
  94.  *   The actual form array.
  95.  *
  96.  * @return
  97.  *   NULL if all is well or an error message if something goes wrong.
  98.  */
  99. function commerce_dedicatoria_add_form_submit(&$line_item, $element, &$form_state, $form) {
  100. drupal_set_message("estoy en commerce_dedicatoria_add_form_submit ");
  101.         $line_item->line_item_label = t('Dedicatoria');
  102.  
  103.   // Wrap the line item and product to easily set field information.
  104.   $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  105.  
  106.   // Provide a default price.
  107.   $amount = variable_get('dedicatoria_amount', 150);
  108.   $currency_code = variable_get('dedicatoria_currency', 'EUR');
  109.  
  110.   $line_item->commerce_unit_price = array('und' => array(
  111.     '0' => array('amount' => $amount, 'currency_code' => $currency_code)
  112.   ));
  113.  
  114.   if (!is_null($line_item_wrapper->commerce_unit_price->value())) {
  115.     // Add the base price to the components array.
  116.     if (!commerce_price_component_load($line_item_wrapper->commerce_unit_price->value(), 'base_price')) {
  117.       $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
  118.         $line_item_wrapper->commerce_unit_price->value(),
  119.         'base_price',
  120.         $line_item_wrapper->commerce_unit_price->value(),
  121.         TRUE
  122.       );
  123.     }
  124.   }
  125.  
  126. }