Randomness (RE: [Zope-dev] CoreSessionTracking 0.8)

Bjorn Stabell bjorn@exoweb.net
Fri, 25 May 2001 21:45:29 +0800


Chris McDonough:
[...]
> weeping (although grateful for the exchange),

I'm sorry Chris.  We didn't give you a very good debugging chase.  I
know how frustrating bug reports like "Help! It doesn't work" is, but I
guess it's very hard to troubleshoot bugs in frameworks since there's so
much customized code in there.

To be a little bit more helpful I've included two functions:

cart_add(sku, qty) (Python Script)
	This function adds qty amount of a skus (integer id for product
items) to the cart

cart_display (DTML Method)
	This method displayes the cart

The bug appears even when these two functions are the only functions
interacting with the session and the shopping.  There are obviously some
references to code not provided in there, so don't expect them to work
just like that.  If you can't see anything wrong from a simple code
inspection, I volounteer to provide the whole site for you.

It's quite refreshing to do a project for a sandwich shop, like we do
now, but I hope we can get to the bottom of these disappearing cokes. :)

Thank you for all the help.  Open source sure beats the heck out of
commercial solutions when it comes to support.

Bye,
--=20
Bjorn Stabell <bjorn@exoweb.net>




cart_add(sku, qty)
_______________

session =3D context.session_mgr.getSessionData()

cart =3D session.get('shopping_cart', {})

sku =3D int(sku)

if not cart.has_key(sku):
  cart[sku] =3D 0

if int(qty)>0:=20
   cart[sku] =3D cart[sku] + int(qty)

session.set('shopping_cart', cart)

container.cart_recalculate()

context.REQUEST.RESPONSE.redirect(context.REQUEST['HTTP_REFERER'])













cart_show()
_______________

<dtml-call "REQUEST.set('totalprice',0)">
<dtml-comment>
Session token key, value: <dtml-var "session_mgr.getTokenKey()">,
<dtml-var "session_mgr.getToken()"><br>
</dtml-comment>

<dtml-let cart=3D"session_mgr.getSessionData().get('shopping_cart', =
{})">

<dtml-if "cart.keys()">

<dtml-in "cart.keys()" sort>
 <dtml-if sequence-start>
  <table border=3D"0" cellspacing=3D"0" cellpadding=3D"0" =
width=3D"100%">
   <tr>=20
    <td bgcolor=3D"#FFDAAB">=20
     <form action=3D"cart_change" method=3D"post">
      <table width=3D"100%" border=3D"0" cellspacing=3D"1" =
cellpadding=3D"2"
align=3D"center">
       <tr>=20
        <td colspan=3D"2" bgcolor=3D"#006633" =
class=3D"pagetitle"><dtml-var
"gettext('Order Bag')"></td>
       </tr>
       <tr>=20
        <td><dtml-var "gettext('Category')"></td>
        <td align=3D"right" width=3D"20%"><dtml-var =
"gettext('Qty')"></td>
       </tr>
  </dtml-if sequence-start>              =20

  <dtml-let shop_item=3D"get_shop_item(_['sequence-item'])">
   <tr valign=3D"top">=20
    <td bgcolor=3D"#FFFFFF">
    <!--dtml-var "shop_item.Description()"-->=20
    <dtml-var "shop_item.Title()">
    <a href=3D"cart_rm?sku=3D&dtml-sequence-item;"><dtml-var
"gettext('remove')"></a>
    <dtml-comment>
     <!--dtml-var "shop_item.absolute_url()" html_quote-->
    <a href=3D"cart_rm?sku=3D&dtml-sequence-item;">remove</a>
    <!--dtml-var "shop_item.price">
    </dtml-comment>
    <dtml-let qty=3D"_.int(cart[_['sequence-item']])">
    <dtml-call "REQUEST.set('totalprice', totalprice + shop_item.price *
qty)">
    </td>  =20
    <td nowrap bgcolor=3D"#FFFFFF"><input type=3D"hidden" =
name=3D"skus:list"
value=3D"&dtml-sequence-item;">
    <input type=3D"text" name=3D"sku_&dtml-sequence-item;:int"
value=3D"<dtml-var "cart[_['sequence-item']]">" size=3D"1">
    </td>
    </dtml-let>
    </dtml-let>
   </tr>
   <dtml-if sequence-end>     =20
     <tr valign=3D"top">=20
     <td colspan=3D"2" align=3D"right" class=3D"RMB"
bgcolor=3D"#FFFFCC"><dtml-var "gettext('TOTAL')">=20
     <dtml-var
"_.int(session_mgr.getSessionData().get('shopping_cart_amount', 0))">
     </td>
     </tr>
     <tr valign=3D"top">=20
     <td colspan=3D"2" bgcolor=3D"#FFFFFF">
<b><dtml-var "gettext('Bonus points')"></b> <br>
<dtml-var "gettext('This order is worth')"> <dtml-var
"_.int(session_mgr.getSessionData().get('shopping_cart_bonus', 0))">
                      <br>
=20
       <dtml-unless "portal_membership.isAnonymousUser()">
                        <dtml-var "gettext('Bonus points to spend')">
<dtml-var "_.int(member.bonus_points)">
       </dtml-unless>
      =20
     </td>
     </tr>
     <tr valign=3D"top">=20
      <td colspan=3D"2" bgcolor=3D"#FFFFFF">=20
       <input type=3D"submit" name=3D"Submit" value=3D"<dtml-var
"gettext('update')">">
       <a href=3D"orderForm"><dtml-var "gettext('Checkout')"></a> </td>
     </tr>
    </table>
   </td>
   </tr>
   </table></dtml-if sequence-end>

  <dtml-else>
    Empty
  </dtml-in>
</form>

</dtml-if>
</dtml-let>