Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c033e49e

Von Werner Hahn vor fast 9 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
use SL::DB::File;
use SL::DB::Default;
use SL::Helper::Flash;
use MIME::Base64;
use Rose::Object::MakeMethods::Generic
(
......
#$part->{cvars} = $cvars;
#$part->{images} = $images;
#$main::lxdebug->dump(0, 'WH: Part II',\$part);
$main::lxdebug->dump(0, 'WH: ShopPart I',\$self->shop_part);
require SL::Shop;
my $shop = SL::Shop->new( config => $shop_part->shop );
SL/ShopConnector/Shopware.pm
use parent qw(SL::ShopConnector::Base);
use SL::JSON;
use JSON;
#use JSON;
use LWP::UserAgent;
use LWP::Authen::Digest;
use SL::DB::ShopOrder;
use SL::DB::ShopOrderItem;
use Data::Dumper;
use Sort::Naturally ();
use Encode qw(encode_utf8);
use Rose::Object::MakeMethods::Generic (
'scalar --get_set_init' => [ qw(connector url) ],
......
my $data = $self->connector->get("http://$url/api/categories");
my $data_json = $data->content;
$main::lxdebug->dump(0, 'WH: IMPORT', \$data_json);
my $import = SL::JSON::decode_json($data_json);
my @daten = @{$import->{data}};
my %categories = map { ($_->{id} => $_) } @daten;
......
}
sub update_part {
my ($self, $json) = @_;
my ($self, $shop_part, $json) = @_;
#shop_part is passed as a param
die unless ref($shop_part) eq 'SL::DB::ShopPart';
$main::lxdebug->dump(0, 'WH: UPDATE SHOPPART: ', \$shop_part);
$main::lxdebug->dump(0, 'WH: UPDATE SELF: ', \$self);
$main::lxdebug->dump(0, 'WH: UPDATE PART: ', \$json);
$main::lxdebug->dump(0, 'WH: UPDATE JSON: ', \$json);
my $url = $self->url;
my $part = SL::DB::Manager::Part->find_by(id => $json->{part_id});
my $part = SL::DB::Part->new(id => $shop_part->{part_id})->load;
#my $part = $shop_part->part;
$main::lxdebug->dump(0, 'WH: Part',\$part);
# TODO: Prices (pricerules, pricegroups,
my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } };
$main::lxdebug->dump(0, 'WH: CVARS',\$cvars);
my $categories = { map { ( name => $_) } @{ $shop_part->{shop_category} } };
$main::lxdebug->dump(0, 'WH: CATEGORIES',\$categories);
my $images = SL::DB::Manager::File->get_all( modul => 'shop_part', trans_id => $part->{id});
$main::lxdebug->dump(0, 'WH: IMAGES',\$images);
$images = { map { ( url => 'data:' . $_->{file_content_type} . ';base64,' . MIME::Base64::encode($_->{file_content}),
description => $_->{title},
position => $_->{position},
extension => 'jpg',
path => $_->{filename},
) } @{ $images } };
$main::lxdebug->dump(0, 'WH: IMAGES 2 ',\$images);
$main::lxdebug->dump(0, 'WH: Partnumber', $part->{partnumber});
my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true");
my $data_json = $data->content;
my $import = SL::JSON::decode_json($data_json);
$main::lxdebug->dump(0, 'WH: IMPORT', \$import);
my $shop_data = { name => $part->{description} ,
taxId => 1 ,
mainDetail => { number => $part->{partnumber} ,
test => 'test' ,
}
}
$main::lxdebug->dump(0, 'WH: Active', $shop_part->active);
my %shop_data = ( name => $part->{description},
taxId => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00
mainDetail => { number => $part->{partnumber},
inStock => $part->{onhand},
prices => [ { from => 1,
price => $part->{sellprice},
customerGroupKey => 'EK',
},
],
},
supplier => $cvars->{freifeld_7}->{value},
description => $shop_part->{shop_description},
active => $shop_part->active,
images => [ $images ],
#categories => [ { name => 'Deutsch\test2' }, ], #[ $categories ],
)
;
#$main::lxdebug->dump(0, 'WH: SHOPDATA',\%shop_data);
my $dataString = SL::JSON::encode_json($shop_data);
$main::lxdebug->dump(0, 'WH: JSONDATA2',$dataString);
#my $daten = SL::JSON::decode_json($dataString);
#$dataString =~ s/{|}//g;
#$dataString = "{".$dataString."}";
#my $json_data = SL::JSON::to_json($shop_data);
#$main::lxdebug->dump(0, 'WH: JSONDATA3',$daten);
#my $dataString2 = JSON::encode_json($shop_data);
#$main::lxdebug->dump(0, 'WH: JSONDATA4',$dataString2);
#$main::lxdebug->message(0, "WH: isuccess: ". $import->{success});
my $json = '{"name": "foo", "taxId": 1}';
$main::lxdebug->dump(0, 'WH: SHOPDATA', \%shop_data );
my $dataString = SL::JSON::to_json(\%shop_data);
$dataString = encode_utf8($dataString);
$main::lxdebug->message(0, 'WH: JSONDATA2 '.$dataString);
if($import->{success}){
#update
$main::lxdebug->message(0, "WH: if success: ". $import->{success});
#update
my $upload = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $dataString);
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload);
}else{
#upload
$main::lxdebug->message(0, "WH: else success: ". $import->{success});
templates/webpages/ic/tabs/_shop.html
<td>[% L.html_tag('span', shop_part.shop_description, id => 'shop_part_description_' _ shop_part.id ) %]</td>
<td>[% L.html_tag('span', shop_part.last_update.to_kivitendo('precision' => 'minute'), id => 'shop_part_last_update_' _ shop_part.id ) %]</td>
<td>[% L.button_tag("kivi.shop_part.edit_shop_part(" _ shop_part.id _ ")", LxERP.t8("Edit")) %]</td>
<td>[% L.button_tag("kivi.shop_part.update_shop_part(" _ shop_part.id _ ")", LxERP.t8("Update")) %]</td>
<td>[% L.button_tag("kivi.shop_part.update_shop_part(" _ shop_part.id _ ")", LxERP.t8("Upload")) %]</td>
<td>[% L.button_tag("kivi.shop_part.get_all_categories(" _ shop_part.id _ ")", LxERP.t8("Shopcategories")) %]</td>
</tr>
[%- END %]
......
[%- FOREACH var = CUSTOM_VARIABLES %]
[%- IF var.name.match('^shop_') %]
<tr>
[%- IF !var.partsgroup_filtered %]
[% # IF !var.partsgroup_filtered %]
<td align="right" valign="top">[% HTML.escape(var.description) %]</td>
[%- END %]
[% # END %]
<td valign="top">[% var.HTML_CODE %]</td>
</tr>
[%- END %]
......
var url = 'controller.pl?action=ShopPart/show_files&modul=shop_part&id=[% shop_part.part_id %]';
$('#shop_images').load(url);
}
<!-- TODO -->
$(window).load(function() {
show_images();
});

Auch abrufbar als: Unified diff