function uc_product_view_ajax_commands in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_product/uc_product.module \uc_product_view_ajax_commands()
Dynamically replaces parts of a product view based on form input.
If a module adds an input field to the add-to-cart form which affects some aspect of a product (e.g. display price or weight), it should attach an #ajax callback to that form element, and use this function in the callback to build updated content for the affected fields.
Parameters
$form_state: The current form state. This must contain a 'variant' entry in the 'storage' array which represents the product as configured by user input data. In most cases, this is provided automatically by uc_product_add_to_cart_form_validate().
$keys: An array of keys in the built product content which should be replaced (e.g. 'display_price').
Return value
An array of Ajax commands.
1 call to uc_product_view_ajax_commands()
- uc_attribute_option_ajax in uc_attribute/
uc_attribute.module - Ajax callback for attribute selection form elements.
File
- uc_product/
uc_product.module, line 696 - The product module for Ubercart.
Code
function uc_product_view_ajax_commands($form_state, $keys) {
$commands = array();
if (variable_get('uc_product_update_node_view', FALSE) && !empty($form_state['storage']['variant'])) {
$node_div = '.uc-product-' . $form_state['storage']['variant']->nid;
$build = node_view($form_state['storage']['variant']);
foreach ($keys as $key) {
if (isset($build[$key])) {
$id = $node_div . '.' . str_replace('_', '-', $key);
$commands[] = ajax_command_replace($id, drupal_render($build[$key]));
}
}
}
return $commands;
}