<?php
/**
* Implementation of hook_form_alter().
*/
function commerce_dedicatoria_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'commerce_checkout_form_checkout') {
drupal_set_message("estoy en commerce_dedicatoria_form_alter ");
/*$form['buttons']['continue']['#submit'][] = 'funcion que llame añada el line item';*/
dsm($form_id); // print form ID to messages
dsm($form);
}
}
/**
* Implements hook_commerce_line_item_type_info().
*/
function commerce_dedicatoria_commerce_line_item_type_info() {
drupal_set_message("estoy en commerce_dedicatoria_commerce_line_item_type_info ");
$line_item_types['dedicatoria'] = array(
'name' => t('Dedicatoria personalizada'),
'description' => t('Dedicatoria personalizada que los usuario spodrán seleccionale en el proceso de compra.'),
'product' => FALSE,
// Here you can change the text in the submit button in the order admin
// line item add area.
'add_form_submit_value' => t('Añadir dedicatoria'),
'callbacks' => array(
'configuration' => 'commerce_dedicatoria_configuration',
'title' => 'commerce_dedicatoria_title',
'add_form' => 'commerce_dedicatoria_add_form',
'add_form_submit' => 'commerce_dedicatoria_add_form_submit',
),
);
return $line_item_types;
}
/**
* Configure the line item with additional fields or whatever.
*
* This function is called by the line item module when it is enabled or this
* module is enabled. It invokes this function using the configuration_callback
* as specified above. Other modules defining product line item types should
* use this function to ensure their types have the required fields.
*
* @param $line_item_type
* The info array of the line item type being configured.
*
* @see commerce_product_line_item_configuration()
*/
function commerce_dedicatoria_configuration($line_item_type) {
$type = $line_item_type['type'];
// Here we could add fields or other configuration.
}
/**
* Returns a title for this line item.
*/
/* título que aparece en la linea de factura*/
function commerce_dedicatoria_title($line_item) {
return(t('Dedicatoria personalizada'));
}
/**
* Returns the elements necessary to add a product line item through a line item
* manager widget (on the order form).
*/
function commerce_dedicatoria_add_form($element, &$form_state) {
drupal_set_message("estoy en commerce_dedicatoria_add_form ");
$form = array();
return $form;
}
/**
* Adds the selected product information to a line item added via a line item
* manager widget (on the admin order page).
*
* @param $line_item
* The newly created line item object.
* @param $element
* The array representing the widget form element.
* @param $form_state
* The present state of the form upon the latest submission.
* @param $form
* The actual form array.
*
* @return
* NULL if all is well or an error message if something goes wrong.
*/
function commerce_dedicatoria_add_form_submit(&$line_item, $element, &$form_state, $form) {
drupal_set_message("estoy en commerce_dedicatoria_add_form_submit ");
$line_item->line_item_label = t('Dedicatoria');
// Wrap the line item and product to easily set field information.
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
// Provide a default price.
$amount = variable_get('dedicatoria_amount', 150);
$currency_code = variable_get('dedicatoria_currency', 'EUR');
$line_item->commerce_unit_price = array('und' => array(
'0' => array('amount' => $amount, 'currency_code' => $currency_code)
));
if (!is_null($line_item_wrapper->commerce_unit_price->value())) {
// Add the base price to the components array.
if (!commerce_price_component_load($line_item_wrapper->commerce_unit_price->value(), 'base_price')) {
$line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
$line_item_wrapper->commerce_unit_price->value(),
'base_price',
$line_item_wrapper->commerce_unit_price->value(),
TRUE
);
}
}
}