Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Interchange: users

Modify my modifier ?

 

 

Interchange users RSS feed   Index | Next | Previous | View Threaded


db at m-and-d

Mar 15, 2012, 7:10 AM

Post #1 of 4 (341 views)
Permalink
Modify my modifier ?

Hi - I currnetly have the below code in place and it works well. If an
item in the products table has value 1 in the heavy column, an extra
charge is added the the cost of shipping.

===================================================

## add fee for items tagged heavy in products table
AutoModifier heavy

Variable HEAVY_FEE 7.95

Sub custom_shipping <<EOS
sub {
my ($final, $mode, $opt, $o) = @_;

$final += $Variable->{HEAVY_FEE}
if grep {$_->{heavy}} @$Items;

return $final;
}
EOS

SpecialSub shipping_callout custom_shipping

===================================================

I'd like to extend this a bit so that I can choose bewteen two or more
different charges depending on the value of the 'heavy' field. For
exmaple add HEAVY_FEE if heavy=1, or add HEAVY_FEE_2 if heavy=2. I don't
remember where this code came from but I probably didn't write it. If I
had, I'd likely know how to modify it ;) If anyone can provide a hint
I'd be grateful.

DB

_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users


racke at linuxia

Mar 15, 2012, 7:27 AM

Post #2 of 4 (330 views)
Permalink
Re: Modify my modifier ? [In reply to]

On 03/15/2012 03:10 PM, DB wrote:
> Hi - I currnetly have the below code in place and it works well. If an
> item in the products table has value 1 in the heavy column, an extra
> charge is added the the cost of shipping.
>
> ===================================================
>
> ## add fee for items tagged heavy in products table
> AutoModifier heavy
>
> Variable HEAVY_FEE 7.95
>
> Sub custom_shipping<<EOS
> sub {
> my ($final, $mode, $opt, $o) = @_;
>
> $final += $Variable->{HEAVY_FEE}
> if grep {$_->{heavy}} @$Items;
>
> return $final;
> }
> EOS
>
> SpecialSub shipping_callout custom_shipping
>
> ===================================================
>
> I'd like to extend this a bit so that I can choose bewteen two or more
> different charges depending on the value of the 'heavy' field. For
> exmaple add HEAVY_FEE if heavy=1, or add HEAVY_FEE_2 if heavy=2. I don't
> remember where this code came from but I probably didn't write it. If I
> had, I'd likely know how to modify it ;) If anyone can provide a hint
> I'd be grateful.

Just loop through the items and determine the highest value of heavy.
Take this maximum to pick the variable you need.

Regards
Racke


--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team


_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users


db at m-and-d

Mar 15, 2012, 9:03 AM

Post #3 of 4 (330 views)
Permalink
Re: Modify my modifier ? [In reply to]

> Just loop through the items and determine the highest value of heavy.
> Take this maximum to pick the variable you need.
>
> Regards
> Racke
>
>
> --
> LinuXia Systems => http://www.linuxia.de/
> Expert Interchange Consulting and System Administration
> ICDEVGROUP => http://www.icdevgroup.org/
> Interchange Development Team

Here is my feeble attempt which seems to not do anything. Does anyone
see what may be wrong with this (in between fits of laughter of course)?


## add fee for items tagged heavy in products table
AutoModifier heavy

Variable HEAVY_FEE 7.95
Variable HEAVY_FEE_2 8.95

Sub custom_shipping <<EOS
sub {
my ($final, $mode, $opt, $o) = @_;

my $additional_fees = 0;

for my $item (@$Items) {
next unless $item->{heavy};
my $quantity = $item->{quantity} || 1;
my $heavy = $item->{heavy};
my $heavy_fee=0;

if ($heavy==1) {
$heavy_fee = $Variable->{HEAVY_FEE};
}

if ($heavy==2) {
$heavy_fee = $Variable->{HEAVY_FEE_2};
}

my $item_fee = $quantity * $heavy_fee;

$additional_fees += $item_fee;
}

$final += $additional_fees;

return $final;
}
EOS

_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users


db at m-and-d

Mar 15, 2012, 9:11 AM

Post #4 of 4 (330 views)
Permalink
Re: Modify my modifier ? [In reply to]

>> Just loop through the items and determine the highest value of heavy.
>> Take this maximum to pick the variable you need.
>>
>> Regards
>> Racke
>>
>>
>> --
>> LinuXia Systems => http://www.linuxia.de/
>> Expert Interchange Consulting and System Administration
>> ICDEVGROUP => http://www.icdevgroup.org/
>> Interchange Development Team
>
> Here is my feeble attempt which seems to not do anything. Does anyone
> see what may be wrong with this (in between fits of laughter of course)?
>
>

Grrr - nevermind it does work :) The problem was a stupid typo.

DB

_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users

Interchange users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.