Revision 802

Date:
2020/08/18 18:06:27
Author:
ahitrov
Revision Log:
Мерж корзины с учетом товаров

Files:

Legend:

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

     
    128 128 uid => $opts{uid},
    129 129 );
    130 130 my ($basket_total, $basket_sum, $wishlist_total, $wishlist_sum) = (0,0,0,0);
    131 my %p_ids = map { $_->item_id => 1 } (@items_user, @items_session);
    132 my @p_ids = keys %p_ids;
    133 my $products = @p_ids ? $keeper->get_documents(
    134 id => \@p_ids,
    135 class => $state->{webshop}->{item_document_class},
    136 return_mode => 'hash_ref',
    137 ) : {};
    138
    131 139 foreach my $item ( @items_user ) {
    140 my $product = exists $products->{$item->item_id} ? $products->{$item->item_id} : undef;
    132 141 my ($item_from_session) = grep {
    133 142 $_->item_id == $item->item_id
    134 143 && $_->status == $item->status
     
    140 149 if ( ref $item_from_session ) {
    141 150 warn "Merge basket: Found identical item id=".$item_from_session->id."\n" if $DEBUG;
    142 151 $item->number( $item->number + $item_from_session->number );
    143 $item->price( $item_from_session->price );
    152 $item->price( ref $product ? $product->price : $item_from_session->price );
    144 153 $item->store;
    145 154 $item_from_session->status(-1);
    146 155 $item_from_session->delete;
     
    154 163 }
    155 164 }
    156 165 foreach my $item ( @items_session ) {
    166 my $product = exists $products->{$item->item_id} ? $products->{$item->item_id} : undef;
    157 167 if ( $item->status > 0 ) {
    158 168 $item->session(undef);
    159 169 $item->uid( $opts{uid} );
    170 if ( ref $product ) {
    171 $item->price( $product->price );
    172 }
    160 173 $item->store;
    161 174 if ( $item->status == 1 ) {
    162 175 $basket_total += $item->number;