How can add multiple items in cart, through checkbox selection of product and attributes too.
I got code from some where but nothing changes reflected. i have also tried module uc_multibuy.
code is here.
$form = drupal_get_form('multi_add_form');
function multi_add_form() {
$form = array();
// Make the products array in the form a tree.
$form['products'] = array(
'#tree' => TRUE,
);
// Use an array of product nids to build the form.
$nids = array(1, 2);
// Add a quantity field for each product. from 0 to 10
foreach ($nids as $nid) {
$node = node_load($nid);
$x = 0;
$options = array();
while ($x <= 10) {
$options[$x] = $x;
$x++;
}
$form['products'][$nid]['qty'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('Amount'),
'#default_value' => 0,
);
}
// Add an add to cart button.
$form['add_to_cart'] = array(
'#type' => 'submit',
'#value' => t('Add to cart'),
);
return $form;
}
function multi_add_form_submit($form, &$form_state) {
// Loop through the products array.
foreach ($form_state['values']['products'] as $key => $value) {
// The key is the product nid, the value holds the qty.
if ($value['qty'] > 0) {
// Add the item to the cart if the quantity was increased.