DWNO,
here is a small improvement (or so I hope) - please review and incorporate into your code (or kill it if it is horribly wrong).
The following code extends Quick Order to handle ONE (1) REQUIRED attribute.
So, if you are adding a product via Quick Order and it has REQUIRED attributes, the product will be added into the cart together with one of them (first in the database). Optional attributes are ignored.
Why only one? - I actually do not know. The SQL query should return all of the required attributes, but it does not. I have run the query in phpMyAdmin, and it works just fine. So, after two hours of banging my head against the wall, I am posting my code here in hope that someone way more qualified takes it and makes it work for multiple required attributes.
So, the only changes are in the includes/modules/pages/quick_order/header_php.php file around line 185 or so. I am posting a bit of code around mine as well, so that you can see where it belongs. All my comments and variables have "aa" prefix.
PHP Code:
//only add if does not exceed maximum
if (($add_max == 1 and $cart_qty == 1)) {
// do not add
} else {
// AA get product attributes
$aa_attributes_db = $db->Execute("select options_id, options_values_id from " . TABLE_PRODUCTS_ATTRIBUTES . "
where products_id = '" . $qo_item_info['pid'][$i] . "' and attributes_default='1'");
$aa_attributes = array($aa_attributes_db->fields["options_id"] => $aa_attributes_db->fields["options_values_id"]);
// check for min/max and add that value or 1
// AA: Original code was: $_SESSION['cart']->add_cart($qo_item_info['pid'][$i], $cart_qty+$new_qty);
$_SESSION['cart']->add_cart($qo_item_info['pid'][$i], $cart_qty+$new_qty, $aa_attributes); // <-AA put new total of the product into cart by ID
}
}//end if (isset...
} //end for $i < $total_models
zen_redirect(zen_href_link(FILENAME_SHOPPING_CART, zen_get_all_get_params($parameters)));
} //end if $error === false
As you can see, it's just three extra lines. I am also attaching the full modified file.
What do you think?
Bookmarks