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});
|
ShopPart: Upload biuleder gehen noch nicht json schein aber richtig zu sein