Trying to add products to cart from pages which are totally outside Magento, on another CMS. The product information is available to these pages so technically I should be able to add to the cart via API.
I'm dealing with a developer who knows his CMS but not Magento, and the API information is not helpful.
All my products are structured as Grouped Products with associated simple products.
EDIT: I have managed do it programatically see at the very end - but that is not answering my question, just a test still no luck doing it over SOAP.
EDIT: I have other worries about SOAP->cart here SOAP API to build cart for frontend - should I be worried? session collision or cart loss?
It can be done in code / urls passing super_group[]
For example my group has ID 635 and one individual product in it is 122 I have been assuming that I need to pass to the cart:
product=635
super_group[122]=1
But how to do so via API? no hint of how. as if the documentation was added pre grouped products and never updated?
Found this which is full of questions, no answer http://www.opencart60s.com/magento/adding-grouped-product-via-magento-v2-api-21796.html
Looking at the API it seems the documentation covers adding: - simple products - simple products with options - bundles
but I am not seeing how to add a simple product which is hidden but only visible within a grouped product. I can add it direct as a simple product, and it gets added to the cart, but the connection to the group is lost, and there is also no link from the cart back to the product.
Clearly Magento needs both group and simple product information to be 100%
Within Magento itself, the way to do it is to pass the "parent" group sku and the component products as an array with quantity -eg super_group[399]=1
product=982&related_product=&super_group%5B399%5D=1
I don't see clear information how to pass super_group[399]=1 within the API
The API has the following possible fields
links An array of links (optional) options An array in the form of option_id => content (optional)
But there's no hint as to the format.
and then i see in several tickets (eg Unable to add configurable product to shopping cart using soap api) that maybe one needs to use "super_attribute" instead of "options" in some way
'super_attribute' => array(
0 => array(
'key' => attribute-id,
'value' => attribute-value
),
1 => array(
'key' => attribute-id,
'value' => attribute-value
)
TESTING
I have a very simple php file which tries to do the following:
$sess_id = $client->login($apiuser,$apikey);
$result = $client ->shoppingCartCreate($sess_id);
$arrProducts = array(); // trying different options, see below
$resultCartProductAdd = $client->shoppingCartProductAdd($sess_id, $result , $arrProducts);
NOT WORKING
array(
'product_id' => '982',
'qty' => 1,
'super_group' => array(
0 => array(
'399' => '1'
)
)
Error: Please specify the quantity of product(s).
NOT WORKING
array(
'product_id' => '982',
'qty' => 1,
'options' => array('399' => '1')
)
Error: Please specify the quantity of product(s).
NOT WORKING
array(
'product_id' => '982',
'qty' => 1,
'super_group' => array(
'399' => '1'
)
)
Error: Please specify the quantity of product(s).
Programatically in a Module I managed to do it - but that brings me no closer to a structure in SOAP. Looking at alternatives now... sending the form_key to build form? creating a view that is just the "add to cart" bit for embedding? Is there an Ajax cart that works with external clients too?
How it works in a Module
public function addcartAction()
{
// try a simple product: $productid = 122
// try a grouped product: $productid = 635, $vintage = 122;
// try another grouped product: $productid = 635, $vintage = 122;
$productid = (int) $this->getRequest()->getParam('id');
$vintage = (int) $this->getRequest()->getParam('vintage');
$qty = (int) $this->getRequest()->getParam('qty');
$super_group = array();
$params = array();
$groupedTypeInstance = Mage::getModel('catalog/product_type_grouped');
//Add product to cart
//Get object of main grouped product
$productModel = Mage::getModel('catalog/product')->load($productid);
if ($productModel->getTypeId() == 'simple') {
$params['product']=$productid;
$params['qty']=$qty;
}
if ($productModel->getTypeId() == 'grouped') {
$params['product']=$productid;
$params['super_group'] = array(
$vintage => $qty
);
}
//Get cart object
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($productModel->getId(), $params);
$cart->save();
echo $this->__('%s was added to your shopping cart.', Mage::helper('core')->htmlEscape($productModel->getName()));
}
(note: removed exception wrapping and tests to make the basics clearer)