286070; $::g_pAdjustmentFunctions = { 'GetAdjustmentRules' => \&GetAdjustmentRules, 'CalculateProductAdjustment' => \&CalculateProductAdjustment, 'CalculateOrderAdjustment' => \&CalculateOrderAdjustment, }; sub GetAdjustmentRules { my (%hashAdjustmentRules); my $sKey; foreach $sKey (keys %{$::g_pDiscountBlob}) { if ($sKey eq 'VERSION') { next; } my @arrAdjustment; my $sName = sprintf("%sADJUST_%s", $::g_pDiscountBlob->{$sKey}->{'TYPE'} == 0 ? "ORDER_" : "", $sKey); push @arrAdjustment, $::g_pDiscountBlob->{$sKey}->{'REWARDS'}; push @arrAdjustment, $::g_pDiscountBlob->{$sKey}->{'DESCRIPTION'}; push @arrAdjustment, $::eAdjTaxProRataAdjusted; push @arrAdjustment, ""; push @arrAdjustment, $::g_pDiscountBlob->{$sKey}->{'BASIS'}; $hashAdjustmentRules{$sName} = \@arrAdjustment; } return($::SUCCESS, '', \%hashAdjustmentRules); } sub CalculateProductAdjustment { my ($pitemProductDetail, $nQuantity, $nAdjustableAmount, $phashAdjustmentRules) = @_; my @arrAdjustments; my $sKey; foreach $sKey (keys %{$pitemProductDetail->{CUSTOMVARS}}) { if($sKey =~ /^ADJUST_/ && defined $$phashAdjustmentRules{$sKey}) { my $parrAdjustmentRule = $$phashAdjustmentRules{$sKey}; my $nAdjustment = $parrAdjustmentRule->[0]; if($nAdjustment =~ /%$/) { $nAdjustment =~ s/%$//; $nAdjustment = $nAdjustableAmount * $nAdjustment / 100; my $nRound = ($nAdjustment < 0) ? -0.5 : 0.5; $nAdjustment = int($nAdjustment + $nRound); } my $nQualifyingQuantity = int(($nQuantity / 2) + 0.4); if($nQualifyingQuantity > 0) { my @arrAdjustment = ($pitemProductDetail->{"REFERENCE"}, $parrAdjustmentRule->[1], $nAdjustment * $nQualifyingQuantity, $::eAdjTaxAsProduct); push @arrAdjustments, \@arrAdjustment; } } } return($::SUCCESS, '', \@arrAdjustments); } sub CalculateOrderAdjustment { my ($parrOrderTotals, $phashAdjustmentRules) = @_; my @arrAdjustments; my $sKey; foreach $sKey (keys %$phashAdjustmentRules) { if($sKey =~ /^ORDER_ADJUST_/) { my $parrAdjustmentRule = $$phashAdjustmentRules{$sKey}; if(($parrAdjustmentRule->[4] <= 2 && scalar(@$parrOrderTotals) == 2)) { my $nTotal; my $nAdjustable; if (defined $parrAdjustmentRule->[4]) { if ($parrAdjustmentRule->[4] == 0) { $nTotal = $parrOrderTotals->[1][0]; $nAdjustable = $nTotal; } elsif ($parrAdjustmentRule->[4] == 1) { $nTotal = $parrOrderTotals->[1][0] + $parrOrderTotals->[1][3] + $parrOrderTotals->[1][4]; $nAdjustable = $parrOrderTotals->[1][0]; } elsif ($parrAdjustmentRule->[4] == 2) { if ($parrOrderTotals->[1][5]) { $nTotal = $parrOrderTotals->[1][0] + $parrOrderTotals->[1][1] + $parrOrderTotals->[1][2]; $nAdjustable = $parrOrderTotals->[1][0]; } } } my $nAdjustment; if (ref($parrAdjustmentRule->[0]) eq 'HASH') { my $nCartValue; foreach $nCartValue (sort {$b <=> $a} keys %{$parrAdjustmentRule->[0]}) { if ($nCartValue <= $nTotal) { $nAdjustment = $parrAdjustmentRule->[0]->{$nCartValue}; last; } } } else { $nAdjustment = $parrAdjustmentRule->[0]; } if($nAdjustment =~ /%$/) { $nAdjustment =~ s/%$//; $nAdjustment = $nAdjustable * $nAdjustment / 100; my $nRound = ($nAdjustment < 0) ? -0.5 : 0.5; $nAdjustment = int($nAdjustment + $nRound); } my @arrAdjustment = ($parrAdjustmentRule->[1], $nAdjustment, $parrAdjustmentRule->[2], $parrAdjustmentRule->[3], $parrAdjustmentRule->[4]); if ($nAdjustment != 0) { push @arrAdjustments, \@arrAdjustment; } } } } return($::SUCCESS, '', \@arrAdjustments); } 1;