Magento: add product twice to cart, with different attributes!
- by Peter
Hello all, i have been working with this for a whole day but i cannot find any solution:
I have a product (lenses), which has identical attributes, but user can choose one attribute set for one eye and another attribute set for another.
On the frontend i got it ok, see it here:
http://connecta.si/clarus/index.php/featured/acuvue-oasys-for-astigmatism.html
So the user can select attributes for left or right eye, but it is the same product.
I build a function, wich should take a product in a cart (before save), add other set of attributes, so there should be two products in the cart. What happens is there are two products, but with the same set of attributes???
Here is the snippet of the function:
$req = Mage::app()-getRequest();
$request[’qty’] = 1;
$request[’product’] = 15;
$request[’uenc’] = $req-get(’uenc’);
$request[’options’][1] = 1;
$request[’options’][3] = 5;
$request[’options’][2] = 3;
$reqo = new Varien_Object($request);
$newitem = $quote-addProduct($founditem-getProduct(), $reqo);
//add another one ------------------------------------------
$request[’qty’] = 1;
$request[’product’] = 15;
$request[’uenc’] = $req-get(’uenc’);
$request[’options’][1] = 2;
$request[’options’][3] = 6;
$request[’options’][2] = 4;
$reqo = new Varien_Object($request);
$newitem = $quote-addProduct($founditem-getProduct(), $reqo);
Or another test, with some other functions (again, product added, with 2 quantity , but same attributes...):
$req = Mage::app()-getRequest();
$request[’qty’] = 1;
$request[’product’] = 15;
$request[’uenc’] = $req-get(’uenc’);
$request[’options’][1] = 2;
$request[’options’][3] = 6;
$request[’options’][2] = 4;
$product = $founditem-getProduct();
$cart = Mage::getSingleton(’checkout/cart’);
//delete all first…
$cart-getItems()-clear()-save();
$reqo = new Varien_Object($request);
$cart-addProduct($founditem-getProduct(), $reqo);
$cart-getItems()-save();
$request[’options’][1] = 1;
$request[’options’][3] = 5;
$request[’options’][2] = 3;
$reqo = new Varien_Object($request);
$cart-addProduct($founditem-getProduct(), $reqo);
$cart-getItems()-save();
i really dont know what more to do, please any advice, this is my first module in magento…
thank you, Peter