Revision 524

Date:
2015/11/09 15:16:19
Author:
ahitrov
Revision Log:
Discount made with coupons is counted according item price and item storage if applicable

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/webshop/lib/webshop/Coupon.pm

     
    93 93 return 0 unless ref $basket eq 'ARRAY' && @$basket;
    94 94
    95 95 my ($number, $sum_total) = (0, 0);
    96 map { $number += $_->number; $sum_total += $_->number * $_->price } @$basket;
    96 map { my $price = exists $_->{item} ? $_->{item}->price : $_->price; $number += $_->number; $sum_total += $_->number * $price } @$basket;
    97 97 warn "BASKET: $number Items of $sum_total Value\n";
    98 98
    99 99 my $discount_counted = 0;
     
    119 119 my $found_sum = 0;
    120 120 foreach my $bi ( @$basket ) {
    121 121 warn "BASKET: Basket item id [".$bi->item_id."]\n" if $DEBUG;
    122 next if $bi->special_price;
    122 next if exists $bi->{item} && $bi->{item}->special_price || !exists $bi->{item} && $bi->special_price;
    123 next if exists $bi->{item} && (!$bi->{item}->price || !$bi->{item}->storage);
    123 124 foreach my $item ( @$items) {
    124 125 if ( $bi->item_id == $item->id ) {
    125 126 warn "BASKET: Product [".$item->name."] id [".$item->id."]\n" if $DEBUG;
    126 $found_sum += $bi->number * $bi->price;
    127 $found_sum += $bi->number * (exists $bi->{item} ? $bi->{item}->price : $bi->price);
    127 128 last;
    128 129 }
    129 130 }
     
    136 137 my $found_sum = 0;
    137 138 foreach my $bi ( @$basket ) {
    138 139 warn "BASKET: Basket item id [".$bi->item_id."]\n" if $DEBUG;
    139 next if $bi->special_price;
    140 $found_sum += $bi->number * $bi->price;
    140 next if exists $bi->{item} && $bi->{item}->special_price || !exists $bi->{item} && $bi->special_price;
    141 next if exists $bi->{item} && (!$bi->{item}->price || !$bi->{item}->storage);
    142 $found_sum += $bi->number * (exists $bi->{item} ? $bi->{item}->price : $bi->price);
    141 143 }
    142 144 warn "Sum found: [$found_sum]\n" if $DEBUG;
    143 145 return $self->can_discount( $found_sum );