Akopia Akopia Services

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

Re: [mv] Deleting entries from a database



******    message to minivend-users from Murray Gibbins <murray@scotweb.ltd.uk>     ******

Chris Rapier wrote:
> 
> ******    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:
>

Hi, i'm working on a simular problem.
i'm creating a mall from many shops we originally had in minivend 3 but
are moving to minivend4

To preserve the basket structure for each shop I've loopped over the
baskets then displaying an order for example.
In each loop I display all the products from each basket. However
regardless of which basket I'm in Minivend4's '[quantity-name]' tag just
puts out 'quantity[num]' . This means I can end up with serveral
products all in different baskets that have the same form-name for
different quanities.

I've been looking for a perl solution and have so far come up with this
- 

[perl]

# ok lets get the carts we are going to run over

my $carts = $CGI->{'carts'};
my @carts = split("_",$carts);

foreach my $cart (@carts){

  # the numbers that are attached to the 
  # cart name.
  # it is likly that he numbers will be 
  # letters so we don't get confused
  # with the quanities.
  # These numbers will relate to the
  # 'mv_ip' numbers

  # i.e. cameronsquare.a_qw_s
  # 

  my $numbers = $CGI->{$cart."numbers"};
  my @numbers = split("_",$numbers);

  foreach my $num (@numbers){

    # defines the quanitiy of 
    # product.

    my $quanitity  = $CGI->{$cart."quantity".$num};
    
    $Carts->{$cart}[$num]{'quantity'} = $quanitity;
    
  }
}



#$Carts->{heritagepark}[0]{'quantity'} = '0';
return ;
[/perl]

This is experimental !

I pass the carts in a CGI variable set on the preceding page. ALong with
the quanitites for each item.
However this does tend to set the session database in ways that Minivend
does not do internaly. I.e the first 'mv_ip' attribute of the carts'
anonymous array in the session data base is set to "1" not "0". 
Minivend normally increments each "mv_ip" value in the db incrementally
from "0".

ie the prefered state of the session db for the carts is

'carts' => {
    'mv_shipping' => undef,
    'main' => [],
    'basket_one' => [],
    'basket_two' => [
      {
        'format' => 'design_one',
        'design' => undef,
        'code' => 'B40',
        'mv_ip' => 0,
        'mv_ib' => 'products',
        'quantity' => '1'
      }
],
    [ {
        'format' => 'design_one',
        'design' => undef,
        'code' => 'B41',
        'mv_ip' => 1,
        'mv_ib' => 'products',
        'quantity' => '1'
      },
 ],
   [ {
        'format' => 'design_one',
        'design' => undef,
        'code' => 'B42',
        'mv_ip' => 2,
        'mv_ib' => 'products',
        'quantity' => '1'
      },
 ],

  }

however manually setting the quanity of the secound product in
basket_two to "0" does not remove the product from the next basket
display page (Where is comes up with quanitity 0) it does remove it
after clicking 'recalulate' again. But can end up with the cart array
looking like this---
'carts' => {
    'mv_shipping' => undef,
    'main' => [],
    'basket_one' => [],
    'basket_two' => [
      {
        'format' => 'design_one',
        'design' => undef,
        'code' => 'B42',
        'mv_ip' => 2,
        'mv_ib' => 'products',
        'quantity' => '1'
      },
 ]

  }

Which can't be healthy.
One posible solution may be to use perl to run throug hthe carts array
looking for the hashes with quantity set to zero and using "splice" to
remove them. Then you would have to run through the array again in order
to reset the "mv_ip"'s.

This is what I'm going to try now. I just wish there was a tag for it.
I've only been using Minivend for a month so I'm quite new to it. Having
a back-ground in perl has helped. If you find a better solution I'd love
to her it :-)

What I'd like to see is a 'cart' attribute for the 'list' tags i.e.

[quantity-name] -> [quantity-name cart="cart_name"]

etc.

If this is already implemented it is not i the documentation.
And i've tried setting the [cart] at the top of the loop this has not
helped.

Yours

Murray

-- 
  ____
  \__/    Murray Gibbins             murray@scotweb.ltd.uk
  /  \    Programmer
_ \__/ _  ================================================
\\ || //  Scotweb Limited,             info@scotweb.ltd.uk
 \\||//   13a Albert Terrace,    http://www.scotweb.ltd.uk
  \||/    Edinburgh EH10 5EA   Tel: +44 (0)  131 270 82 33
   ||     Scotland. Europe.    Fax: +44 (0) 7020  93 49 04
-
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: