Revision 839
- Date:
- 2022/01/08 11:44:24
- Files:
Legend:
- Added
- Removed
- Modified
-
utf8/plugins/webshop/lib/webshop/Coupon.pm
164 164 } 165 165 166 166 167 ############################### 168 # Проверка доступности по объекту сессии. В случае конфликта 169 # возвращает 0, иначе 1. 170 ########################################################### 171 sub is_accessible 172 { 173 my $self = shift; 174 my $session = shift; 167 175 176 if ( !$self->accessible ) { 177 return 1; 178 } 179 if ( !ref $session ) { 180 return !$self->accessible || $self->accessible == 1 ? 1 : 0; 181 } 182 if ( $session->get('company_id') && $self->accessible == 2 || !$session->get('company_id') && $self->accessible == 1 ) { 183 return 1; 184 } 168 185 186 return 0; 187 } 188 189 169 190 #sub table_links 170 191 #{ 171 192 # return [ -
utf8/plugins/webshop/lib/webshop/Keeper.pm
465 465 source_id => 0, 466 466 return_mode => 'array_ref', 467 467 ); 468 my %cids = map{ $_->dest_id => 1 } (@items, @$merge_to); 469 my @cids = keys %cids; 470 my $coupons = @cids ? $keeper->get_documents( 471 class => 'webshop::Coupon', 472 id => \@cids, 473 return_mode => 'hash_ref', 474 ) : {}; 468 475 my %merge_to; 469 476 foreach my $link ( @$merge_to ) { 470 if ( exists $merge_to{$link->dest_id} ) { 477 my $coupon = $coupons->{$link->dest_id}; 478 if ( !ref $coupon || !$coupon->is_accessible($opts{session}) ) { 471 479 $link->delete; 480 } elsif ( exists $merge_to{$link->dest_id} ) { 481 $link->delete; 472 482 } else { 473 483 $merge_to{$link->dest_id} = $link; 474 484 } 475 485 } 476 486 foreach my $item ( @items ) { 477 if ( exists $merge_to{$item->dest_id} ) { 487 my $coupon = $coupons->{$link->dest_id}; 488 if ( !ref $coupon || !$coupon->is_accessible($opts{session}) ) { 489 $link->delete; 490 } elsif ( exists $merge_to{$item->dest_id} ) { 478 491 $item->delete; 479 492 } else { 480 493 $item->session( undef ); … … 567 580 return ($discount_sum, $discount_payment, $summarize); 568 581 } 569 582 583 584 ### Метод проверки и получения списка доступных купонов 585 ############################################################# 570 586 sub check_coupons { 571 587 my $self = shift; 572 588 my (%opts) = @_; … … 575 591 my %dopts; 576 592 if ( exists $opts{uid} && $opts{uid} ) { 577 593 $dopts{luid} = $opts{uid}; 578 } else { 579 $dopts{lsession} = $opts{session}; 594 } elsif ( ref $opts{session} ) { 595 $dopts{lsession} = $opts{session}->_session_id; 580 596 } 581 597 my $basket = exists $opts{basket} ? $opts{basket} : $self->get_basket( %opts, with_products => 1 ); 582 598 return (0, []) unless ref $basket eq 'ARRAY' && @$basket; … … 593 609 %dopts, 594 610 ); 595 611 return (0, []) unless @coupons; 596 my @usable = grep { $_->discount } @coupons; 612 my @usable = grep { $_->discount && $_->is_accessible($opts{session}) } @coupons; 597 613 warn "We count on ".scalar(@usable)." coupons: [".join(', ', map { $_->id.'. '.$_->name } @usable)."]\n" if $DEBUG; 598 614 my ($total, $sum) = $self->basket_count( \@basket ); 599 615 return (0, \@usable) unless $sum; … … 642 658 } 643 659 644 660 661 ### Метод проверки и регистрации купона по введенному коду. 662 # Код не чувствителен к регистру. 663 ############################################################# 645 664 sub register_coupon { 646 665 my $self = shift; 647 666 my ($code, $session) = @_; … … 701 720 ilike => 1, 702 721 ); 703 722 } 704 if ( ref $coupon ) { 723 if ( ref $coupon && $coupon->is_accessible($session) ) { 705 724 if ( $coupon->uid && $coupon->status == 3 ) { 706 725 $result{error} = 'Купон уже использован'; 707 726 }