Forums / Developer / Fetching basket: not for current user, but for current session

Fetching basket: not for current user, but for current session

Author Message

Adolfo Barragán

Wednesday 13 April 2005 5:06:37 am

I need fetch basket for current user, so I use the sample code from http://ez.no/ez_publish/documentation/reference/data_fetching/shop/basket
but this function don't retrieve the basket for current user, it retrieve the basket for current session. If I change user in same session, I always get same basket.

This is my code:
I've create a template to show a box with basket's items (basket_box.tpl) and I included this template in pagelayout:

{set-block scope=root variable=cache_ttl}0{/set-block}
{let mybasket=fetch( 'shop', 'basket')}
  {section show=$mybasket.is_empty|not()}
    <div class="rightbox">
      <h4>Your Basket</h4>
      <div class="rightbox_content">
        {section var=item loop=$mybasket.items}
        <p>{$item.item_count}x {$item.object_name</p>
        {/section}
        <div align="right">
          <form name="basket_box" method="post" action={"/shop/basket/"|ezurl}>
            <input class="button" type="submit" name="CheckoutButton" value="{'Checkout'|i18n('design/standard/shop')}" />
          </form>
        </div>
      </div>
    </div>
  {/section}
{/let}

If I (anonymous user) buy any products, I can see the box. If (before I checkout) I login on site, I can see the box. When I checkout and confirm, the box dissapear. All of this is Ok.

But...
If I don't checkout and I logout, I also see the basket_box. In this case, basket would dissapear (I think)

Also, If I logout (from user A) and I login with another user (user B) I still see the basket box. I think basket would dissapear, because the buy is from user A, not from user B.

What is wrong in my code?

Thanks in advance
Adolfo Barragán

Bård Farstad

Wednesday 20 April 2005 3:06:42 am

Adolfo,

I'm not sure if I follow what you are asking for. But the shopping basket is connected to sessions and not users. E.g. if you add some products to the shopping basket and logs in with another user, then the shopping basket will contain the same products. This is intentional because you are often not logged in when you start to add products in the basket.

I hope this answered your question.

--bård

Documentation: http://ez.no/doc

john polo

Friday 06 January 2006 3:35:56 pm

Basket cannot be linked to user instead of session ?

Reason im asking this is that, what if someother user enters the same site in public pc..those products will be shown again to any user that logs on that site

William Steenbergh

Wednesday 11 January 2006 1:31:24 am

I believe the behavior of the basket should be made an INI-setting or something, with one way working on a per-session base, and the other per-user.

I think it's illogical to begin with, if you look at the default settings in ez Publish's ini files.

Bard said this was so anonymoous shoppers could start shopping and not lose the basket when logging on, but then why is the default set to:

{UserSettings]
RequireLogin=true

??
In this default, the user should always be logged on to even see the site, let alone buy stuff. Considering the default settings, the argumentation for this behavior is not logical (but understandable on the whole, though ;-)).

Please consider making this behavior optional. You will save a lot of us headaches and long nights of kernel hacking.

eZ debug

Timing: Jan 31 2025 01:18:50
Script start
Timing: Jan 31 2025 01:18:50
Module start 'content'
Timing: Jan 31 2025 01:18:50
Module end 'content'
Timing: Jan 31 2025 01:18:50
Script end

Main resources:

Total runtime0.1969 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 588.1875370.2578
Module start 'content' 0.00780.0146 958.44531,005.7500
Module end 'content' 0.02240.1744 1,964.19533,896.0859
Script end 0.1968  5,860.2813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00482.4232200.0002
Check MTime0.00140.6948200.0001
Mysql Total
Database connection0.00090.466710.0009
Mysqli_queries0.098650.09141410.0007
Looping result0.00140.71611390.0000
Template Total0.174088.410.1740
Template load0.00080.431710.0008
Template processing0.173187.922110.1731
Override
Cache load0.00060.293010.0006
Sytem overhead
Fetch class attribute can translate value0.00201.020310.0020
XML
Image XML parsing0.00030.153310.0003
General
dbfile0.00713.6051200.0004
String conversion0.00000.003030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs