PDA

View Full Version : Automatically add multiple products with attribute to cart from external source



michael_s
05-24-2011, 03:52 PM
UPDATE BY: Richard Woolf / rfwoolf

This new version has 1 MAIN IMPROVEMENT and 1 WARNING:

IMPROVEMENT:
Up until now, you could add several products with 1 attribute.
But what if you have several attributes, like this:
..addproducts.php?product_id=28{8}17{7}15{9}19[1]
In the above URL, there are 3 attributes being set.
You can now have as many or as little attributes as you want.
Also, it is less sensitive, so if you leave off a bracket or something, it's okay - it will just ignore that attribute or quantity.

WARNING:
I have made it so that it specifically *adds* to your shopping cart (for some reason with me, if I had 1 in my cart and I add another 1, it was still 1).
To change this back, edit the file and change the SECOND parameter of add_cart:
CHANGE ALL OF THESE:
//(makes the cart quantity what it was PLUS your new quantity)
$cart->add_cart($productID, ($cart->get_quantity(tep_get_uprid($productID, $attributes))+$productQuantity), $attributes);
TO THIS:
//(makes the cart quantity your new quantity):
$cart->add_cart($productID, $productQuantity, $attributes);
CHANGE ALL OF THESE:
//(makes the cart quantity what it was PLUS 1)
TO THIS:
$cart->add_cart($productID, 1);

More... (http://addons.oscommerce.com/info/7877)