0

I am using the update_cart_form nested inside the cart_items_info tag, to allow customers to edit the size or quantity of their item (as well as delete it from cart). I cannot find a way to have the item option they selected as the selected option in the (for example, if Medium is selected under the product_size, display that as the selected option)

I would also like to replicate this for displaying their currently chosen shipping method. Here is the code I currently am using:

{exp:cartthrob:cart_items_info}
    {if no_results}
        <p>You have nothing in your cart. <a class="blue" href="/shop">GO SHOP &raquo;</a></p>
    {/if}
    {if total_items > 0}
        {if first_row}
             {exp:cartthrob:update_cart_form  return="checkout" class="cart_form"}
        {/if}
                <ul class="cart-table">
                    {if product_detail_image}
                        <img src="{product_detail_image:feed}"/>
                    {if:else}
                        <img src="{site_url}content/img/ride.png"/>
                    {/if}
                    <li><p>{title} <span>Quantity: <input type="text" name="quantity[{row_id}]" size="1" maxlength="2" value="{quantity}" /></span></p>
                        <p>{exp:cartthrob:item_options entry_id="{entry_id}" }
                        {if dynamic}
                            <label>{option_label}</label>
                            {input}
                        {if:else}
                            {if options_exist}
                                {select}  
                                    <option {selected} value="{option_value}">
                                    {option_name}{if option_price_numeric > 0} +{option_price}{/if}
                                    </option>
                                {/select}
                            {/if}
                        {/if}
                        {/exp:cartthrob:item_options}
                        <span><input type="checkbox" name="delete[{row_id}]"> Delete this item</span></p>
                    </li>
                </ul>
            {if last_row}
                <select name="shipping_option">
                        {exp:cartthrob:get_shipping_options}
                                <option value="{rate_short_name}" {selected}>{rate_title} - {rate_price}</option>
                        {/exp:cartthrob:get_shipping_options}
                </select>
                <input type="submit" value="Update Cart" />
            {/exp:cartthrob:update_cart_form}
        {/if}
    {/if}
{/exp:cartthrob:cart_items_info}
0

Instead of using:

<option {selected} value="{option_value}">

Use:

<option {if selected}selected{/if} value="{option_value}">

Also, add the row_id parameter to your {exp:cartthrob:item_options} tag.
ie.

{exp:cartthrob:item_options row_id="{row_id}"}
2
  • Unfortunately that didn't work. I added an XL shirt to the cart and viewed the checkout page, but the select dropdown still shows Medium (the default first option) as the selected option, and none of the options have a selected attribute for some reason. It works on my shipping dropdown, but not my item_options dropdown. Is there something maybe in the way I'm rendering it that isn't working? I can output the selected option by my product title if I use {title}, {item_options:product_size} - {item_options:product_size:price} – Alexa L May 14 '13 at 18:03
  • I updated my answer for you. Give that a shot. – Jason Varga May 14 '13 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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