Revision 66858543
Von Werner Hahn vor etwa 7 Jahren hinzugefügt
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 |
|
|
23 |
my $ordnumber = $self->config->last_order_number + 1; |
|
24 |
my $otf = $self->config->orders_to_fetch; |
|
25 |
|
|
26 |
my $i; |
|
27 |
for ($i=1;$i<=$otf;$i++) { |
|
28 |
my $data = $self->connector->get("http://$url/api/orders/$ordnumber?useNumberAsId=true"); |
|
29 |
my $data_json = $data->content; |
|
30 |
my $import = SL::JSON::decode_json($data_json); |
|
31 |
if ($import->{success}){ |
|
32 |
|
|
33 |
# Mapping to table shoporders. See http://community.shopware.com/_detail_1690.html#GET_.28Liste.29 |
|
34 |
my %columns = ( |
|
35 |
amount => $import->{data}->{invoiceAmount}, |
|
36 |
billing_city => $import->{data}->{billing}->{city}, |
|
37 |
billing_company => $import->{data}->{billing}->{company}, |
|
38 |
billing_country => $import->{data}->{billing}->{country}->{name}, |
|
39 |
billing_department => $import->{data}->{billing}->{department}, |
|
40 |
billing_email => $import->{data}->{customer}->{email}, |
|
41 |
billing_fax => $import->{data}->{billing}->{fax}, |
|
42 |
billing_firstname => $import->{data}->{billing}->{firstName}, |
|
43 |
billing_greeting => ($import->{data}->{billing}->{salutation} eq 'mr' ? 'Herr' : 'Frau'), |
|
44 |
billing_lastname => $import->{data}->{billing}->{lastName}, |
|
45 |
billing_phone => $import->{data}->{billing}->{phone}, |
|
46 |
billing_street => $import->{data}->{billing}->{street}, |
|
47 |
billing_vat => $import->{data}->{billing}->{vatId}, |
|
48 |
billing_zipcode => $import->{data}->{billing}->{zipCode}, |
|
49 |
customer_city => $import->{data}->{billing}->{city}, |
|
50 |
customer_company => $import->{data}->{billing}->{company}, |
|
51 |
customer_country => $import->{data}->{billing}->{country}->{name}, |
|
52 |
customer_department => $import->{data}->{billing}->{department}, |
|
53 |
customer_email => $import->{data}->{customer}->{email}, |
|
54 |
customer_fax => $import->{data}->{billing}->{fax}, |
|
55 |
customer_firstname => $import->{data}->{billing}->{firstName}, |
|
56 |
customer_greeting => ($import->{data}->{billing}->{salutation} eq 'mr' ? 'Herr' : 'Frau'), |
|
57 |
customer_lastname => $import->{data}->{billing}->{lastName}, |
|
58 |
customer_phone => $import->{data}->{billing}->{phone}, |
|
59 |
customer_street => $import->{data}->{billing}->{street}, |
|
60 |
customer_vat => $import->{data}->{billing}->{vatId}, |
|
61 |
customer_zipcode => $import->{data}->{billing}->{zipCode}, |
|
62 |
customer_newsletter => $import->{data}->{customer}->{newsletter}, |
|
63 |
delivery_city => $import->{data}->{shipping}->{city}, |
|
64 |
delivery_company => $import->{data}->{shipping}->{company}, |
|
65 |
delivery_country => $import->{data}->{shipping}->{country}->{name}, |
|
66 |
delivery_department => $import->{data}->{shipping}->{department}, |
|
67 |
delivery_email => "", |
|
68 |
delivery_fax => $import->{data}->{shipping}->{fax}, |
|
69 |
delivery_firstname => $import->{data}->{shipping}->{firstName}, |
|
70 |
delivery_greeting => ($import->{data}->{shipping}->{salutation} eq 'mr' ? 'Herr' : 'Frau'), |
|
71 |
delivery_lastname => $import->{data}->{shipping}->{lastName}, |
|
72 |
delivery_phone => $import->{data}->{shipping}->{phone}, |
|
73 |
delivery_street => $import->{data}->{shipping}->{street}, |
|
74 |
delivery_vat => $import->{data}->{shipping}->{vatId}, |
|
75 |
delivery_zipcode => $import->{data}->{shipping}->{zipCode}, |
|
76 |
host => $import->{data}->{shop}->{hosts}, |
|
77 |
netamount => $import->{data}->{invoiceAmountNet}, |
|
78 |
order_date => $import->{data}->{orderTime}, |
|
79 |
payment_description => $import->{data}->{payment}->{description}, |
|
80 |
payment_id => $import->{data}->{paymentId}, |
|
81 |
remote_ip => $import->{data}->{remoteAddress}, |
|
82 |
sepa_account_holder => $import->{data}->{paymentIntances}->{accountHolder}, |
|
83 |
sepa_bic => $import->{data}->{paymentIntances}->{bic}, |
|
84 |
sepa_iban => $import->{data}->{paymentIntances}->{iban}, |
|
85 |
shipping_costs => $import->{data}->{invoiceShipping}, |
|
86 |
shipping_costs_net => $import->{data}->{invoiceShippingNet}, |
|
87 |
shop_c_billing_id => $import->{data}->{billing}->{customerId}, |
|
88 |
shop_c_billing_number => $import->{data}->{billing}->{number}, |
|
89 |
shop_c_delivery_id => $import->{data}->{shipping}->{id}, |
|
90 |
shop_customer_id => $import->{data}->{customerId}, |
|
91 |
shop_customer_number => $import->{data}->{billing}->{number}, |
|
92 |
shop_customer_comment => $import->{data}->{customerComment}, |
|
93 |
shop_data => "", |
|
94 |
shop_id => $import->{data}->{id}, |
|
95 |
shop_ordernumber => $import->{data}->{number}, |
|
96 |
shop_trans_id => $import->{data}->{id}, |
|
97 |
tax_included => ($import->{data}->{net} == 0 ? 0 : 1) |
|
98 |
); |
|
99 |
my $insert = SL::DB::ShopOrder->new(%columns); |
|
100 |
$insert->save; |
|
101 |
my $id = $insert->id; |
|
102 |
|
|
103 |
my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} }; |
|
104 |
my $position = 1; |
|
105 |
foreach my $pos(@positions) { |
|
106 |
my %pos_columns = ( description => $pos->{articleName}, |
|
107 |
partnumber => $pos->{articleNumber}, |
|
108 |
price => $pos->{price}, |
|
109 |
quantity => $pos->{quantity}, |
|
110 |
position => $position, |
|
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 |
$position++; |
|
118 |
} |
|
119 |
# Versandkosten als Position am ende einfügen Dreschflegelspezifisch event. konfigurierbar machen |
|
120 |
|
|
121 |
if (my $shipping = $import->{data}->{dispatch}->{name}) { |
|
122 |
my %shipping_partnumbers = ( |
|
123 |
'Auslandsversand Einschreiben' => { 'partnumber' => '900650'}, |
|
124 |
'Auslandsversand' => { 'partnumber' => '900650'}, |
|
125 |
'Standard Versand' => { 'partnumber' => '905500'}, |
|
126 |
'Kostenloser Versand' => { 'partnumber' => '905500'}, |
|
127 |
); |
|
128 |
my %shipping_pos = ( description => $import->{data}->{dispatch}->{name}, |
|
129 |
partnumber => $shipping_partnumbers{$shipping}->{partnumber}, |
|
130 |
price => $import->{data}->{invoiceShipping}, |
|
131 |
quantity => 1, |
|
132 |
position => $position, |
|
133 |
tax_rate => 7, |
|
134 |
shop_trans_id => 0, |
|
135 |
shop_order_id => $id, |
|
136 |
); |
|
137 |
my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos); |
|
138 |
$shipping_pos_insert->save; |
|
139 |
|
|
140 |
my $attributes->{last_order_number} = $ordnumber; |
|
141 |
$self->config->assign_attributes( %{ $attributes } ); |
|
142 |
$self->config->save; |
|
143 |
$ordnumber++; |
|
144 |
} |
|
145 |
}else{ |
|
146 |
last; |
|
147 |
} |
|
148 |
} |
|
149 |
# return $import; |
|
150 |
}; |
|
151 |
|
|
152 |
sub init_url { |
|
153 |
my ($self) = @_; |
|
154 |
# TODO: validate url and port |
|
155 |
$self->url($self->config->url . ":" . $self->config->port); |
|
156 |
}; |
|
157 |
|
|
158 |
sub init_connector { |
|
159 |
my ($self) = @_; |
|
160 |
my $ua = LWP::UserAgent->new; |
|
161 |
$ua->credentials( |
|
162 |
$self->url, |
|
163 |
"Shopware REST-API", |
|
164 |
$self->config->login => $self->config->password |
|
165 |
); |
|
166 |
return $ua; |
|
167 |
}; |
|
168 |
|
|
169 |
1; |
|
170 |
|
|
171 |
__END__ |
|
172 |
|
|
173 |
=encoding utf-8 |
|
174 |
|
|
175 |
=head1 NAME |
|
176 |
|
|
177 |
SL::ShopConnecter::Shopware - connector for Shopware 5 |
|
178 |
|
|
179 |
=head1 SYNOPSIS |
|
180 |
|
|
181 |
=head1 DESCRIPTION |
|
182 |
|
|
183 |
=head1 BUGS |
|
184 |
|
|
185 |
None yet. :) |
|
186 |
|
|
187 |
=head1 AUTHOR |
|
188 |
|
|
189 |
|
|
190 |
=cut |
Auch abrufbar als: Unified diff
Shopmodul: Shopware5-Connector angepasst