Fetch and display shopping basket of current user

Author Message

Sejal Paliwal

Friday 28 November 2008 2:03:23 am

I used the fetch function as described in the documentation. Have used the following code to display shopping basket of current user on every product page.


{def $basket=fetch( 'shop', 'basket' )}
 
{if $basket.is_empty}
 
    There are no products in the basket.
 
{else}
 
    There are {count( $basket.items )} items in the basket.  <br />
    Total price (ex. VAT) :  {$basket.total_ex_vat|l10n( currency )} <br />
    Total price (inc. VAT):  {$basket.total_inc_vat|l10n( currency )}<br>

     <strong>{$total_inc_shipping_ex_vat|l10n( 'currency', $locale, $symbol )}</strong>
 
{/if}

{undef $basket}

This outputs the result for the first time but when adding more items "i.e after clicking the continue shopping button", the code does not update the count and total from shopping basket.

Please guide me with the code.

Thanks in advance!

Arnaud Lafon

Monday 01 December 2008 4:26:09 am

Hi Sejal,

Are you using this code in the pagelayout (or a template included in) or in the template that is used to display your product (an override of node/view/full.tpl...) ?

Looking for information about SQLI ?
Looking for a new job in Paris ?
Please contact me at alafon [at] sqli [dot] com

Pascal Specht

Monday 01 December 2008 6:41:42 am

Hi Sejal,

try adding this line at the top of your product template:

{set-block scope=global variable=cache_ttl}0{/set-block}

If this works, it means that the data is cached and therefore not updated...

</Pascal>

Sejal Paliwal

Monday 01 December 2008 7:32:44 pm

Yes it works! :)

Thanks a lot!!!

Arnaud Lafon

Tuesday 02 December 2008 1:03:08 am

Hi Sejal,

If disabling view caching is working, this means that your basket fetch is done in a view template (an override of node/view/*.tpl)... If you don't want to experience some performance issues, you should replace your code in the pagelayout or in a template included in...

Also check SQL queries count in the debug.

Regards

Looking for information about SQLI ?
Looking for a new job in Paris ?
Please contact me at alafon [at] sqli [dot] com

Sejal Paliwal

Tuesday 02 December 2008 9:45:08 pm

Hi Arnaud,

As suggested by Pascal, I had added the following code to my node/view/full.product.tpl.

{set-block scope=global variable=cache_ttl}0{/set-block}

And now it is working fine.

You guessed it right that I added the code in the view template.
But, you specified of some performance issues and replace the code in the pagelayout or in a template included. I didnt get to know what to do, being a newbie to eZ Publish.

I would appreciate if you could explain me what is wrong or should I let the code in node/view/full/product.tpl?

Thanks in Advance!

Regards

Arnaud Lafon

Wednesday 03 December 2008 5:00:52 am

Hi Sejal,

If the product pages represent a large proportion of the visited pages on your site, then they will have an impact on your server load. And If these pages, without caching, generates a lot of MySQL queries, then you'll have serious problems... (how many queries do you have in the ezdebug ?). It's common to say that an ez content page with view caching should generate from 2 to 6 sql queries maximum...

Actually, disabling view caching without adding some cache-block isn't a good solution. As far as you're concerned, adding some cache-block won't be a good solution too, cuz you'll have to expire the cache-block each time something is done in the user basket...

So you have 2 solutions :
- doing your basket fetch in the pagelayout.tpl, and doing this not in a cache-block...
- If you want to do your fetch in the content view template, then how about doing this with some ajax ?

Looking for information about SQLI ?
Looking for a new job in Paris ?
Please contact me at alafon [at] sqli [dot] com

Sejal Paliwal

Wednesday 03 December 2008 8:02:27 pm

Hi Arnaud,

Thank you so much for your kind support!

Well, you are right that my count of SQL queries have tremendously increased after disabling the view caching.

So, finally I have pasted the code in the new override for pagelayout.tpl. and thankfully it is working fine.
But, now I have to work on the CSS so as to lay it on a proper position. Is there any way that the fetch basket block and my main content are placed inline?

A part of my pagelayout.tpl ->

 <!-- Main area content: START -->

<div class="rttop">  // positions it on right top corner
<fetch basket code>
</div>
 {$module_result.content}

          <!-- Main area content: END -->

I can only place it either above or below the main area. How can I position it on the top-right area of the main content so that the header of the product class and the block of fetch basket has the same top margin.

Thanks again!

Regards

Arnaud Lafon

Thursday 04 December 2008 2:12:26 am

Sorry Sejal, I'm really bad in CSS :D

Looking for information about SQLI ?
Looking for a new job in Paris ?
Please contact me at alafon [at] sqli [dot] com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.