Month: October, 2011
Ubercart API – Add to Cart with Attributes
I had a problem with that and finally I have found solution for that – it is very simple.
1 2 3 4 |
$product_id = 100; // this is your product id, in drupal it is node with product type $quantity = 1; // amount of product uc_cart_add_item($product_id, $quantity, array('attributes' => array(1 => 500)), NULL, NULL, $check_redirect = FALSE); ?> |
And the third parameter concerns attributes, the key of that array it is the first attribute on list of attributes in UbertCart control panel.
How to Modify Sth After Submiting in Drupal 6
In Drupal 6 we have some constructions which are very helpful. You want to modify sth after node has been submited? No problem you can easly do it by using hooks. In some module create some functions which will called:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function my_module_form_alter(&$form, $form_state, $form_id) { if($form_id == 'name_of_your_form') { $form['#after_build'][] = '_my_module_after_build'; } } function _my_module_after_build(&$form, $form_state) { // here you should add that piece of code // $form['#redirect'] = 'your-page-after-submit'; $form['#submit'][] = 'my_module_action_after_submit'; } function my_module_action_after_submit($form, &$form_state) { // and here you have all you want, you can modify $form_state variable // to change status or other variables in node // $form_state['values']['status'] = false; return $form_state; } |
And that’s all you should know about it. Now you can simply modify whatever you want to modify.
See you!