<p>Currently only one <code>purchasableId</code> can be added to the cart in a single form action. To get around this limitation you would need to use ajax to send multiple http requests (to add both items) OR use a plugin like MultiAdd: <a href="https://github.com/engram-design/MultiAdd" rel="nofollow">https://github.com/engram-design/MultiAdd</a></p>

CC BY-SA 3.0
2016-01-05T02:30:36.013Z
Thank you Brad & Luke - this pointed me in the right direction! I'm able to loop through the inputs via "plain ajax" (no plugin) and getting things successfully added to my cart. 

Would you suggest I wait for a response after each request or just let the loop run?
Damon
CC BY-SA 3.0
2016-01-04T18:09:42.307Z
2016-01-04T18:09:42.307Z
Luke Holder
<p>Using Craft Commerce, I would like to offer more than one product on my <code>_entry</code> template.</p>

<p>For example, let's say I am selling a wagon. I have a drop down of variants for color:</p>

<pre><code>&lt;label&gt;Choose Color&lt;/label&gt;

&lt;select name="purchasableId" class="form-control"&gt;
    {% for purchasable in product.variants %}
        &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}"&gt;
        {{ purchasable.wagon.label }} &amp;ndash; {{ purchasable.price|currency(cart.currency) }}
        &lt;/option&gt;
    {% endfor %}
&lt;/select&gt;
</code></pre>

<p>Now I would also like to offer a warranty. There could be different prices for different plans (variants) as well:</p>

<pre><code>&lt;label&gt;Choose Warranty&lt;/label&gt;

&lt;select name="purchasableId" class="form-control"&gt;
    {% for purchasable in product.variants %}
        &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}"&gt;
        {{ purchasable.warranty.label }} &amp;ndash; {{ purchasable.price|currency(cart.currency) }}
        &lt;/option&gt;
    {% endfor %}
&lt;/select&gt;
</code></pre>

<p><strong>EDIT</strong></p>

<p>Each "Warranty" is it's own section and has it's own product type within Commerce. 
You could purchase a warranty by visiting <code>mysite.com/warranties/my-warranty</code> or <code>mysite.com/wagons</code>. </p>

<p>An example might look like <code>mysite.com/warranties/basic</code>. That page would have information about the "basic" warranty along with the option to add to cart.</p>

<p>In theory, you could purchase a warranty <em>without</em> purchasing a wagon. </p>

<p>I also want to (somehow) allow the user to purchase a warranty when they purchase a wagon. That's not to say I <em>must</em> do it this way, I am open to ideas. Currently both products are available together.</p>

<p><strong>EDIT 2</strong></p>

<p>Here is what my current form looks like on my product page. Is there a naming convention I should follow to pass multiple  options to the <code>updateCart</code> method? If I make both fields have the name of <code>purchasableId</code>, as expected, the system just grabs the last element. In my case it's the warranty product.</p>

<p>Since I would like to make the warranty a required field, maybe I need to restructure how I am selling wagons? I don't want to add to the variant list of my wagon product, that would get out of hand quickly.</p>

<p>Or, perhaps it's just a "Related Products" title and a link to the warranties page?</p>

<pre><code>&lt;form method="post" action="" accept-charset="utf-8"&gt;
&lt;fieldset&gt;
    &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
    &lt;input type="hidden" name="redirect" value="commerce/cart"&gt;
    &lt;input type="hidden" name="qty" value="1"&gt;
    {{ getCsrfInput() }}
&lt;/fieldset&gt;

&lt;fieldset&gt;
    &lt;label for="purchasableId"&gt;Choose Color&lt;/label&gt;
    &lt;select name="purchasableId" class="form-control"&gt;
        {% for purchasable in product.variants %}
            &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}"&gt;
            {{ purchasable.title }} &amp;ndash; {{ purchasable.price|currency(cart.currency) }}
        &lt;/option&gt;
    {% endfor %}
    &lt;/select&gt;
&lt;/fieldset&gt;

&lt;fieldset&gt;
    {% set warranties = product.warrantyOptions %}  {# This is the products field #}
    &lt;label for="warranty"&gt;Choose Warranty&lt;/label&gt;
    &lt;select name="warrantyId" class="form-control"&gt;
        {% for warranty in warranties %}
            {% for purchasable in warranty.variants %}
                &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %}
                value="{{ purchasable.purchasableId }}"&gt;
               {{ purchasable.title }} &amp;ndash; {{ purchasable.price|currency(cart.currency) }}
               &lt;/option&gt;
           {% endfor %}
       {% endfor %}
    &lt;/select&gt;
&lt;/fieldset&gt;
</code></pre>

<p></p>

CC BY-SA 3.0
2016-01-02T05:49:46.723Z
Are warranties related to specific products?  Or are warranties more generic and available to all products?
Brad Bell
CC BY-SA 3.0
2016-01-02T15:44:33.893Z
They would be available to all products. They are optional & not product-specific, but available to all products. 

