Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0067f9b2

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID 0067f9b2dd692f7b3452faad2806ee41684211a8
  • Vorgänger d1582152
  • Nachfolger c59be376

Webshop: Kommentare rausgenommen

Unterschiede anzeigen:

SL/Controller/Shop.pm
144 144

  
145 145

  
146 146
1;
147

  
148
__END__
149

  
150
=encoding utf-8
151

  
152
=head1 NAME
153

  
154
  SL::Controller::Shop
155

  
156
=head1 SYNOPSIS
157

  
158

  
159
=head1 DESCRIPTION
160

  
161

  
162
=head1 BUGS
163

  
164
  None yet. :)
165

  
166
=head1 AUTHOR
167

  
168
  G. Richardson E<lt>information@kivitendo-premium.deE<gt>
169
  W. Hahn E<lt>wh@futureworldsearch.netE<gt>
SL/Controller/ShopOrder.pm
25 25

  
26 26
sub action_get_orders {
27 27
  my ( $self ) = @_;
28

  
28
  my $orders_fetched;
29 29
  my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
30 30
  foreach my $shop_config ( @{ $active_shops } ) {
31 31
    my $shop = SL::Shop->new( config => $shop_config );
32 32
    my $new_orders = $shop->connector->get_new_orders;
33
    push @{ $orders_fetched },@{ $new_orders };
33 34
  };
34 35
  $self->action_list;
36
  #TODO Flashinfo how many orders from wich shop have been fetched. infos in $orders_fetched
35 37
}
36 38

  
37 39
sub action_list {
......
236 238
}
237 239

  
238 240
1;
241

  
242
__END__
243

  
244
=encoding utf-8
245

  
246
=head1 NAME
247

  
248
  SL::Controller::ShopOrder - Handles th imported shoporders
249

  
250
=head1 SYNOPSIS
251

  
252

  
253
=head1 DESCRIPTION
254

  
255

  
256
=head1 BUGS
257

  
258
  None yet. :)
259

  
260
=head1 AUTHOR
261

  
262
  W. Hahn E<lt>wh@futureworldsearch.netE<gt>
263

  
264
=cut
SL/Controller/ShopPart.pm
334 334
}
335 335
1;
336 336

  
337
=pod
337
__END__
338 338

  
339 339
=encoding utf-8
340 340

  
341

  
341 342
=head1 NAME
342 343

  
343
SL::Controller::ShopPart - Controller for managing ShopParts
344
  SL::Controller::ShopPart - Controller for managing ShopParts
344 345

  
345 346
=head1 SYNOPSIS
346 347

  
347
ShopParts are configured in a tab of the corresponding part.
348
  ShopParts are configured in a tab of the corresponding part.
348 349

  
349 350
=head1 FUNCTIONS
350 351

  
352

  
351 353
=over 4
352 354

  
355

  
353 356
=item C<action_update_shop>
354 357

  
355
To be called from the "Update" button, for manually syncing a part with its
356
shop. Generates a  Calls some ClientJS functions to modifiy original page.
358
  To be called from the "Update" button, for manually syncing a part with its shop. Generates a  Calls some ClientJS functions to modifiy original page.
357 359

  
358
=back
359 360

  
360 361
=head1 AUTHORS
361 362

  
362
G. Richardson E<lt>information@kivitendo-premium.deE<gt>
363
W. Hahn E<lt>wh@futureworldsearch.netE<gt>
363
  G. Richardson E<lt>information@kivitendo-premium.deE<gt>
364
  W. Hahn E<lt>wh@futureworldsearch.netE<gt>
364 365

  
365 366
=cut
SL/ShopConnector/Shopware.pm
11 11
use SL::DB::ShopOrderItem;
12 12
use Data::Dumper;
13 13
use Sort::Naturally ();
14
use SL::Helper::Flash;
14 15
use Encode qw(encode_utf8);
15 16
use SL::Controller::ShopPart;
16 17

  
......
22 23
  my ($self, $id) = @_;
23 24

  
24 25
  my $url = $self->url;
25
  #TODO Letzte Bestellnummer und Anzahl der abzuholenden Bestellungen muss noch in die Shopconfig
26
  my $ordnumber = 63641;
27
  #TODO Muss noch angepasst werden
