0

I've got a cartthrob site where I have two product channels and then an "on_the_fly" product, where a user will enter their data for account number, price and client fields. Here is my add_to_cart code:

    {exp:cartthrob:add_to_cart_form 
    allow_user_price="yes"    
    entry_id="{entry_id}" 
    on_the_fly="y"
    return="cart"
    tax_exempt="yes"
    title="Online Bill Pay"
    }       
    <input type="text" name="item_options[account_number]" value="" placeholder="Account Number">
    <input type="text" name="price" value="" placeholder="Dollar Amount Owed">
    <input type="text" name="item_options[client]" value="" placeholder="Person Being Served">
    <input type="submit" value="Add to Cart">            
{/exp:cartthrob:add_to_cart_form}

I would assume that would put an item in my cart titled: "Online Bill Pay" with the three options of account_number, price and client appearing in the cart. Only thing that appears in the cart is the title (obviously, its hard-coded) and the price.

And here is my cart template (the switchee conditional is hopefully used to help decipher between my two product channels and the one that I'm adding on the fly) which has no channel name. Perhaps there is a better way to detecting this -- if so I'm open to suggestions.

    {exp:cartthrob:cart_items_info}
    {if no_items}There's nothing in your cart{/if}
    {if first_row}
        {exp:cartthrob:update_cart_form return="/cart/"}
    {/if}
    {exp:switchee variable='{channel_short_name}' parse='inward'}
    {case value='events|workshops'}
        {exp:channel_images:images entry_id="{entry_id}"}
            <img src="{image:url:large}">
        {/exp:channel_images:images}
    {/case}
    {case value=''}
        <img src="image.jpg">
    {/case}
    {/exp:switchee}
    <a href="{exp:switchee variable='{channel_short_name}' parse='inward'}
    {case value='events'}/events/{url_title}{/case}
    {case value='workshops'}/workshops/{url_title}{/case}
    {case value=''}/pay{/case}{/exp:switchee}">{title}</a>
        {if dynamic}
            {exp:cartthrob:item_options row_id="{row_id}"}
                {options}
                    {option_value}
                {/options}
            {/exp:cartthrob:item_options}
        {if:else}
            {summary}
        {/if}
    Quantity: {quantity} @ {item_price}/ea
    <a href="/cart/delete/{row_id}">Remove Item</a>
    <h4>{cart_total}</h4>
{/exp:cartthrob:cart_items_info}

To recap: I'm not getting the item options for account number or client in the add to cart form to show in the cart. In the cart, I'm unable to detect if this is an existing product channel or my on the fly, user-populated product. Can anyone please advise where I'm going wrong? TIA.

0

I don't really see anything that is obviously wrong with your add to cart form. However, I'd like to check that you have the add_to_cart form loaded inside a channel_entries tag. If not, you will be missing an entry_id for the product. Also, do you have products set up via cartthrob's product channel settings? I'm going to assume that you don't because you are using on_the_fly but if you have the same products setup as entries, then I would recommend using them instead of on_the_fly for better control and inventory.

In my case, I build my products out via data from several channels and assign an entry_id in the form itself (via script) so I use a hidden input field name="entry_id" to do so. At the same time, I use a title input field to set the title instead of using the title parameter in the tag. I have a pretty unconventional setup, but since I needed inventory control, I set up products so that I don't need to use on_the_fly.

I do not use switchee but I do something similar in that I have another hidden input name="item_type" that I use to categorize my items. I then have the output tags set to check that field and change the display to fit the item being shown. As I mentioned above, the entry_id, all item_options etc are set to the form based on user input so I use jQuery to manage the input values and set things dynamically.

  • I have two product channels, but the on_the_fly item is not in a channel entry, as it is dynamically created - populated by user input (account_number, price and client). – soire Jul 12 '17 at 16:16

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.