Revision 63720c4e
Von Werner Hahn vor mehr als 8 Jahren hinzugefügt
SL/Controller/ShopPart.pm | ||
---|---|---|
7 | 7 |
use Data::Dumper; |
8 | 8 |
use SL::Locale::String qw(t8); |
9 | 9 |
use SL::DB::ShopPart; |
10 |
use SL::DB::File; |
|
10 | 11 |
use SL::DB::Default; |
11 | 12 |
use SL::Helper::Flash; |
12 | 13 |
|
... | ... | |
32 | 33 |
|
33 | 34 |
my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id}); |
34 | 35 |
die unless $shop_part; |
36 |
$main::lxdebug->dump(0, 'WH: ShopPart',\$shop_part); |
|
37 |
|
|
38 |
#my $part = SL::DB::Manager::Part->find_by(id => $shop_part->{part_id}); |
|
39 |
#$main::lxdebug->dump(0, 'WH: Part',\$part); |
|
40 |
|
|
41 |
#my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } }; |
|
42 |
#$main::lxdebug->dump(0, 'WH: CVARS',\$cvars); |
|
43 |
|
|
44 |
#my $images = SL::DB::Manager::File->get_all_sorted( where => [ trans_id => $shop_part->{part_id}, modul => 'shop_part', file_content_type => { like => 'image/%' } ], sort_by => 'position' ); |
|
45 |
#$main::lxdebug->dump(0, 'WH: Images',\$images); |
|
46 |
|
|
47 |
#$part->{shop_part} = $shop_part; |
|
48 |
#$part->{cvars} = $cvars; |
|
49 |
#$part->{images} = $images; |
|
50 |
|
|
51 |
#$main::lxdebug->dump(0, 'WH: Part II',\$part); |
|
35 | 52 |
require SL::Shop; |
36 | 53 |
my $shop = SL::Shop->new( config => $shop_part->shop ); |
37 | 54 |
|
38 |
# TODO: generate data to upload to shop |
|
55 |
# TODO: generate data to upload to shop. Goes to SL::Connector::XXXConnector. Here the object holds all data from parts, shop_parts, files, custom_variables for one article
|
|
39 | 56 |
my $part_hash = $shop_part->part->as_tree; |
40 | 57 |
my $json = SL::JSON::to_json($part_hash); |
41 | 58 |
my $return = $shop->connector->update_part($self->shop_part, $json); |
... | ... | |
56 | 73 |
sub action_show_files { |
57 | 74 |
my ($self) = @_; |
58 | 75 |
|
59 |
require SL::DB::File; |
|
60 | 76 |
my $images = SL::DB::Manager::File->get_all_sorted( where => [ trans_id => $::form->{id}, modul => $::form->{modul}, file_content_type => { like => 'image/%' } ], sort_by => 'position' ); |
61 | 77 |
|
62 | 78 |
$self->render('shop_part/_list_images', { header => 0 }, IMAGES => $images); |
... | ... | |
214 | 230 |
=head1 AUTHORS |
215 | 231 |
|
216 | 232 |
G. Richardson E<lt>information@kivitendo-premium.deE<gt> |
217 |
|
|
233 |
W. Hahn E<lt>wh@futureworldsearch.netE<gt> |
|
218 | 234 |
=cut |
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 { |
js/kivi.shop_part.js | ||
---|---|---|
46 | 46 |
var form = $('form').serializeArray(); |
47 | 47 |
form.push( { name: 'action', value: 'ShopPart/update' } |
48 | 48 |
); |
49 |
|
|
49 |
alert(form.join('\n')); |
|
50 | 50 |
$.post('controller.pl', form, function(data) { |
51 | 51 |
kivi.eval_json_result(data); |
52 | 52 |
}); |
templates/webpages/ic/tabs/_shop.html | ||
---|---|---|
41 | 41 |
[% # L.dump(shop_part) %] |
42 | 42 |
<hr> |
43 | 43 |
[%- IF CUSTOM_VARIABLES.size %] |
44 |
[% # L.dump(CUSTOM_VARIABLES) %] |
|
44 | 45 |
<div id="shop_custom_variables"> |
45 | 46 |
<p> |
46 | 47 |
<table> |
templates/webpages/shop_part/categories.html | ||
---|---|---|
28 | 28 |
[% END %] |
29 | 29 |
<div><h2>[% LxERP.t8("Shopcategories") %]</h2> |
30 | 30 |
[% FOREACH row = CATEGORIES %] |
31 |
<!-- TODO: Is still hardcoded 'Root' is shopware specified --> |
|
31 | 32 |
[% IF row.name == 'Root' %] |
32 | 33 |
[% IF row.childrenCount >= 1 %] |
33 | 34 |
[% INCLUDE recurse data=row.children %] |
Auch abrufbar als: Unified diff
ShopPart: Test Artikel wird mit json im LWP::UserAgent in den Shop hochgeladen