[ic] Re: adding extra information into the shopping cart structure

John Allman interchange-users@icdevgroup.org
Thu Oct 10 10:20:00 2002


racke@linuxia.de wrote:

> John Allman writes:
>
>>
>> Am i right in thinking that if i want to add a new key and value to 
>> the shopping cart data scructure it is pretty straightforward? I am 
>> considering going with a one shopping basket solution and just having 
>> something on the basket page to indicate that an item ordered was 
>> ordered via the "quick catalog order" option. I'm thinking that it 
>> should be possible for me to put something like quickorder => 1 in 
>> the perl structure and then access it on the basket page with 
>> [item-quickorder]. Am i right in thinking this and if so could you 
>> tell me the correct syntax?
>> i'm thinking maybe something like
>> $lastitem = pop($Session->{carts}->{main});
>> $lastitem->{'quickorder' => 1};
>
>
> I doubt that is valid Perl syntax. Try:
> $lastitem->{quickorder} = 1;
>
>> push($Session->{carts}->{main},$lastitem);
>
>
> Or in the shorthand:
> $Items->[$#$Items]->{quickorder} = 1
>
>>
>> could something like that work and could i access it with 
>> [item-quickorder] on the basket page? is there a better way to do 
>> what i'm looking for?
>
>
> Don't try to invent ITL :-;, give [item-field quickorder] a shot.
> You may need AutoModifier quickorder in the configuration.
> Bye
>     Racke
>
Ok - i'm getting places. i have the following in the page for the quick 
catalog order:

[set altercart]
[perl]
        $Session->{carts}->{main}->[$Tag->nitems(main)-1]->{quickorder}=1;
[/perl]
[/set]

and later:
<input type=hidden name=mv_check value=altercart>

i found that if i put the code in mv_click it wasn't executed before the 
item was added to the cart - but this way seems to work. [dump] reveals 
the following in the  ##### ###### SESSION ##### bit:

'carts' => { 'main' =>  [ { 'spprice' => undef, 'userdiscount' => undef, 
'quickorder' => 1, 'mv_ip' => '0', 'code' => '0115163400', 'size' => 
undef, 'mv_ib' => 'products', 'quantity' => 1, 'color' => undef } ] }

so it looks like quickorder has been added and assigned the value 1. 
good stuff so far.

however i'm having difficulty getting it back out in the basket page. 
[item-field quickorder] returns nothing. i added a line AutoModifier 
quickorder into the catalog.cfg but that doesn't appear to improve 
matters either...

I am a little confused - i thought item-field picked out the value of a 
particular field in the products database for the current item? Also - 
from the AutoModifier page in the docs: "Sets an attribute in a shopping 
cart entry to the field of the same name in the ProductsFile pertaining 
to this item."

but this has nothing to do with the products table - it is only to do 
with the shopping cart?

perhaps there's some way to access the appropriate part of the shopping 
cart in perl? i'm assuming as the basket page iterates through the 
contents of the cart there is some variable which keeps track of the 
current item - a counter or something?

thank you for your help so far - it looks as if this should be possible 
and i'm almost there - can you suggest anything else?

thanks

John Allman