3

Following Store official documentation I'm trying to include the content of some custom fields inside my {exp:store:checkout}{/exp:store:checkout} tags. According to the docs:

Inside the {items} loop, you can use the following variables.

entry_id

The entry id of this item. If you need to access other custom fields associated with this item, you can feed the entry id into a channel entries loop:

{items} {exp:channel:entries entry_id="{entry_id}"} {my_custom_field} {/exp:channel:entries} {/items}

So I tried to use the following code:

{items}
            <tr class="item_row">
                <td class="item">
                {exp:channel:entries channel='books' entry_id='{entry_id}'} 

                {book_author}


                {/exp:channel:entries}      
                    <h4><a href="{path='store/product'}/{url_title}">{title}</a> </h4>

                </td>
                <td class="price">{price}</td>
                <td class="qty"><input name="items[{key}][item_qty]" value="{item_qty}" class="input-mini" /></td>
                <td style="text-align:right" >{item_subtotal}</td>
            </tr>
        {/items}

but the content of the {book_author} custom field doesn't show up. Switching the template debug on I can see that the entry_id is retrieved:

 `{exp:channel:entries channel='books' entry_id='30'}
(0.075356 / 7.57MB) Closing Tag Found
(0.075517 / 7.59MB) Tag: {exp:channel:entries channel='books' entry_id='35'}
(0.075568 / 7.57MB) Closing Tag Found`

so everything looks ok, but a few lines below I read:

(0.093014 / 9.06MB) Calling Class/Method: Channel/entries
(0.093276 / 9.06MB) -> Class Called: Channel
(0.095509 / 9.22MB) -> Method Called: entries
(0.116360 / 10.72MB) Returning No Results Content
(0.116438 / 10.72MB) -> Data Returned

I also tried to use CE_image plug-in to put a tumbnail inside the checkout page, but the plug-in tag is not processed, and the plugin's own debug details don't show-up either.

All the other product details show-up so the {exp:store:checkout} tag seems to work, that is all the details that are not called inside the exp:channel:entries loop.

Is there a reason why the code above doesn't work?

  • Hmm, that should definitely work, and there are no bugs I'm aware of which might cause this. Can you try distilling your template down until you find the simplest possible template which doesn't work? Are you using any caching at all? Is your product definitely in the books channel? (try removing the channel parameter). If you put {entry_id} in the template right above your channel entries tag, does it output the expected entry ID? – Adrian Macneil Jan 30 '13 at 16:52
  • 1
    I am having the same issue as the OP. I have no caching, I've tried removing the channel parameter, and if I put {entry_id} above the channel entries tag, it outputs the expected entry ID. – Keely Feb 1 '13 at 23:31
  • @Keely I meant add a comment, not answer. I've converted your answer to a comment now. – Adrian Macneil Feb 2 '13 at 3:33
  • Sorry if it took me a while to reply, but I had to meet a deadline and couldn't test the suggested solutions. First: as @Keely pointed out putting the {entry_id} variable before the channel entries tag, outputs the right ID. However the entry id/s was/were correctly retrieved anyway, as my debug log shows. The problem seem to show up only with custom fields. Regarding the channel parameter: removing it as @AdrianMacneil suggested didn't make any difference. As a matter of fact I added the channel par. 'cause the example from the doc didn't work. – kikaweb Feb 3 '13 at 17:25
  • Which version of ExpressionEngine are you using? I've heard some reports of bugs with template parsing in versions < 2.5.5 – Adrian Macneil Feb 4 '13 at 6:08
1

Generally speaking, I've noticed that order can be really important with placing a channel entries loop inside of another tag. I believe the {exp:channel:entries} info should come right after the {item} tag. I'm not certain if you need the channel='books' tag. It should be fine, but try it without first, then if that works, go back and add it.

Having it, generally reduces the number of queries the channels tag needs to make, but since the items embedded, it could cause issues. So start without, then add.

{items}
    {exp:channel:entries entry_id='{entry_id}'} 
    <tr class="item_row">
        <td class="item">
            <h4><a href="{path='store/product'}/{url_title}">{title}</a> </h4>
            {book_author}
        </td>
        <td class="price">{price}</td>
        <td class="qty"><input name="items[{key}][item_qty]" value="{item_qty}" class="input-mini" /></td>
        <td style="text-align:right" >{item_subtotal}</td>
    </tr>
    {/exp:channel:entries}   
{/items}

Otherwise, it's just that you need the full record outputted for the {items} tag, which includes the price, quantity, and subtotal lines. Otherwise, your breaking the order.

Give that a try and see what happens.

  • 1
    Thanks for the suggestion @nonprofit_tech but I'm not sure I see your point: are you saying that I should call for all the variables and in a precise order? I tried using your example, unfortunately with no results. The channel parameter doesn't seem to make any difference though, and since the entry_id is parsed even without it I removed it. – kikaweb Feb 3 '13 at 17:41
  • Not exactly. In your example, the {exp:channel:entries} tag, broke of components of the {item}{/item} tags. For each item, I believe everything within the {item}{/item} repeats, so your placement of the channels tag, would attempt to create an author loop, within a single {item}, not for 'ALL' items. Also, if this didn't work, you probably need to back out, and show the code before the {items}{/items} tag. Because I tested against a current Store install, and it worked well. It's possibly something pre- or post - {items} causing the problem. – nonprofit_tech Feb 3 '13 at 19:09
  • Thanks for your explanation @nonprofit_tech : now I understand what you mean. Yes, showing everything outside the {items}{/items} tag seems to be the only option for the moment, but I'll have to re-engineer the whole code. – kikaweb Feb 4 '13 at 20:51
1

I had similar issue and solution was to add status="not closed" to the exp:channel:entries tag from where I had pulled custom fields (GRID in my case)

Simple code:

{exp:store:checkout form_class="form-horizontal"}

                {items}
                    *Some code here*
                     {exp:channel:entries channel="products" status="not closed" dynamic="no" entry_id="{entry_id}"}
                      *Custom field code here*
                      {/exp:channel:entries}
                {/items}

{/exp:store:checkout}
0

It's quite likely this is a problem with parse order.

The easiest way to check for/avoid parse order issues is to use an embed:

{items}
    {embed="store/.checkout_item" entry_id="{entry_id}"}
{/items}

and in your store/.checkout_item template:

{exp:channel:entries entry_id="{embed:entry_id}"}
    {book_author}
{/exp:channel:entries}      

This works because embed tags are parsed after everything else in the template (so you can be sure the {entry_id} will be passed to that tag correctly). The store/.checkout_item template is parsed completely separately, so you won't run into any issues caused by nesting too many tags.

  • Hi @Adrian, thanks for the suggestion. I tried to use this solution using the sample 'checkout' template that comes with Store install, since it's quite minimal and there's no other tag that could cause incompatibility issues. However I still have the same problem: entry ID is correctly parsed (I can see it in the template debug log) but no custom field content seems to be parsed 'cause I can't see it in the log. – kikaweb Feb 3 '13 at 17:37

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.