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.