Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c033e49e

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID c033e49e7f0a5bd418aadc7453c70f1e0177ff49
  • Vorgänger 63720c4e
  • Nachfolger 4edf2b76

ShopPart: Upload biuleder gehen noch nicht json schein aber richtig zu sein

Unterschiede anzeigen:

SL/Controller/ShopPart.pm
10 10
use SL::DB::File;
11 11
use SL::DB::Default;
12 12
use SL::Helper::Flash;
13
use MIME::Base64;
13 14

  
14 15
use Rose::Object::MakeMethods::Generic
15 16
(
......
48 49
  #$part->{cvars}      = $cvars;
49 50
  #$part->{images}     = $images;
50 51

  
51
  #$main::lxdebug->dump(0, 'WH: Part II',\$part);
52
  $main::lxdebug->dump(0, 'WH: ShopPart I',\$self->shop_part);
52 53
  require SL::Shop;
53 54
  my $shop = SL::Shop->new( config => $shop_part->shop );
54 55

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

  
7 7
use SL::JSON;
8
use JSON;
8
#use JSON;
9 9
use LWP::UserAgent;
10 10
use LWP::Authen::Digest;
11 11
use SL::DB::ShopOrder;
12 12
use SL::DB::ShopOrderItem;
13 13
use Data::Dumper;
14 14
use Sort::Naturally ();
15
use Encode qw(encode_utf8);
15 16

  
16 17
use Rose::Object::MakeMethods::Generic (
17 18
  'scalar --get_set_init' => [ qw(connector url) ],
......
145 146

  
146 147
  my $data = $self->connector->get("http://$url/api/categories");
147 148
  my $data_json = $data->content;
149
  $main::lxdebug->dump(0, 'WH: IMPORT', \$data_json);
148 150
  my $import = SL::JSON::decode_json($data_json);
149 151
  my @daten = @{$import->{data}};
150 152
  my %categories = map { ($_->{id} => $_) } @daten;
......
168 170
}
169 171

  
170 172
sub update_part {
171
  my ($self, $json) = @_;
173
  my ($self, $shop_part, $json) = @_;
174

  
175
  #shop_part is passed as a param
176
  die unless ref($shop_part) eq 'SL::DB::ShopPart';
177

  
178
  $main::lxdebug->dump(0, 'WH: UPDATE SHOPPART: ', \$shop_part);
172 179
  $main::lxdebug->dump(0, 'WH: UPDATE SELF: ', \$self);
173
  $main::lxdebug->dump(0, 'WH: UPDATE PART: ', \$json);
180
  $main::lxdebug->dump(0, 'WH: UPDATE JSON: ', \$json);
174 181
  my $url = $self->url;
175
  my $part = SL::DB::Manager::Part->find_by(id => $json->{part_id});
182
  my $part = SL::DB::Part->new(id => $shop_part->{part_id})->load;
183
  #my $part = $shop_part->part;
176 184
  $main::lxdebug->dump(0, 'WH: Part',\$part);
177 185

  
186
  # TODO: Prices (pricerules, pricegroups,
178 187
  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);
188
  my $categories = { map { ( name => $_) } @{ $shop_part->{shop_category} } };
189
  $main::lxdebug->dump(0, 'WH: CATEGORIES',\$categories);
190
  my $images = SL::DB::Manager::File->get_all( modul => 'shop_part', trans_id => $part->{id});
191
  $main::lxdebug->dump(0, 'WH: IMAGES',\$images);
192
  $images = { map { ( url => 'data:' . $_->{file_content_type} . ';base64,' . MIME::Base64::encode($_->{file_content}),
193
                      description => $_->{title},
194
                      position    => $_->{position},
195
                      extension   => 'jpg',
196
                      path        => $_->{filename},
197
                    ) } @{ $images } };
198
  $main::lxdebug->dump(0, 'WH: IMAGES 2 ',\$images);
180 199
$main::lxdebug->dump(0, 'WH: Partnumber', $part->{partnumber});
181 200

  
182 201
  my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true");
183 202
  my $data_json = $data->content;
184 203
  my $import = SL::JSON::decode_json($data_json);
185 204
  $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
                                 }
205
  $main::lxdebug->dump(0, 'WH: Active', $shop_part->active);
206

  
207

  
208
  my %shop_data =  (  name          => $part->{description},
209
                      taxId         => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00
210
                      mainDetail    => { number   => $part->{partnumber},
211
                                         inStock  => $part->{onhand},
212
                                         prices   =>  [ {          from   => 1,
213
                                                                   price  => $part->{sellprice},
214
                                                        customerGroupKey  => 'EK',
215
                                                      },
216
                                                    ],
217
                                       },
218
                      supplier      => $cvars->{freifeld_7}->{value},
219
                      description   => $shop_part->{shop_description},
220
                      active        => $shop_part->active,
221
                      images        => [ $images ],
222
                      #categories    => [ { name => 'Deutsch\test2' }, ], #[ $categories ],
223
                    )
193 224
                  ;
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}';
225
$main::lxdebug->dump(0, 'WH: SHOPDATA', \%shop_data );
226
my $dataString = SL::JSON::to_json(\%shop_data);
227
$dataString = encode_utf8($dataString);
228
$main::lxdebug->message(0, 'WH: JSONDATA2 '.$dataString);
206 229
  if($import->{success}){
207
    #update
208 230
$main::lxdebug->message(0, "WH: if success: ". $import->{success});
231
    #update
232
    my $upload = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $dataString);
233
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload);
209 234
  }else{
210 235
    #upload
211 236
$main::lxdebug->message(0, "WH: else success: ". $import->{success});
templates/webpages/ic/tabs/_shop.html
21 21
   <td>[% L.html_tag('span', shop_part.shop_description, id => 'shop_part_description_' _ shop_part.id ) %]</td>
22 22
   <td>[% L.html_tag('span', shop_part.last_update.to_kivitendo('precision' => 'minute'), id => 'shop_part_last_update_' _ shop_part.id ) %]</td>
23 23
   <td>[% L.button_tag("kivi.shop_part.edit_shop_part(" _ shop_part.id _ ")", LxERP.t8("Edit"))  %]</td>
24
   <td>[% L.button_tag("kivi.shop_part.update_shop_part(" _ shop_part.id _ ")", LxERP.t8("Update"))  %]</td>
24
   <td>[% L.button_tag("kivi.shop_part.update_shop_part(" _ shop_part.id _ ")", LxERP.t8("Upload"))  %]</td>
25 25
   <td>[% L.button_tag("kivi.shop_part.get_all_categories(" _ shop_part.id _ ")", LxERP.t8("Shopcategories"))  %]</td>
26 26
  </tr>
27 27
  [%- END %]
......
48 48
     [%- FOREACH var = CUSTOM_VARIABLES %]
49 49
      [%- IF var.name.match('^shop_') %]
50 50
       <tr>
51
        [%- IF !var.partsgroup_filtered %]
51
        [% # IF !var.partsgroup_filtered %]
52 52
          <td align="right" valign="top">[% HTML.escape(var.description) %]</td>
53
        [%- END %]
53
        [% # END %]
54 54
        <td valign="top">[% var.HTML_CODE %]</td>
55 55
       </tr>
56 56
      [%- END %]
......
64 64
      var url = 'controller.pl?action=ShopPart/show_files&modul=shop_part&id=[% shop_part.part_id %]';
65 65
      $('#shop_images').load(url);
66 66
    }
67

  
67
<!-- TODO -->
68 68
$(window).load(function() {
69 69
        show_images();
70 70
});

Auch abrufbar als: Unified diff