1

I have a channel to create an event. I also have a CartThrob Price Modifier field to add tickets if they are available.

On the single entry page, I only wish to show the exp:cartthrob:multi_add_to_cart_form if the single entry has available tickets.

I'm using the following code;

{if event_tickets:total_results}
<div id="event_tickets" class="box toptagorange buybox">
    <h2>Buy Tickets</h2>
        {exp:cartthrob:multi_add_to_cart_form
            return="shop/basket"
        }
        <fieldset>
            <table>
                <tbody>
                    <tr>
                        <th class="ticket">Ticket</th>
                        <th>Qty</th>
                    </tr>
                    {event_tickets}
                    <tr>
                        <td>{option_name} <span class="price">{exp:cartthrob:view_formatted_number number="{price:plus_tax}" prefix="£" decimals="2"}</span></td>
                        <td><input type="text" name="quantity[{row_id}]" value="" class="tiny" /></td>
                        <input type="hidden" name="item_options[{row_id}][event_tickets]" value="{option_value}" />
                        <input type="hidden" name="entry_id[{row_id}]" value="{entry_id}" />
                    </tr>
                    {/event_tickets}
                </tbody>
            </table>
        </fieldset>
        <input type="submit" value="Buy Tickets">
    {/exp:cartthrob:multi_add_to_cart_form}
</div>
{/if}

This works fine for an event that has tickets. However, if an event doesn't have any tickets then the page just goes to a 404. I was wondering if someone might be able to help figure this out?

Thanks, Neil

1
  • I have resolved this by using a Matrix field instead of the CartThrob Price Modifier field. I will mark this as answered when I am able to do so. Commented Jul 8, 2013 at 16:03

1 Answer 1

1

Solution using Matrix field type instead:

{if event_tickets}
<div id="event_tickets" class="box toptagorange buybox">
<h2>Buy Tickets</h2>
{exp:cartthrob:multi_add_to_cart_form
return="shop/basket"
}
<fieldset>
<table>
<tbody>
<tr>
<th class="ticket">Ticket</th>
<th>Qty</th>
</tr>
{event_tickets}
<tr>
<td>{if option_name}{option_name}{if:else}{option_value}{/if} <span class="price">{price_plus_tax_numeric}</span></td>
<td><input type="text" name="quantity[{row_id}]" value="" class="tiny" /></td>
<input type="hidden" name="item_options[{row_id}][event_tickets]" value="{option_value}" />
<input type="hidden" name="entry_id[{row_id}]" value="{entry_id}" />
</tr>
{/event_tickets}
</tbody>
</table>
</fieldset>
{if '{event_tickets:sum col="inventory"}' == 0}
<p>Out Of Stock</p>
{if:else}
<input type="submit" value="Buy Tickets">
{/if}
{/exp:cartthrob:multi_add_to_cart_form}
</div>
{/if}
1
  • I've moved your solution down into the "answer". This allows people to easily find it, and also allows the community to continue to submit alternative "answers" in future. Commented Jul 19, 2013 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.