jeffharrell / minicart

The minicart is a great way to improve your PayPal shopping cart integration.
MIT License
501 stars 211 forks source link

checkout with multiple items to paypal api #316

Open liadlevy opened 4 years ago

liadlevy commented 4 years ago

How can I checkout with multiple items in cart? I've noticed that paypal api using _x doesn't work, but if you do multiple form post data it will. I thought of doing a JS for loop and everytime post it to paypal but it did not work. any ideas? using JS and HTML5

snippet of my code I tried:

<!-- TEST -->
<form id='test' action="https://www.paypal.com/cgi-bin/webscr" method="post">
        <input type="submit" name="submit" value="Add to cart"/>

</form>

<!-- // TEST -->
<script>
      var wrapper = document.getElementById("test");
       var myHTML = '';

        shoe.render();
        shoe.cart.on('shoe_checkout', function (evt) {
            var items, len, i;

            if (this.subtotal() > 0) {
                items = this.items();
                alert(Object.keys(items[0]))
                for (i = 0, len = items.length; i < len; i++) {
                     myHTML = `<input type="hidden" name="cmd" value="_cart"/>
                    <input type="hidden" name="add" value="1"/>
                    <input type="hidden" name="business" value="liad4business@gmail.com"/>
                    <input type="hidden" name="item_name" value=` + items[i]._data.shoe_item +`/>
                    <input type="hidden" name="quantity" value=` + items[i]._data.quantity +`/>
                    <input type="hidden" name="amount" value=` + items[i]._data.amount +`/>
                    <input type="hidden" name="currency_code" value="USD"/>
                    <input type="hidden" name="shipping" value="1.00">`;

                alert(myHTML)
                wrapper.innerHTML = myHTML

                }

            }
        });

</script>