Revision 391

Date:
2013/10/30 12:19:06
Author:
ahitrov
Revision Log:
add_wishlist() method
Files:

Legend:

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

     
    59 59 return ($total, $sum);
    60 60 }
    61 61
    62 sub add_wishlist {
    63 my $self = shift;
    64 my $object = shift;
    65 my (%options) = @_;
    66
    67 return unless ref $object;
    68 return unless $object->item_id && $object->number;
    69 return unless $object->uid || $object->session;
    70
    71
    72 my %opts;
    73 if ( $object->uid ) {
    74 $opts{uid} = $object->uid;
    75 } elsif ( $object->session ) {
    76 $opts{session} = $object->session;
    77 }
    78 my @items = $keeper->get_documents (
    79 class => 'webshop::Basket',
    80 status => 0,
    81 order_id=> 0,
    82 %opts,
    83 );
    84 my $total = 0;
    85 my $sum = 0;
    86 my $found = 0;
    87 if ( @items ) {
    88 foreach my $item ( @items ) {
    89 if ( $object->item_id == $item->item_id && $object->color_id == $item->color_id && ($object->size_id == $item->size_id || $object->size eq $item->size) ) {
    90 $item->number($item->number + $object->number);
    91 $item->store;
    92 $found = 1;
    93 }
    94 $total += $item->number;
    95 $sum += $item->number * $item->price;
    96 }
    97 }
    98 unless ( $found ) {
    99 $total += $object->number;
    100 $sum += $object->number * $object->price;
    101 $object->order_id(0);
    102 $object->store;
    103 }
    104 return ($total, $sum);
    105 }
    106
    62 107 ### Метод приведения корзины для пользователя в момент логина
    63 108 #############################################################
    64 109 sub merge_basket {