For example "1 year - $50.00", "2 year- $100.00"
Damon
CC BY-SA 3.0
2016-01-02T16:04:35.610Z
Are all the warranties in their own section?  Or are they distinguished by a category?  And would you want to display _all_ warranties, or just a subset of them?
Brad Bell
CC BY-SA 3.0
2016-01-02T19:58:53.140Z
I've updated my question to give better answers.
Damon
CC BY-SA 3.0
2016-01-03T19:56:22.883Z
Seems like you'd just be able to create a "Commerce Products" field with its source set to your warranties section(s) and add that to your to your other products field layouts, no?  Then you could just pull them in as "related" products from your main product pages?
Brad Bell
CC BY-SA 3.0
2016-01-03T21:42:16.983Z
Thank you for the suggestions Brad, I appreciate it. That worked well - I am curious how to pass multiple arguments like that to the `update` function.

`$purchasableId = craft()->request->getPost('purchasableId')` It seems like it's built to only be a 1:1 method. 

I will be passing it 2 items, so I almost need something like a `foreach` in the controller?
Damon
<plugin-craftcommerce>
How can I have more than one product on the same page?
# How can I have more than one product on the same page?

(Asked by: username_0 on 2016-01-02)

Using Craft Commerce, I would like to offer more than one product on my _entry template.
For example, let's say I am selling a wagon. I have a drop down of variants for color:
Choose Color


    {% for purchasable in product.variants %}
        
        {{ purchasable.wagon.label }} – {{ purchasable.price|currency(cart.currency) }}
        
    {% endfor %}


Now I would also like to offer a warranty. There could be different prices for different plans (variants) as well:
Choose Warranty


    {% for purchasable in product.variants %}
        
        {{ purchasable.warranty.label }} – {{ purchasable.price|currency(cart.currency) }}
        
    {% endfor %}


EDIT
Each "Warranty" is it's own section and has it's own product type within Commerce. 
You could purchase a warranty by visiting mysite.com/warranties/my-warranty or mysite.com/wagons. 
An example might look like mysite.com/warranties/basic. That page would have information about the "basic" warranty along with the option to add to cart.
In theory, you could purchase a warranty without purchasing a wagon. 
I also want to (somehow) allow the user to purchase a warranty when they purchase a wagon. That's not to say I must do it this way, I am open to ideas. Currently both products are available together.
EDIT 2
Here is what my current form looks like on my product page. Is there a naming convention I should follow to pass multiple  options to the updateCart method? If I make both fields have the name of purchasableId, as expected, the system just grabs the last element. In my case it's the warranty product.
Since I would like to make the warranty a required field, maybe I need to restructure how I am selling wagons? I don't want to add to the variant list of my wagon product, that would get out of hand quickly.
Or, perhaps it's just a "Related Products" title and a link to the warranties page?


    
    
    
    {{ getCsrfInput() }}



    Choose Color
    
        {% for purchasable in product.variants %}
            
            {{ purchasable.title }} – {{ purchasable.price|currency(cart.currency) }}
        
    {% endfor %}
    



    {% set warranties = product.warrantyOptions %}  {# This is the products field #}
    Choose Warranty
    
        {% for warranty in warranties %}
            {% for purchasable in warranty.variants %}
                
               {{ purchasable.title }} – {{ purchasable.price|currency(cart.currency) }}
               
           {% endfor %}
       {% endfor %}

**Tags:** plugin-craftcommerce

> **Comments:**
> **username_1**: Are warranties related to specific products?  Or are warranties more generic and available to all products?  
> **username_0**: They would be available to all products. They are optional & not product-specific, but available to all products.   For example "1 year - $50.00", "2 year- $100.00"  
> **username_1**: Are all the warranties in their own section?  Or are they distinguished by a category?  And would you want to display _all_ warranties, or just a subset of them?  
> **username_0**: I've updated my question to give better answers.  
> **username_1**: Seems like you'd just be able to create a "Commerce Products" field with its source set to your warranties section(s) and add that to your to your other products field layouts, no?  Then you could just pull them in as "related" products from your main product pages?  
> **username_0**: Thank you for the suggestions Brad, I appreciate it. That worked well - I am curious how to pass multiple arguments like that to the `update` function.  `$purchasableId = craft()->request->getPost('purchasableId')` It seems like it's built to only be a 1:1 method.   I will be passing it 2 items, so I almost need something like a `foreach` in the controller?  

---

## 1 answers

### Answer by username_2 on 2016-01-04. Score: 2 | Accepted answer

Currently only one `purchasableId` can be added to the cart in a single form action. To get around this limitation you would need to use ajax to send multiple http requests (to add both items) OR use a plugin like MultiAdd: <https://github.com/engram-design/MultiAdd>

> **Comments:**
> **username_0**: Thank you Brad & Luke - this pointed me in the right direction! I'm able to loop through the inputs via "plain ajax" (no plugin) and getting things successfully added to my cart.   Would you suggest I wait for a response after each request or just let the loop run?  

---