28
  for(my $i=1;$i<=350;$i++) {
29
    my $data = $self->connector->get("https://$url/api/orders/$ordnumber?useNumberAsId=true");
30
    $ordnumber++;
26

  
27
  my $ordnumber = $self->config->last_order_number + 1;
28
  my $otf = $self->config->orders_to_fetch;
29

  
30
  my $i;
31
  for ($i=1;$i<=$otf;$i++) {
32
    my $data = $self->connector->get("http://$url/api/orders/$ordnumber?useNumberAsId=true");
31 33
    my $data_json = $data->content;
32 34
    my $import = SL::JSON::decode_json($data_json);
33
    # Mapping to table shoporders
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}, # . " " . $import->{data}->{billing}->{streetNumber},
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}, # . " " . $import->{data}->{billing}->{streetNumber},
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}, # . " " . $import->{data}->{shipping}->{streetNumber},
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
    if (my $shipping = $import->{data}->{dispatch}->{name}) {
121
      my %shipping_partnumbers = (
122
                                  'Auslandsversand Einschreiben'  => { 'partnumber' => '900650'},
123
                                  'Auslandsversand'               => { 'partnumber' => '900650'},
124
                                  'Standard Versand'              => { 'partnumber' => '905500'},
125
                                  'Kostenloser Versand'           => { 'partnumber' => '905500'},
126
                                );
127
      my %shipping_pos = ( description    => $import->{data}->{dispatch}->{name},
128
                           partnumber     => $shipping_partnumbers{$shipping}->{partnumber},
129
                           price          => $import->{data}->{invoiceShipping},
130
                           quantity       => 1,
131
                           position       => $position,
132
                           tax_rate       => 7,
133
                           shop_trans_id  => 0,
134
                           shop_order_id  => $id,
135
                         );
136
      my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos);
137
      $shipping_pos_insert->save;
35
    if ($import->{success}){
36

  
37
      # Mapping to table shoporders. See http://community.shopware.com/_detail_1690.html#GET_.28Liste.29
38
      my %columns = (
39
        amount                  => $import->{data}->{invoiceAmount},
40
        billing_city            => $import->{data}->{billing}->{city},
41
        billing_company         => $import->{data}->{billing}->{company},
42
        billing_country         => $import->{data}->{billing}->{country}->{name},
43
        billing_department      => $import->{data}->{billing}->{department},
44
        billing_email           => $import->{data}->{customer}->{email},
45
        billing_fax             => $import->{data}->{billing}->{fax},
46
        billing_firstname       => $import->{data}->{billing}->{firstName},
47
        billing_greeting        => ($import->{data}->{billing}->{salutation} eq 'mr' ? 'Herr' : 'Frau'),
48
        billing_lastname        => $import->{data}->{billing}->{lastName},
49
        billing_phone           => $import->{data}->{billing}->{phone},
50
        billing_street          => $import->{data}->{billing}->{street},
51
        billing_vat             => $import->{data}->{billing}->{vatId},
52
        billing_zipcode         => $import->{data}->{billing}->{zipCode},
53
        customer_city           => $import->{data}->{billing}->{city},
54
        customer_company        => $import->{data}->{billing}->{company},
55
        customer_country        => $import->{data}->{billing}->{country}->{name},
56
        customer_department     => $import->{data}->{billing}->{department},
57
        customer_email          => $import->{data}->{customer}->{email},
58
        customer_fax            => $import->{data}->{billing}->{fax},
59
        customer_firstname      => $import->{data}->{billing}->{firstName},
60
        customer_greeting       => ($import->{data}->{billing}->{salutation} eq 'mr' ? 'Herr' : 'Frau'),
61
        customer_lastname       => $import->{data}->{billing}->{lastName},
62
        customer_phone          => $import->{data}->{billing}->{phone},
63
        customer_street         => $import->{data}->{billing}->{street},
64
        customer_vat            => $import->{data}->{billing}->{vatId},
65
        customer_zipcode        => $import->{data}->{billing}->{zipCode},
66
        customer_newsletter     => $import->{data}->{customer}->{newsletter},
67
        delivery_city           => $import->{data}->{shipping}->{city},
68
        delivery_company        => $import->{data}->{shipping}->{company},
69
        delivery_country        => $import->{data}->{shipping}->{country}->{name},
70
        delivery_department     => $import->{data}->{shipping}->{department},
71
        delivery_email          => "",
72
        delivery_fax            => $import->{data}->{shipping}->{fax},
73
        delivery_firstname      => $import->{data}->{shipping}->{firstName},
74
        delivery_greeting       => ($import->{data}->{shipping}->{salutation} eq 'mr' ? 'Herr' : 'Frau'),
75
        delivery_lastname       => $import->{data}->{shipping}->{lastName},
76
        delivery_phone          => $import->{data}->{shipping}->{phone},
77
        delivery_street         => $import->{data}->{shipping}->{street},
78
        delivery_vat            => $import->{data}->{shipping}->{vatId},
79
        delivery_zipcode        => $import->{data}->{shipping}->{zipCode},
80
        host                    => $import->{data}->{shop}->{hosts},
81
        netamount               => $import->{data}->{invoiceAmountNet},
82
        order_date              => $import->{data}->{orderTime},
83
        payment_description     => $import->{data}->{payment}->{description},
84
        payment_id              => $import->{data}->{paymentId},
85
        remote_ip               => $import->{data}->{remoteAddress},
86
        sepa_account_holder     => $import->{data}->{paymentIntances}->{accountHolder},
87
        sepa_bic                => $import->{data}->{paymentIntances}->{bic},
88
        sepa_iban               => $import->{data}->{paymentIntances}->{iban},
89
        shipping_costs          => $import->{data}->{invoiceShipping},
90
        shipping_costs_net      => $import->{data}->{invoiceShippingNet},
91
        shop_c_billing_id       => $import->{data}->{billing}->{customerId},
92
        shop_c_billing_number   => $import->{data}->{billing}->{number},
93
        shop_c_delivery_id      => $import->{data}->{shipping}->{id},
94
        shop_customer_id        => $import->{data}->{customerId},
95
        shop_customer_number    => $import->{data}->{billing}->{number},
96
        shop_customer_comment   => $import->{data}->{customerComment},
97
        shop_data               => "",
98
        shop_id                 => $import->{data}->{id},
99
        shop_ordernumber        => $import->{data}->{number},
100
        shop_trans_id           => $import->{data}->{id},
101
        tax_included            => ($import->{data}->{net} == 0 ? 0 : 1)
102
      );
103
      my $insert = SL::DB::ShopOrder->new(%columns);
104
      $insert->save;
105
      my $id = $insert->id;
106

  
107
      my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} };
