Revision 7d0bf515
Von Werner Hahn vor mehr als 8 Jahren hinzugefügt
SL/Controller/ShopPart.pm | ||
---|---|---|
34 | 34 |
|
35 | 35 |
my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id}); |
36 | 36 |
die unless $shop_part; |
37 |
$main::lxdebug->dump(0, 'WH: ShopPart',\$shop_part); |
|
38 | 37 |
|
39 |
#my $part = SL::DB::Manager::Part->find_by(id => $shop_part->{part_id}); |
|
40 |
#$main::lxdebug->dump(0, 'WH: Part',\$part); |
|
41 |
|
|
42 |
#my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } }; |
|
43 |
#$main::lxdebug->dump(0, 'WH: CVARS',\$cvars); |
|
44 |
|
|
45 |
#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' ); |
|
46 |
#$main::lxdebug->dump(0, 'WH: Images',\$images); |
|
47 |
|
|
48 |
#$part->{shop_part} = $shop_part; |
|
49 |
#$part->{cvars} = $cvars; |
|
50 |
#$part->{images} = $images; |
|
51 |
|
|
52 |
$main::lxdebug->dump(0, 'WH: ShopPart I',\$self->shop_part); |
|
53 | 38 |
require SL::Shop; |
54 | 39 |
my $shop = SL::Shop->new( config => $shop_part->shop ); |
55 | 40 |
|
... | ... | |
100 | 85 |
$self->js->render; |
101 | 86 |
} |
102 | 87 |
|
103 |
# old: |
|
104 |
# sub action_edit { |
|
105 |
# my ($self) = @_; |
|
106 |
# |
|
107 |
# $self->render('shop_part/edit'); #, { output => 0 }); #, price_source => $price_source) |
|
108 |
# } |
|
109 |
# |
|
110 |
# used when saving existing ShopPart |
|
111 |
|
|
112 | 88 |
sub action_update { |
113 | 89 |
my ($self) = @_; |
114 | 90 |
|
... | ... | |
128 | 104 |
$self->shop_part->save; |
129 | 105 |
|
130 | 106 |
flash('info', $is_new ? t8('The shop part has been created.') : t8('The shop part has been saved.')); |
131 |
# $self->js->val('#partnumber', 'ladida'); |
|
132 | 107 |
$self->js->html('#shop_part_description_' . $self->shop_part->id, $self->shop_part->shop_description) |
133 | 108 |
->html('#shop_part_active_' . $self->shop_part->id, $self->shop_part->active) |
134 | 109 |
->run('kivi.shop_part.close_dialog') |
... | ... | |
156 | 131 |
my ($self) = @_; |
157 | 132 |
|
158 | 133 |
my @categories = @{ $::form->{categories} || [] }; |
159 |
$main::lxdebug->dump(0, 'WH: KATEGORIEN: ', \@categories); |
|
134 |
|
|
160 | 135 |
my @cat = (); |
161 | 136 |
foreach my $cat ( @categories) { |
162 | 137 |
# TODO das koma macht Probleme z.B kategorie "Feldsalat, Rapunzel" |
163 | 138 |
my @temp = [split(/,/,$cat)]; |
164 | 139 |
push( @cat, @temp ); |
165 | 140 |
} |
166 |
$main::lxdebug->dump(0, 'WH: KAT2:',\@cat); |
|
167 | 141 |
|
168 | 142 |
my $categories->{shop_category} = \@cat; |
169 | 143 |
|
... | ... | |
183 | 157 |
|
184 | 158 |
sub action_reorder { |
185 | 159 |
my ($self) = @_; |
186 |
$main::lxdebug->message(0, "WH:REORDER "); |
|
160 |
|
|
187 | 161 |
require SL::DB::File; |
188 | 162 |
SL::DB::File->reorder_list(@{ $::form->{image_id} || [] }); |
189 |
$main::lxdebug->message(0, "WH:REORDER II "); |
|
190 | 163 |
|
191 | 164 |
$self->render(\'', { type => 'json' }); |
192 | 165 |
} |
... | ... | |
241 | 214 |
|
242 | 215 |
G. Richardson E<lt>information@kivitendo-premium.deE<gt> |
243 | 216 |
W. Hahn E<lt>wh@futureworldsearch.netE<gt> |
217 |
|
|
244 | 218 |
=cut |
SL/ShopConnector/Shopware.pm | ||
---|---|---|
169 | 169 |
#shop_part is passed as a param |
170 | 170 |
die unless ref($shop_part) eq 'SL::DB::ShopPart'; |
171 | 171 |
|
172 |
$main::lxdebug->dump(0, 'WH: UPDATE SHOPPART: ', \$shop_part); |
|
173 |
$main::lxdebug->dump(0, 'WH: UPDATE SELF: ', \$self); |
|
174 |
$main::lxdebug->dump(0, 'WH: UPDATE JSON: ', \$json); |
|
175 | 172 |
my $url = $self->url; |
176 | 173 |
my $part = SL::DB::Part->new(id => $shop_part->{part_id})->load; |
177 |
#my $part = $shop_part->part; |
|
178 |
$main::lxdebug->dump(0, 'WH: Part',\$part); |
|
179 | 174 |
|
180 | 175 |
# TODO: Prices (pricerules, pricegroups, |
181 | 176 |
my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } }; |
182 |
#my $categories = { map { ( name => $_) } @{ $shop_part->{shop_category} } }; |
|
177 |
|
|
183 | 178 |
my @cat = (); |
184 | 179 |
foreach my $row_cat ( @{ $shop_part->shop_category } ) { |
185 |
$main::lxdebug->dump(0, 'WH:ROWCAT ',\$row_cat); |
|
186 |
|
|
187 | 180 |
my $temp = { ( id => @{$row_cat}[0], ) }; |
188 |
$main::lxdebug->dump(0, 'WH: TEMP: ', \$temp); |
|
189 |
|
|
190 | 181 |
push ( @cat, $temp ); |
191 | 182 |
#push ( @cat, map { ( name => $_[1]) } @{ $row_cat } ); |
192 | 183 |
} |
193 |
$main::lxdebug->dump(0, 'WH: CATEGORIES',\@cat); |
|
184 |
|
|
194 | 185 |
my $images = SL::DB::Manager::File->get_all( where => [ modul => 'shop_part', trans_id => $part->{id} ]); |
195 |
$main::lxdebug->dump(0, 'WH: IMAGES',\@{ $images } ); |
|
196 |
my $images2 = { map { |
|
197 |
( link => 'data:' . $_->{file_content_type} . ';base64,' . MIME::Base64::encode($_->{file_content},''), |
|
198 |
description => $_->{title}, |
|
199 |
position => $_->{position}, |
|
200 |
extension => 'jpg', # muss $extionsion sein |
|
201 |
path => $_->{filename}, # muss $path sein |
|
202 |
) } @{ $images } }; |
|
203 |
$main::lxdebug->dump(0, 'WH: IMAGES 2 ',\$images2); |
|
204 |
|
|
205 |
my @images3 = (); |
|
206 |
foreach my $img (@{ $images }) { |
|
207 |
$main::lxdebug->dump(0, 'WH: FOR: ', \$img); |
|
208 | 186 |
|
187 |
#my $images2 = { map { |
|
188 |
# ( link => 'data:' . $_->{file_content_type} . ';base64,' . MIME::Base64::encode($_->{file_content},''), |
|
189 |
# description => $_->{title}, |
|
190 |
# position => $_->{position}, |
|
191 |
# extension => 'jpg', # muss $extionsion sein |
|
192 |
# path => $_->{filename}, # muss $path sein |
|
193 |
# ) } @{ $images } }; |
|
194 |
|
|
195 |
my @upload_img = (); |
|
196 |
foreach my $img (@{ $images }) { |
|
209 | 197 |
my ($path, $extension) = (split /\./, $img->{filename}); |
210 |
$main::lxdebug->message(0, "WH: PATH: $path Ext: $extension"); |
|
211 | 198 |
|
212 | 199 |
my $temp ={ |
213 | 200 |
( link => 'data:' . $img->{file_content_type} . ';base64,' . MIME::Base64::encode($img->{file_content},''), |
... | ... | |
216 | 203 |
extension => $extension, |
217 | 204 |
path => $path, |
218 | 205 |
)} ; |
219 |
push( @images3, $temp);
|
|
206 |
push( @upload_img, $temp);
|
|
220 | 207 |
} |
221 |
$main::lxdebug->dump(0, 'WH: IMAGES 3 ',\@images3); |
|
222 | 208 |
|
223 | 209 |
my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true"); |
224 | 210 |
my $data_json = $data->content; |
225 | 211 |
my $import = SL::JSON::decode_json($data_json); |
226 |
$main::lxdebug->dump(0, 'WH: IMPORT', \$import); |
|
227 |
$main::lxdebug->dump(0, 'WH: Active', $shop_part->active); |
|
228 |
|
|
229 | 212 |
|
230 | 213 |
my %shop_data = ( name => $part->{description}, |
231 | 214 |
taxId => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00 |
... | ... | |
240 | 223 |
supplier => $cvars->{freifeld_7}->{value}, |
241 | 224 |
description => $shop_part->{shop_description}, |
242 | 225 |
active => $shop_part->active, |
243 |
images => [ @images3 ],
|
|
226 |
images => [ @upload_img ],
|
|
244 | 227 |
__options_images => { replace => 1, }, |
245 | 228 |
categories => [ @cat ], #{ path => 'Deutsch|test2' }, ], #[ $categories ], |
246 | 229 |
|
247 | 230 |
) |
248 | 231 |
; |
249 |
$main::lxdebug->dump(0, 'WH: SHOPDATA', \%shop_data ); |
|
250 |
my $dataString = SL::JSON::to_json(\%shop_data); |
|
251 |
$dataString = encode_utf8($dataString); |
|
252 |
$main::lxdebug->message(0, 'WH: JSONDATA2 '.$dataString); |
|
232 |
my $dataString = SL::JSON::to_json(\%shop_data); |
|
233 |
$dataString = encode_utf8($dataString); |
|
234 |
|
|
253 | 235 |
if($import->{success}){ |
254 |
$main::lxdebug->message(0, "WH: if success: ". $import->{success}); |
|
255 |
my %del_img = ( images => [ {} ], ) ; |
|
256 |
my $del_imgString = SL::JSON::to_json(\%del_img); |
|
257 |
#my $delImg = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $del_imgString); |
|
258 | 236 |
#update |
259 | 237 |
my $upload = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $dataString); |
260 | 238 |
my $data_json = $upload->content; |
261 | 239 |
my $upload_content = SL::JSON::decode_json($data_json); |
262 |
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload); |
|
263 | 240 |
return $upload_content->{success}; |
264 | 241 |
}else{ |
265 | 242 |
#upload |
266 |
$main::lxdebug->message(0, "WH: else success: ". $import->{success}); |
|
267 | 243 |
my $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString); |
268 | 244 |
my $data_json = $upload->content; |
269 | 245 |
my $upload_content = SL::JSON::decode_json($data_json); |
270 |
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload); |
|
271 | 246 |
return $upload_content->{success}; |
272 | 247 |
} |
273 | 248 |
|
... | ... | |
281 | 256 |
|
282 | 257 |
sub init_connector { |
283 | 258 |
my ($self) = @_; |
284 |
$main::lxdebug->dump(0, 'WH: CONNECTOR: ',\$self); |
|
285 | 259 |
my $ua = LWP::UserAgent->new; |
286 | 260 |
$ua->credentials( |
287 | 261 |
$self->url, |
288 | 262 |
"Shopware REST-API", |
289 | 263 |
$self->config->login => $self->config->password |
290 | 264 |
); |
291 |
$main::lxdebug->dump(0, 'WH: UA: ',\$ua); |
|
292 | 265 |
return $ua; |
293 | 266 |
}; |
294 | 267 |
|
... | ... | |
312 | 285 |
|
313 | 286 |
=head1 AUTHOR |
314 | 287 |
|
288 |
W. Hahn E<lt>wh@futureworldsearch.netE<gt> |
|
289 |
|
|
315 | 290 |
=cut |
js/kivi.shop_part.js | ||
---|---|---|
46 | 46 |
var form = $('form').serializeArray(); |
47 | 47 |
form.push( { name: 'action', value: 'ShopPart/update' } |
48 | 48 |
); |
49 |
alert(form.join('\n')); |
|
49 |
//alert(form.join('\n'));
|
|
50 | 50 |
$.post('controller.pl', form, function(data) { |
51 | 51 |
kivi.eval_json_result(data); |
52 | 52 |
}); |
sql/Pg-upgrade2/shop_parts_3.sql | ||
---|---|---|
1 |
-- @tag: shop_parts_3 |
|
2 |
-- @description: Add tables for part information for shop |
|
3 |
-- @charset: UTF-8 |
|
4 |
-- @depends: release_3_3_0 shops |
|
5 |
-- @ignore: 0 |
|
6 |
ALTER TABLE shop_parts ALTER COLUMN shop_category TYPE TEXT[][] USING array[shop_category]; |
templates/webpages/common/file_upload.html | ||
---|---|---|
1 | 1 |
[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% USE Base64 %] |
2 | 2 |
[% SET style="width: 500px" %] |
3 | 3 |
[% SET id_base = "fileupload" %] |
4 |
[% L.dump(DATA) %] |
|
4 |
[% # L.dump(DATA) %]
|
|
5 | 5 |
<form method="post" id="fileupload_form" method="POST" enctype="multipart/form-data"> |
6 | 6 |
[% L.hidden_tag('form_prefix', id_base, id=id_base _ '_form_prefix') %] |
7 | 7 |
[% L.hidden_tag('id', DATA.id, no_id=1) %] |
templates/webpages/shop_part/categories.html | ||
---|---|---|
14 | 14 |
|
15 | 15 |
<form action="controller.pl" method="post"> |
16 | 16 |
[% BLOCK recurse %] |
17 |
[% # path = '' %]<!-- TODO: Pfad wg neuer Kategorie im Shop anlegen --> |
|
17 |
[% # path = '' %]<!-- TODO: Pfad wg neuer Kategorie im Shop anlegen -->
|
|
18 | 18 |
[% FOREACH obj = data %] |
19 | 19 |
<ul> |
20 | 20 |
<li> |
Auch abrufbar als: Unified diff
ShopPart: Debugs rausgenommen