We have a scenario where on the product page we have a few text links that reference a purchasable product "in addition to the actual product that the user is currently viewing".
The goal would be to allow the user to make additional sections via eit开发者_运维问答her checkbox or possibly a radio button and then add the selected additional item to the cart when the user clicks the generic add to cart button.
The idea is to sell additional services, such as a warranty, a membership or others at that same time as purchasing their main product.
While I do realize this could be done via grouped or bundled products, we wish to have a much more custom view of how the products are represented on the page thus causing us to pursue this method of adding multiple products on the fly.
The other difficulty is that we would like to try and avoid modifying any core files and stay within out theme and local files if at all possible.
Thank you in advance!
[UPDATE] I have been testing a small piece of code that will add an actual stocked item via the following when the user uses the default add to cart
<?php // add multiple items to cart
$cart = Mage::getModel("checkout/cart");
$cart->addProduct($someId, $someQty);
$cart->save();
?>
Found a solutions with the following:
<script type="text/javascript">
//<![CDATA[
$$('.related-checkbox').each(function(elem){
Event.observe(elem, 'click', addRelatedToProduct)
});
var relatedProductsCheckFlag = false;
function addRelatedToProduct(){
var checkboxes = $$('.related-checkbox');
var values = [];
for(var i=0;i<checkboxes.length;i++){
if(checkboxes[i].checked) values.push(checkboxes[i].value);
}
if($('related-products-field')){
$('related-products-field').value = values.join(',');
}
}
//]]>
</script>
You can then add the following item(s):
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox35" name="related_products[]" value="35">
Hopefully this may help some one in the future trying to do the same thing!
Cheers!
精彩评论