Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 07b6482f

Von Werner Hahn vor mehr als 6 Jahren hinzugefügt

  • ID 07b6482f47cf5a4f5854480cdec5116eff66db72
  • Vorgänger 6c044ff2
  • Nachfolger 4ff4dc6a

Shopmodul: Test für Shoporders

Unterschiede anzeigen:

SL/ShopConnector/Shopware.pm
4 4

  
5 5
use parent qw(SL::ShopConnector::Base);
6 6

  
7
use SL::DBUtils;
7

  
8 8
use SL::JSON;
9 9
use LWP::UserAgent;
10 10
use LWP::Authen::Digest;
......
42 42
      my $data_json = $data->content;
43 43
      my $import    = SL::JSON::decode_json($data_json);
44 44

  
45
      my $shop_order = $self->map_data_to_shoporder($import);
46

  
47
      $shop_order->save;
48
      $of ++;
49
      my $id = $shop_order->id;
50

  
51
      my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} };
52
      my $position = 1;
53
      foreach my $pos(@positions) {
54
        my $price = $::form->round_amount($pos->{price},2);
55

  
56
        my %pos_columns = ( description          => $pos->{articleName},
57
                            partnumber           => $pos->{articleNumber},
58
                            price                => $price,
59
                            quantity             => $pos->{quantity},
60
                            position             => $position,
61
                            tax_rate             => $pos->{taxRate},
62
                            shop_trans_id        => $pos->{articleId},
63
                            shop_order_id        => $id,
64
                            active_price_source  => $self->config->price_source,
65
                          );
66
        my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
67
        $pos_insert->save;
68
        $position++;
69
      }
70
      $shop_order->{positions} = $position-1;
71
      my $customer = $shop_order->get_customer;
72
      if(ref($customer)){
73
        $shop_order->kivi_customer_id($customer->id);
74
        $shop_order->save;
75
      }
76

  
77
      my $attributes->{last_order_number} = $ordnumber;
78
      $self->config->assign_attributes( %{ $attributes } );
45
      $self->import_data_to_shop_order($import);
46

  
47
      $self->config->assign_attributes( last_order_number => $ordnumber);
79 48
      $self->config->save;
80 49
      $ordnumber++;
50
      $of++;
81 51
    }
82 52
  }
83 53
  my $shop           = $self->config->description;
......
85 55
  return \%fetched_orders;
86 56
}
87 57

  
58
sub import_data_to_shop_order {
59
  my ( $self, $import ) = @_;
60
  my $shop_order = $self->map_data_to_shoporder($import);
61

  
62
  $shop_order->save;
63
  my $id = $shop_order->id;
64

  
65
  my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} };
66
  my $position = 1;
67
  my $active_price_source = $self->config->price_source;
68
  foreach my $pos(@positions) {
69
    my $price = $::form->round_amount($pos->{price},2);
70
    my %pos_columns = ( description          => $pos->{articleName},
71
                        partnumber           => $pos->{articleNumber},
72
                        price                => $price,
73
                        quantity             => $pos->{quantity},
74
                        position             => $position,
75
                        tax_rate             => $pos->{taxRate},
76
                        shop_trans_id        => $pos->{articleId},
77
                        shop_order_id        => $id,
78
                        active_price_source  => $active_price_source,
79
                      );
80
    my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
81
    $pos_insert->save;
82
    $position++;
83
  }
84
  $shop_order->{positions} = $position-1;
85

  
86
  my $customer = $shop_order->get_customer;
87
  if(ref($customer)){
88
    $shop_order->kivi_customer_id($customer->id);
89
    $shop_order->save;
90
  }
91
}
92

  
88 93
sub map_data_to_shoporder {
89 94
  my ($self, $import) = @_;
95

  
90 96
  my $parser = DateTime::Format::Strptime->new( pattern   => '%Y-%m-%dT%H:%M:%S',
91 97
                                                  locale    => 'de_DE',
92 98
                                                  time_zone => 'local'
93 99
                                                );
94 100
  my $orderdate = $parser->parse_datetime($import->{data}->{orderTime});
101

  
102
  my $shop_id      = $self->config->id;
103
  my $tax_included = $self->config->pricetype;
95 104
  # Mapping to table shoporders. See http://community.shopware.com/_detail_1690.html#GET_.28Liste.29
96 105
  my %columns = (
97 106
    amount                  => $import->{data}->{invoiceAmount},
......
152 161
    shop_customer_id        => $import->{data}->{customerId},
153 162
    shop_customer_number    => $import->{data}->{billing}->{number},
154 163
    shop_customer_comment   => $import->{data}->{customerComment},
155
    shop_id                 => $self->config->id,
164
    shop_id                 => $shop_id,
156 165
    shop_ordernumber        => $import->{data}->{number},
157 166
    shop_trans_id           => $import->{data}->{id},
158
    tax_included            => $self->config->pricetype eq "brutto" ? 1 : 0,
167
    tax_included            => $tax_included eq "brutto" ? 1 : 0,
159 168
  );
169

  
160 170
  my $shop_order = SL::DB::ShopOrder->new(%columns);
161 171
  return $shop_order;
162 172
}
......
358 368

  
359 369
=head1 NAME
360 370

  
361
  SL::Shopconnecter::Shopware - connector for shopware 5
371
SL::Shopconnecter::Shopware - connector for shopware 5
362 372

  
363 373
=head1 SYNOPSIS
364 374

  
365 375

  
366 376
=head1 DESCRIPTION
367 377

  
378
=head1 METHODS
379

  
380
=back 4
381

  
382
=item C<import_data_to_shop_order>
383

  
384
Creates on shoporder object from json
385

  
368 386
=head1 TODO
369 387

  
370
  Pricesrules, pricessources aren't fully implemented yet.
371
  Payments aren't implemented( need to map payments from Shopware like invoice, paypal etc. to payments in kivitendo)
388
Pricesrules, pricessources aren't fully implemented yet.
389
Payments aren't implemented( need to map payments from Shopware like invoice, paypal etc. to payments in kivitendo)
372 390

  
373 391
=head1 BUGS
374 392

  
375
  None yet. :)
393
None yet. :)
376 394

  
377 395
=head1 AUTHOR
378 396

  
379
  W. Hahn E<lt>wh@futureworldsearch.netE<gt>
397
W. Hahn E<lt>wh@futureworldsearch.netE<gt>
380 398

  
381 399
=cut

Auch abrufbar als: Unified diff