SalguaMagentoAddProduct
SalguaMagentoAddProduct copied to clipboard
support for configurable products
Hi,
Firstly - this is a brilliant solution and happy to have found your work.
I am just wondering if your solution applies to configurable products (aka am I just doing something wrong or no.. config products aren't supported.)
I tried http://mystore.com.au/urlcheckout/add?product=1&qty=2&coupon_code=XXXXXX&super_attribute[92]=3&super_attribute[134]=9
but just got an empty cart
i chose the super_attribute parameter based on info from this article http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_a_product_to_the_cart_via_querystring
i dont expect you to code an answer, just a reply would be appreciated to let me know if such functionality is already written in this module.
ive also seen this as a possible solution http://stackoverflow.com/questions/14876680/add-a-configurable-product-to-the-cart-using-url
your solution seems better as it doesn't modify template files.
Thanks H
Hi,
I'm glad that the module was useful for you. The controller parse only coupon_code and product parameters, the others are ignored. I think it should be a simple implementation, I will try to do it asap.
Thanks, Salvatore
Hey, I second hudsondonovan's comment, fantastically simple extension, but I'd also like the little extra bit for configurable products and options. Is there any movement on this yet?
Hello everybody. I build a configurator with it. In the next week i will test it and need the configurable product functionallity too...
Work it now or do you like to fix it?
I've adjusted the code to suit our purpose, we didn't need to cater for multiple products at once so to simplify things I took out that loop and we set options via the following snippet. Works perfectly for us :-)
// Handle product & quantity
$product_id = $this->getRequest()->getParam('product');
$qty = $this->getRequest()->getParam('qty');
$options = $this->getRequest()->getParam('share');
if ($product_id == '') {
$this->_redirect('/');
}
// Initialize the Cart
$cart = Mage::getModel('checkout/cart');
$cart->init();
// Build the cart
// Quantity
if($qty == ''){
$q = '1';
}else{
$q = $qty;
}
// Product
$productModel = Mage::getModel('catalog/product')->load($product_id);
$params['qty'] = $q;
$params['options'] = array(7 => $options); // 7 is the option ID found in the product page input id
try{
$cart->addProduct($productModel, $params);
}
catch(Exception $e){
$this->_redirect('/');
}
// Save the cart
$cart->save();
Thanks. I think this snippet will bring me a big step forward...
@salgua Can u merge this codesnippet? @ksjones How can i handle more than one option id?
Hello everybody, here is the codesnippet to handle more than one option.
<?php
/**
* AddProduct Module
*
* NOTICE OF LICENSE
*
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
* through the world wide web, please send an email to
* [email protected] so we can send you a copy immediately.
*
*/
class Salgua_AddProduct_AddController extends Mage_Core_Controller_Front_Action {
public function indexAction () {
// Handle product & quantity
$product_id = $this->getRequest()->getParam('product');
$qty = $this->getRequest()->getParam('qty');
// Base Color
$basecolor = $this->getRequest()->getParam('bc');
// Zweitfarbe
$second = $this->getRequest()->getParam('sc');
// Drittfarbe
$third = $this->getRequest()->getParam('tc');
// Bommelcolor 1
$bommel_one = $this->getRequest()->getParam('pc1');
// Bommelcolor 2
$bommel_two = $this->getRequest()->getParam('pc2');
// Bommelcolor 3
$bommel_three = $this->getRequest()->getParam('pc3');
// Schaftverlängerung
$schaft = $this->getRequest()->getParam('sv');
// Kontakt gewünscht
$kontakt = $this->getRequest()->getParam('kg');
// Initialen aufdrucken
$initialen_aufdrucken = $this->getRequest()->getParam('ia');
// Initialen aufdrucken
$initialen = $this->getRequest()->getParam('it');
// Golf Club
$golfclub = $this->getRequest()->getParam('gc');
if ($product_id == '') {
$this->_redirect('/');
}
// Initialize the Cart
$cart = Mage::getModel('checkout/cart');
$cart->init();
// Build the cart
// Quantity
if($qty == ''){
$q = '1';
}else{
$q = $qty;
}
// Product
$productModel = Mage::getModel('catalog/product')->load($product_id);
$params['qty'] = $q;
$params['options'] = array(28 => $basecolor,
29 => $bommel_one,
30 => $bommel_two,
31 => $bommel_three,
32 => $second,
33 => $third,
58 => $schaft,
59 => $kontakt,
60 => $initialen_aufdrucken,
61 => $initialen,
27 => $golfclub );
try{
$cart->addProduct($productModel, $params);
}
catch(Exception $e){
$this->_redirect('/');
}
// Save the cart
$cart->save();
if ($this->getRequest()->isXmlHttpRequest()) {
exit('1');
}
$this->_redirect('checkout/cart');
}
}