Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f3837cad

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID f3837cad5560781e6df269cd074c6ca22a7ec312
  • Vorgänger 6abedbe4
  • Nachfolger 72903759

Connector angepasst

Conflicts:
SL/ShopConnector/Shopware.pm

Unterschiede anzeigen:

SL/ShopConnector/Shopware.pm
1
package SL::ShopConnector::Shopware;
2

  
3
use strict;
4

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

  
7
use SL::JSON;
8
use LWP::UserAgent;
9
use LWP::Authen::Digest;
10
use SL::DB::ShopOrder;
11
use SL::DB::ShopOrderItem;
12
use Data::Dumper;
13

  
14
use Rose::Object::MakeMethods::Generic (
15
  'scalar --get_set_init' => [ qw(connector url) ],
16
);
17

  
18
sub get_new_orders {
19
  my ($self, $id) = @_;
20

  
21
  my $url = $self->url;
22
  my $ordnumber = 61544;
23
  # Muss noch angepasst werden
24
  for(my $i=1;$i<=300;$i++) {
25
    my $data = $self->connector->get("http://$url/api/orders/$ordnumber?useNumberAsId=true");
26
    $ordnumber++;
27
    $::lxdebug->dump(0, "WH: DATA ", \$data);
28
    my $data_json = $data->content;
29
    my $import = SL::JSON::decode_json($data_json);
30
    $::lxdebug->dump(0, "WH: IMPORT ", \$import);
31
    my %columns = (
32
      amount                  => $import->{data}->{invoiceAmount},
33
      billing_city            => $import->{data}->{billing}->{city},
34
      billing_company         => $import->{data}->{billing}->{company},
35
      billing_country         => $import->{data}->{billing}->{country}->{name},
36
      billing_department      => $import->{data}->{billing}->{department},
37
      billing_email           => $import->{data}->{customer}->{email},
38
      billing_fax             => $import->{data}->{billing}->{fax},
39
      billing_firstname       => $import->{data}->{billing}->{firstName},
40
      billing_greeting        => ($import->{data}->{billing}->{salutation} eq 'mr' ? 'Herr' : 'Frau'),
41
      billing_lastname        => $import->{data}->{billing}->{lastName},
42
      billing_phone           => $import->{data}->{billing}->{phone},
43
      billing_street          => $import->{data}->{billing}->{street} . " " . $import->{data}->{billing}->{streetNumber},
44
      billing_vat             => $import->{data}->{billing}->{vatId},
45
      billing_zipcode         => $import->{data}->{billing}->{zipCode},
46
      customer_city           => $import->{data}->{billing}->{city},
47
      customer_company        => $import->{data}->{billing}->{company},
48
      customer_country        => $import->{data}->{billing}->{country}->{name},
49
      customer_department     => $import->{data}->{billing}->{department},
50
      customer_email          => $import->{data}->{customer}->{email},
51
      customer_fax            => $import->{data}->{billing}->{fax},
52
      customer_firstname      => $import->{data}->{billing}->{firstName},
53
      customer_greeting       => ($import->{data}->{billing}->{salutation} eq 'mr' ? 'Herr' : 'Frau'),
54
      customer_lastname       => $import->{data}->{billing}->{lastName},
55
      customer_phone          => $import->{data}->{billing}->{phone},
56
      customer_street         => $import->{data}->{billing}->{street} . " " . $import->{data}->{billing}->{streetNumber},
57
      customer_vat            => $import->{data}->{billing}->{vatId},
58
      customer_zipcode        => $import->{data}->{billing}->{zipCode},
59
      customer_newsletter     => $import->{data}->{customer}->{newsletter},
60
      delivery_city           => $import->{data}->{shipping}->{city},
61
      delivery_company        => $import->{data}->{shipping}->{company},
62
      delivery_country        => $import->{data}->{shipping}->{country}->{name},
63
      delivery_department     => $import->{data}->{shipping}->{department},
64
      delivery_email          => "",
65
      delivery_fax            => $import->{data}->{shipping}->{fax},
66
      delivery_firstname      => $import->{data}->{shipping}->{firstName},
67
      delivery_greeting       => ($import->{data}->{shipping}->{salutation} eq 'mr' ? 'Herr' : 'Frau'),
68
      delivery_lastname       => $import->{data}->{shipping}->{lastName},
69
      delivery_phone          => $import->{data}->{shipping}->{phone},
70
      delivery_street         => $import->{data}->{shipping}->{street} . " " . $import->{data}->{shipping}->{streetNumber},
71
      delivery_vat            => $import->{data}->{shipping}->{vatId},
72
      delivery_zipcode        => $import->{data}->{shipping}->{zipCode},
73
      host                    => $import->{data}->{shop}->{hosts},
74
      netamount               => $import->{data}->{invoiceAmountNet},
75
      order_date              => $import->{data}->{orderTime},
76
      payment_description     => $import->{data}->{payment}->{description},
77
      payment_id              => $import->{data}->{paymentId},
78
      remote_ip               => $import->{data}->{remoteAddress},
79
      sepa_account_holder     => $import->{data}->{paymentIntances}->{accountHolder},
80
      sepa_bic                => $import->{data}->{paymentIntances}->{bic},
81
      sepa_iban               => $import->{data}->{paymentIntances}->{iban},
82
      shipping_costs          => $import->{data}->{invoiceShipping},
83
      shipping_costs_net      => $import->{data}->{invoiceShippingNet},
84
      shop_c_billing_id       => $import->{data}->{billing}->{customerId},
85
      shop_c_billing_number   => $import->{data}->{billing}->{number},
86
      shop_c_delivery_id      => $import->{data}->{shipping}->{id},
87
      shop_customer_id        => $import->{data}->{customerId},
88
      shop_customer_number    => $import->{data}->{billing}->{number},
89
      shop_customer_comment   => $import->{data}->{customerComment},
90
      shop_data               => "",
91
      shop_id                 => $import->{data}->{id},
92
      shop_ordernumber        => $import->{data}->{number},
93
      shop_trans_id           => $import->{data}->{id},
94
      tax_included            => ($import->{data}->{net} == 0 ? 0 : 1)
95
    );
96
    $::lxdebug->dump(0, "WH: COLUMNS ", \%columns);
97
    my $insert = SL::DB::ShopOrder->new(%columns);
98
    $insert->save;
99
    my $id = $insert->id;
100
    #$::lxdebug->dump(0, "WH: ID ", $insert->id);
101

  
102
    my @positions = @{ $import->{data}->{details} };
103
    #$::lxdebug->dump(0, "WH: POSITIONS ", \@positions);
104
    foreach my $pos(@positions) {
105
      my %pos_columns = ( description => $pos->{articleName},
106
                          id          => $pos->{id},
107
                          partnumber  => $pos->{articleNumber},
108
                          price       => $pos->{price},
109
                          quantity    => $pos->{quantity},
110
                          #shop_id     => $pos->{articleId},
111
                          tax_rate    => $pos->{taxRate},
112
                          shop_trans_id    => $pos->{articleId},
113
                          shop_order_id    => $id,
114
                        );
115
      my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
116
      $pos_insert->save;
117
      #$::lxdebug->dump(0,"WH: POS ", \%pos_columns);
118
    }
119
  }
120
  # return $import;
121
};
122

  
123
sub init_url {
124
  my ($self) = @_;
125
  # TODO: validate url and port
126
  $self->url($self->config->url . ":" . $self->config->port);
127
};
128

  
129
sub init_connector {
130
  my ($self) = @_;
131
  my $ua = LWP::UserAgent->new;
132
  $ua->credentials(
133
      $self->url,
134
      "Shopware4 REST-API",
135
      $self->config->login => $self->config->password
136
  );
137
  return $ua;
138
};
139

  
140
1;
141

  
142
__END__
143

  
144
=encoding utf-8
145

  
146
=head1 NAME
147

  
148
SL::ShopConnecter::Shopware - connector for Shopware 4
149

  
150
=head1 SYNOPSIS
151

  
152
=head1 DESCRIPTION
153

  
154
=head1 BUGS
155

  
156
None yet. :)
157

  
158
=head1 AUTHOR
159

  
160
=cut

Auch abrufbar als: Unified diff