eZ Community » Forums » General » [Legazy ] Retrieving in basket...
expandshrink

[Legazy ] Retrieving in basket content object value

[Legazy ] Retrieving in basket content object value

Monday 22 September 2014 9:14:20 am - 6 replies

Good morning.

I'm trying to retrieve a content object value, but only can show it and cannot asign to variable in template. I am using old shop basket btw.

If i use:

 {$Basket:ProductItem:item.item_object.contentobject.main_node.data_map.calories.content}

It show the calorie attribute content, but if i use:

 

 
 
{def $calories=0}
 
{set $calories=$Basket:ProductItem:item.item_object.contentobject.main_node.data_map.calories.content }
 
Calories - > {$calories}

Return: Calories -> 0

I try defining calories as integer.... same result.

Any idea?

Thank you very much.

Monday 22 September 2014 10:17:21 am

Hello Hugo,

Thank you for sharing your details and code so well. Sorry your having trouble.

I don't know if it matters much but you have a trailing space in the code example for your 'set' variable definition. You might want to remove that trailing space.

More importantly would you please show your whole loop code as I suspect there is a problem with the placement of your set code either in or outside your loop.

 

Cheers,
Heath 

Monday 22 September 2014 10:32:59 am

Thank you very much // Heat for your answer.

Below is part of code. The line **Calories -> {$calories} must show the field value.

Retrieve basket and show some values:

{def $calories=0}
{def $basket=fetch( 'shop', 'basket' )}

            {section name=Basket show=$basket.items}

            <table class="cart"  width="100%" cellspacing="0" cellpadding="0" border="0">
            {section name=ProductItem loop=$basket.items sequence=array(bglight,bgdark)}
                <tr>
                        <td class="{$Basket:ProductItem:sequence}">
                        <input type="hidden" name="ProductItemIDList[]" value="{$Basket:ProductItem:item.id}" />
                        <div class="cart-item-name">
                            <a href={concat("/content/view/full/",$Basket:ProductItem:item.node_id,"/")|ezurl}>{$Basket:ProductItem:item.object_name|wash}</a>
                        </div>    
                        </td>
                        <td class="{$Basket:ProductItem:sequence}">
                            <div class="cart-item-qty">
                                {set $calories=$Basket:ProductItem:item.item_object.contentobject.main_node.data_map.calories.content}

                                **Calories -> {$calories}

                            </div>
                        </td>

                </tr>
            {/section}
            </table>

            {section-else}

            <div class="feedback">
            <h2>{"You have no products in your cart"|i18n("design/standard/shop")}</h2>
            </div>

            {/section}
            <input type="button" value="{'Edit order'|wash}" onclick="location.href='/shop/basket'"  class="button-edit-order"/>
  

Monday 22 September 2014 3:24:34 pm

Hello Hugo,

Apologies for my late reply.

Please note that use of the 'section' is deprecated and at this late point in time no longer documented: RE: https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-control-structures/Deprecated/section

You should most likely rewrite your code example to use the 'foreach' function instead: https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-control-structures/Looping/foreach

I think the real cause of your problem is your combination of def/set and section. In the older template syntax (that your partially using) you would not need to put $ in-front of {set $calories=1}. Instead you would use {set calories=1} .. weird huh? Also in the older template syntax you would not use 'def' you would use 'let' instead.

https://doc.ez.no/eZ-Publish/Technical-manual/3.6/Reference/Template-functions/Variables/set

https://doc.ez.no/eZ-Publish/Technical-manual/3.6/Reference/Template-functions/Variables/let

I gleamed these ideas from reviewing this template still in the default distribution: https://github.com/ezsystems/ezpublish-legacy/blob/master/design/standard/templates/toolbar/full/basket.tpl

 

Like I said I think your problems go away if you use foreach instead of section.

If you still have problems after rewriting to use foreach instead please let us know.

Cheers,
Heath 

Modified on Monday 22 September 2014 3:24:55 pm by // Heath

Monday 22 September 2014 7:11:55 pm

Thank you very much // Heath for the advise.

I'm having no success with foreach. Some times retrieve array of values but no clue how retrieve field values. I feel like ancient indigenous, shooting arrows at clouds xD

I will present something in a meeting in a couple hours and must stop modifications to code today. Later will test again.

 

Best regards

Tuesday 23 September 2014 4:30:53 pm

Hello Hugo,

I just wanted to check in with you. Where you able to solve your problem?

If not would you please share another copy of your current code that you are working with?

Cheers,
Heath 

Friday 14 November 2014 1:11:33 pm

Hi Hugo,

It's not best practice, but if you just def the node first inside your section you can get the value:

{def $temp_product = fetch(content,node,hash( node_id, $Basket:ProductItem:item.node_id ))}

{def $calories = $temp_product.data_map.calories.content}

**Calories -> {$calories}

Modified on Friday 14 November 2014 1:13:09 pm by Petter Arneson

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from