108
      my $position = 1;
109
      foreach my $pos(@positions) {
110
        my %pos_columns = ( description       => $pos->{articleName},
111
                            partnumber        => $pos->{articleNumber},
112
                            price             => $pos->{price},
113
                            quantity          => $pos->{quantity},
114
                            position          => $position,
115
                            tax_rate          => $pos->{taxRate},
116
                            shop_trans_id     => $pos->{articleId},
117
                            shop_order_id     => $id,
118
                          );
119
        my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
120
        $pos_insert->save;
121
        $position++;
122
      }
123
      # Versandkosten als Position am ende einfügen Dreschflegelspezifisch event. konfigurierbar machen
124

  
125
      if (my $shipping = $import->{data}->{dispatch}->{name}) {
126
        my %shipping_partnumbers = (
127
                                    'Auslandsversand Einschreiben'  => { 'partnumber' => '900650'},
128
                                    'Auslandsversand'               => { 'partnumber' => '900650'},
129
                                    'Standard Versand'              => { 'partnumber' => '905500'},
130
                                    'Kostenloser Versand'           => { 'partnumber' => '905500'},
131
                                  );
132
        my %shipping_pos = ( description    => $import->{data}->{dispatch}->{name},
133
                             partnumber     => $shipping_partnumbers{$shipping}->{partnumber},
134
                             price          => $import->{data}->{invoiceShipping},
135
                             quantity       => 1,
136
                             position       => $position,
137
                             tax_rate       => 7,
138
                             shop_trans_id  => 0,
139
                             shop_order_id  => $id,
140
                           );
141
        my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos);
142
        $shipping_pos_insert->save;
143

  
144
        my $attributes->{last_order_number} = $ordnumber;
145
        $self->config->assign_attributes( %{ $attributes } );
146
        $self->config->save;
147
        $ordnumber++;
148
      }
149
    }else{
150
      last;
138 151
    }
152
    my $shop = $self->config->description;
153

  
154
    my @fetched_orders = ($shop,$i);
155

  
156
    return \@fetched_orders;
139 157
  }
140 158
};
141 159

  
......
172 190

  
173 191
  my $url = $self->url;
174 192
  my $part = SL::DB::Part->new(id => $shop_part->{part_id})->load;
175
$main::lxdebug->dump(0, 'WH: SHOPPART: ',\$part);
176 193

  
177 194
  # TODO: Prices (pricerules, pricegroups, multiple prices)
178 195
  my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } };
......
248 265
  }
249 266
  if(@upload_img) {
250 267
    $self->connector->put("http://$url/api/generateArticleImages/$part->{partnumber}?useNumberAsId=true");
251
    #$self->connector->delete("http://$url/api/caches/");
252 268
  }
253 269
  return $upload_content->{success};
254 270
}
......
287 303

  
288 304
=head1 NAME
289 305

  
290
SL::ShopConnecter::Shopware - connector for Shopware 4
306
  SL::ShopConnecter::Shopware - connector for Shopware 5
291 307

  
292 308
=head1 SYNOPSIS
293 309

  
310

  
294 311
=head1 DESCRIPTION
295 312

  
313

  
296 314
=head1 BUGS
297 315

  
298
None yet. :)
316
  None yet. :)
299 317

  
300 318
=head1 AUTHOR
301 319

  
302
W. Hahn E<lt>wh@futureworldsearch.netE<gt>
320
  W. Hahn E<lt>wh@futureworldsearch.netE<gt>
303 321

  
304 322
=cut

Auch abrufbar als: Unified diff