magento add multiple products to cart from wishlist through check box

magento add multiple products to cart from wishlist through check box

August 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento add multiple products to cart from wishlist through check box

Adding Multiple Products to Cart from Wishlist via Checkbox

Are you looking to add multiple products from your Magento wishlist to the cart using checkboxes? In this post, we’ll guide you through implementing this functionality step-by-step.

The Scenario: Transferring Selected Wishlist Items to Cart

Your goal is to allow users to select multiple items from their wishlist via checkboxes and add them all to the cart in one go. Upon adding the selected items to the cart, those items should be removed from the wishlist table.

You’ve already tried implementing this using related-products javascript logic, but you’re still facing issues. Let’s troubleshoot this together.

Implementing the Solution: A Detailed Walkthrough

Step 1: The Checkbox Column (Hardcoded for Demonstration)

First, let’s look at the relevant HTML code for the checkbox column in your wishlist view:

<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox7" name="related_products[]" value="7">

Step 2: Adding Javascript Functionality

Next, you’ve added some JavaScript to manage the checkboxes:

<script type="text/javascript">
    //<![CDATA[
    $$('.related-checkbox').each(function(elem){
        Event.observe(elem, 'click', addRelatedToProduct)
    });

    var relatedProductsCheckFlag = false;
    function selectAllRelated(txt){
        if (relatedProductsCheckFlag == false) {
            $$('.related-checkbox').each(function(elem){
                elem.checked = true;
            });
            relatedProductsCheckFlag = true;
            txt.innerHTML="unselect all";
        } else {
            $$('.related-checkbox').each(function(elem){
                elem.checked = false;
            });
            relatedProductsCheckFlag = false;
            txt.innerHTML="select all";
        }
        addRelatedToProduct();
    }

    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>

This script allows users to select all checkboxes at once and updates the selected product IDs in a hidden field named related-products-field.

Step 3: The “Add to Cart” Button

You’ve also provided HTML for the “Add to Cart” button:

<button type="button" title="Add to Cart" class="button btn-cart" onclick="productAddToCartForm.submit(this)">
    <span>
        <span>Add to Cart</span>
    </span>
</button>

Step 4: The “Add to Cart” JavaScript

Finally, you’ve included the relevant JavaScript for handling the “Add to Cart” functionality:

<script type="text/javascript">
    //<![CDATA[
        var productAddToCartForm = new VarienForm('product_addtocart_form');
        productAddToCartForm.submit = function(button, url) {
            if (this.validator.validate()) {
                var form = this.form;
                var oldUrl = form.action;

                if (url) {
                   form.action = url;
                }
                var e = null;
                try {
                    this.form.submit();
                } catch (e) {
                }
                this.form.action = oldUrl;
                if (e) {
                    throw e;
                }

                if (button &amp;&amp; button != 'undefined') {
                    button.disabled = true;
                }
            }
        }.bind(productAddToCartForm);

        productAddToCartForm.submitLight = function(button, url){
            if(this.validator) {
                var nv = Validation.methods;
                delete Validation.methods['required-entry'];
                delete Validation.methods['validate-one-required'];
                delete Validation.methods['validate-one-required-by-name'];
                // Remove custom datetime validators
                for (var methodName in Validation.methods) {
                    if (methodName.match(/^validate-datetime-.*/i)) {
                        delete Validation.methods[methodName];
                    }
                }

                if (this.validator.validate()) {
                    if (url) {
                        this.form.action = url;
                    }
                    this.form.submit();
                }
                Object.extend(Validation.methods, nv);
            }
        }.bind(productAddToCartForm);
    //]]>
</script>

The Next Steps: Integrating with Magento’s Core Functionality

While you’ve made great progress with your custom JavaScript code, to fully implement this feature, you’ll need to integrate it with Magento’s core add-to-cart functionality.

I recommend checking out the official Magento documentation on Adding Products to Cart and Working with Wishlists in Magento 2. These resources provide a solid foundation for understanding how to work with the Magento cart and wishlist systems.

Additionally, consider exploring some of the popular third-party extensions available on the Magento Marketplace (like the Amasty Wishlist extension) that offer enhanced wishlist functionality, including the ability to add multiple items to the cart from a wishlist.

Conclusion

In this post, we’ve explored how to implement adding multiple products from the wishlist to the cart using checkboxes in Magento. We’ve examined your existing JavaScript code and provided guidance on integrating it with Magento’s core functionality.

Remember, when working with the Magento platform, always consult the official documentation and consider leveraging reputable third-party extensions for enhanced features. This approach will help ensure a stable and secure implementation of your desired functionality.

Happy coding, and feel free to explore other Magento tutorials and tips on Laravel Company.

Checkout Catalog Database Errors

Our network