Akopia Akopia Services

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

[mv] Deleting entries from a database



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

I need to remove entire entries from a database when the quantity of 
that item reaches zero. To handle this I've used the following code:

[item-list]
 [perl tables="products"]
  $Document->hot(1); #debug statement
  $ref = $Db{products}; #set reference
  $column = "quantity"; #only column we care about
  $cart_sku = $Items->[$i]{'code'}; #get the product code from the cart
entries
  $cart_quantity = $Items->[$i]{'quantity'}; #find the amount they
ordered
  $db_quantity = $ref->field($cart_sku, $column); #find how many are
actually in stock
  $difference = $db_quantity - $cart_quantity; # we can do everythign
based on this
  if ($difference > 0) { #greater than zero means they haven't ordered
them all
    $ref->inc_field($column, $cart_sku, ((-1)*$cart_quantity));
#decrement by amount in cart
  $Document->write("hit on diff &gt zero<br>"); #debug statement
  } 
  if ($difference == 0) { #if its zero then they got the last one
    $ref->delete_record($cart_sku); #delete the record from the database
  $Document->write("hit on diff = zero<br>"); #debug statement
  }
  $i++; #increment for next item in the cart
 [/perl]
[/item-list]

Hopefully the comments didn't wrap too badly. The means to decrement and
delete records came from the documentation regarding Minivend perl
objects. I know that the example in the documentation at
http://www.minivend.com/minivend/minivend.html#MiniVend_Perl_Objects
has at least one bug in it ($ref = $Db->{products} should be
$ref=$Db{products}). Can anyone point out what I am doing wrong? I know
I am getting values out of the 'products' table because the debug
statements do work. So... anyone have any ideas? Another bug or am I
unclear on the concept?
-
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: