Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

[mv] Help! Still Lost in Perl



******    message to minivend-users from Chris Rapier <rapier@psc.edu>     ******

> cfm@maine.com wrote:
> 
> > > I'm not exactly a newbie when it comes to perl but using it with
> > > minivend is confusing and frustrating me.
> >
> > Start with $Vend::Session->{'values'} and go from there.
> > Unpack it and see what you have.
> 
> Is this sort of thing in the documentation anywhere or is it just one of
> those things you just infer from the soucre?

Well, once I started actually reading the documentation again I realized
that the data I wanted was actually in the $Items ref. Now I can get
that data but I've more problems...

Synopsis: I need to compare the quantity Q of ITEM in the cart CART with
sku of SKU to the corresponding entry in database PRODUCTS. 
In really bad pseudo code:
if PRODUCTS(SKU(Q)) - CART(SKU(Q)) = 0 
   then 
       delete the record from PRODUCTS with key SKU 
   else 
       decrement PROCDUCTS(SKU(Q) by 1

To do this I've written:

[item-list]
 [perl tables=products]
  $ref = $Db->{products};
  $column = "quantity";
  $cart_sku = $Items->[$i]{'code'};
  $cart_quantity = $Items->[$i]{'quantity'};
  $db_quantity = $ref->field($column, $cart_sku);
  $difference = $db_qauntity - $cart_quantity;
  if ($difference < 0){
     $Items->[$i]{'quantity'} = $db_quantity;
  }
  if ($difference > 0) {
     $ref->inc_field($column, $cart_sku, -1);
  } 
  if ($difference == 0) {
     $ref->delete_record($cart_sku);
  }
  $i++;
 [/perl]
[/item-list]


Obviously this doesn't work. In fact I get an internal server error when
ever I do run it with the error log gving a premature end of headers. If
I comment out the $ref lines then the page is displayed but its
relatively useless to me. Does anyone have an idea what I'm doing wrong?
The $ref lines I got directly from the documentation.
-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: