Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 63720c4e

Von Werner Hahn vor fast 8 Jahren hinzugefügt

  • ID 63720c4e063fdd6b3297048f429037c30af1a7f8
  • Vorgänger 81d283b4
  • Nachfolger c033e49e

ShopPart: Test Artikel wird mit json im LWP::UserAgent in den Shop hochgeladen

Unterschiede anzeigen:

SL/ShopConnector/Shopware.pm
5 5
use parent qw(SL::ShopConnector::Base);
6 6

  
7 7
use SL::JSON;
8
use JSON;
8 9
use LWP::UserAgent;
9 10
use LWP::Authen::Digest;
10 11
use SL::DB::ShopOrder;
......
26 27
  for(my $i=1;$i<=350;$i++) {
27 28
    my $data = $self->connector->get("https://$url/api/orders/$ordnumber?useNumberAsId=true");
28 29
    $ordnumber++;
29
    $::lxdebug->dump(0, "WH: DATA ", \$data);
30 30
    my $data_json = $data->content;
31 31
    my $import = SL::JSON::decode_json($data_json);
32
    $::lxdebug->dump(0, "WH: IMPORT ", \$import);
33 32
    # Mapping to table shoporders
34 33
    my %columns = (
35 34
      amount                  => $import->{data}->{invoiceAmount},
......
96 95
      shop_trans_id           => $import->{data}->{id},
97 96
      tax_included            => ($import->{data}->{net} == 0 ? 0 : 1)
98 97
    );
99
    $::lxdebug->dump(0, "WH: COLUMNS ", \%columns);
100 98
    my $insert = SL::DB::ShopOrder->new(%columns);
101 99
    $insert->save;
102 100
    my $id = $insert->id;
103
    #$::lxdebug->dump(0, "WH: ID ", $insert->id);
104 101

  
105
    #my @positions = @{ $import->{data}->{details} };
106 102
    my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} };
107
    # $::lxdebug->dump(0, "WH: POSITIONS ", \@positions);
108 103
    my $position = 1;
109 104
    foreach my $pos(@positions) {
110 105
      my %pos_columns = ( description => $pos->{articleName},
111
        #     id          => $pos->{id},
112 106
                          partnumber  => $pos->{articleNumber},
113 107
                          price       => $pos->{price},
114 108
                          quantity    => $pos->{quantity},
......
120 114
      my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
121 115
      $pos_insert->save;
122 116
      $position++;
123
      #$::lxdebug->dump(0,"WH: POS ", \%pos_columns);
124 117
    }
125 118
    # Versandkosten als Position am ende einfügen Dreschflegelspezifisch event. konfigurierbar machen
126 119
    if (my $shipping = $import->{data}->{dispatch}->{name}) {
......
130 123
                                  'Standard Versand'            => { 'partnumber' => '905500'},
131 124
                                  'Kostenloser Versand'         => { 'partnumber' => '905500'},
132 125
                                );
133
      $main::lxdebug->message(0, "WH: SHIPPING1: $shipping ");
134 126
      my %shipping_pos = ( description => $import->{data}->{dispatch}->{name},
135
        #      id          => 0,
136 127
                           partnumber  => $shipping_partnumbers{$shipping}->{partnumber},
137 128
                           price       => $import->{data}->{invoiceShipping},
138 129
                           quantity    => 1,
......
141 132
                           shop_trans_id  => 0,
142 133
                           shop_order_id  => $id,
143 134
                         );
144
      $main::lxdebug->dump(0, 'WH: SHIPPING: ', \%shipping_pos);
145 135
      my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos);
146 136
      $shipping_pos_insert->save;
147 137
    }
148 138
  }
149
  # return $import;
150 139
};
151 140

  
152 141
sub get_categories {
......
173 162
}
174 163

  
175 164
sub get_articles {
165
  my ($self, $json_data) = @_;
166
  $main::lxdebug->dump(0, 'WH: JSON: ', \$json_data);
167

  
176 168
}
177 169

  
178
sub set_article {
170
sub update_part {
171
  my ($self, $json) = @_;
172
  $main::lxdebug->dump(0, 'WH: UPDATE SELF: ', \$self);
173
  $main::lxdebug->dump(0, 'WH: UPDATE PART: ', \$json);
174
  my $url = $self->url;
175
  my $part = SL::DB::Manager::Part->find_by(id => $json->{part_id});
176
  $main::lxdebug->dump(0, 'WH: Part',\$part);
177

  
178
  my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } };
179
  $main::lxdebug->dump(0, 'WH: CVARS',\$cvars);
180
$main::lxdebug->dump(0, 'WH: Partnumber', $part->{partnumber});
181

  
182
  my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true");
183
  my $data_json = $data->content;
184
  my $import = SL::JSON::decode_json($data_json);
185
  $main::lxdebug->dump(0, 'WH: IMPORT', \$import);
186

  
187
  my $shop_data =  {  name        => $part->{description} ,
188
                      taxId       => 1 ,
189
                      mainDetail  => { number => $part->{partnumber}  ,
190
                                        test        => 'test' ,
191
                                     }
192
                                 }
193
                  ;
194
#$main::lxdebug->dump(0, 'WH: SHOPDATA',\%shop_data);
195
my $dataString = SL::JSON::encode_json($shop_data);
196
$main::lxdebug->dump(0, 'WH: JSONDATA2',$dataString);
197
#my $daten = SL::JSON::decode_json($dataString);
198
#$dataString =~ s/{|}//g;
199
#$dataString = "{".$dataString."}";
200
#my $json_data      = SL::JSON::to_json($shop_data);
201
#$main::lxdebug->dump(0, 'WH: JSONDATA3',$daten);
202
#my $dataString2 = JSON::encode_json($shop_data);
203
#$main::lxdebug->dump(0, 'WH: JSONDATA4',$dataString2);
204
#$main::lxdebug->message(0, "WH: isuccess: ". $import->{success});
205
my $json = '{"name": "foo", "taxId": 1}';
206
  if($import->{success}){
207
    #update
208
$main::lxdebug->message(0, "WH: if success: ". $import->{success});
209
  }else{
210
    #upload
211
$main::lxdebug->message(0, "WH: else success: ". $import->{success});
212
    my $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString);
213
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload);
214
  }
215

  
179 216
}
180 217

  
181 218
sub init_url {

Auch abrufbar als: Unified diff