Revision 75db0490
Von Werner Hahn vor mehr als 7 Jahren hinzugefügt
SL/Controller/ShopPart.pm | ||
---|---|---|
56 | 56 |
|
57 | 57 |
sub action_show_files { |
58 | 58 |
my ($self) = @_; |
59 |
$main::lxdebug->dump(0, 'WH: Show_Files',\$::form); |
|
59 |
|
|
60 | 60 |
require SL::DB::File; |
61 | 61 |
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' ); |
62 |
$main::lxdebug->dump(0, 'WH: ',\$images); |
|
63 |
#my $html = $self->render('shop_part/_list_images', { output => 0 }, IMAGES => $images); |
|
64 |
$self->render('shop_part/_list_images', { header => 0 }, IMAGES => $images); |
|
65 |
#$main::lxdebug->dump(0, 'WH: ',\$html); |
|
66 |
|
|
67 |
#$self->js->html('#shop_images', $html); |
|
68 |
#$self->js->render; |
|
69 |
|
|
70 |
# $self->render('customer_vendor_turnover/count_open_items_by_year', { layout => 0 }); |
|
71 | 62 |
|
63 |
$self->render('shop_part/_list_images', { header => 0 }, IMAGES => $images); |
|
72 | 64 |
|
73 | 65 |
} |
74 | 66 |
|
75 | 67 |
sub action_get_categories { |
76 | 68 |
my ($self) = @_; |
77 | 69 |
|
78 |
my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id}); |
|
79 |
die unless $shop_part; |
|
70 |
# my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
|
|
71 |
# die unless $shop_part;
|
|
80 | 72 |
require SL::Shop; |
81 |
my $shop = SL::Shop->new( config => $shop_part->shop ); |
|
73 |
my $shop = SL::Shop->new( config => $self->shop_part->shop );
|
|
82 | 74 |
my $categories = $shop->connector->get_categories; |
83 |
$main::lxdebug->dump(0, 'WH: GET',\$categories); |
|
84 | 75 |
|
85 | 76 |
$self->js |
86 | 77 |
->run( |
... | ... | |
145 | 136 |
$self->js->render; |
146 | 137 |
} |
147 | 138 |
|
148 |
sub render_shop_categories_edit_dialog {
|
|
139 |
sub action_save_categories {
|
|
149 | 140 |
my ($self) = @_; |
150 | 141 |
|
151 |
# when self->shop_part is called in template, it will be an existing shop_part with id,
|
|
152 |
# or a new shop_part with only part_id and shop_id set
|
|
153 |
$self->js
|
|
154 |
->run(
|
|
155 |
'kivi.shop_part.shop_part_dialog',
|
|
156 |
t8('Shopcategories'),
|
|
157 |
$self->render('shop_part/categories', { output => 0 }) #, shop_part => $self->shop_part)
|
|
158 |
)
|
|
159 |
->reinit_widgets;
|
|
142 |
my @categories = @{ $::form->{categories} || [] };
|
|
143 |
$main::lxdebug->dump(0, 'WH: KATEGORIEN: ', \@categories);
|
|
144 |
my @cat = ();
|
|
145 |
foreach my $cat ( @categories) {
|
|
146 |
# TODO das koma macht Probleme z.B kategorie "Feldsalat, Rapunzel"
|
|
147 |
my @temp = [split(/,/,$cat)];
|
|
148 |
push( @cat, @temp );
|
|
149 |
}
|
|
150 |
$main::lxdebug->dump(0, 'WH: KAT2:',\@cat);
|
|
160 | 151 |
|
161 |
$self->js->render; |
|
152 |
my $categories->{shop_category} = \@cat; |
|
153 |
|
|
154 |
my $params = delete($::form->{shop_part}) || { }; |
|
155 |
|
|
156 |
$self->shop_part->assign_attributes(%{ $params }); |
|
157 |
$self->shop_part->assign_attributes(%{ $categories }); |
|
158 |
|
|
159 |
$self->shop_part->save; |
|
160 |
|
|
161 |
flash('info', t8('The categories has been saved.')); |
|
162 |
|
|
163 |
$self->js->run('kivi.shop_part.close_dialog') |
|
164 |
->flash('info', t8("Updated categories")) |
|
165 |
->render; |
|
162 | 166 |
} |
167 |
|
|
163 | 168 |
sub action_reorder { |
164 | 169 |
my ($self) = @_; |
165 | 170 |
$main::lxdebug->message(0, "WH:REORDER "); |
SL/DB/ShopPart.pm | ||
---|---|---|
9 | 9 |
use SL::DB::MetaSetup::ShopPart; |
10 | 10 |
use SL::DB::Manager::ShopPart; |
11 | 11 |
use SL::DB::Helper::AttrHTML; |
12 |
use SL::DB::Helper::ActsAsList; |
|
12 |
#use SL::DB::Helper::ActsAsList;
|
|
13 | 13 |
|
14 | 14 |
__PACKAGE__->meta->initialize; |
15 | 15 |
__PACKAGE__->attr_html('shop_description'); |
SL/ShopConnector/Shopware.pm | ||
---|---|---|
173 | 173 |
sub get_article { |
174 | 174 |
} |
175 | 175 |
|
176 |
sub get_articles { |
|
177 |
} |
|
176 |
sub update_part { |
|
177 |
my ($self, $shop_part, $json) = @_; |
|
178 |
|
|
179 |
#shop_part is passed as a param |
|
180 |
die unless ref($shop_part) eq 'SL::DB::ShopPart'; |
|
181 |
|
|
182 |
$main::lxdebug->dump(0, 'WH: UPDATE SHOPPART: ', \$shop_part); |
|
183 |
$main::lxdebug->dump(0, 'WH: UPDATE SELF: ', \$self); |
|
184 |
$main::lxdebug->dump(0, 'WH: UPDATE JSON: ', \$json); |
|
185 |
my $url = $self->url; |
|
186 |
my $part = SL::DB::Part->new(id => $shop_part->{part_id})->load; |
|
187 |
#my $part = $shop_part->part; |
|
188 |
$main::lxdebug->dump(0, 'WH: Part',\$part); |
|
189 |
|
|
190 |
# TODO: Prices (pricerules, pricegroups, |
|
191 |
my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } }; |
|
192 |
#my $categories = { map { ( name => $_) } @{ $shop_part->{shop_category} } }; |
|
193 |
my @cat = (); |
|
194 |
foreach my $row_cat ( @{ $shop_part->shop_category } ) { |
|
195 |
$main::lxdebug->dump(0, 'WH:ROWCAT ',\$row_cat); |
|
196 |
|
|
197 |
my $temp = { ( id => @{$row_cat}[0], ) }; |
|
198 |
$main::lxdebug->dump(0, 'WH: TEMP: ', \$temp); |
|
199 |
|
|
200 |
push ( @cat, $temp ); |
|
201 |
#push ( @cat, map { ( name => $_[1]) } @{ $row_cat } ); |
|
202 |
} |
|
203 |
$main::lxdebug->dump(0, 'WH: CATEGORIES',\@cat); |
|
204 |
my $images = SL::DB::Manager::File->get_all( where => [ modul => 'shop_part', trans_id => $part->{id} ]); |
|
205 |
$main::lxdebug->dump(0, 'WH: IMAGES',\@{ $images } ); |
|
206 |
my $images2 = { map { |
|
207 |
( link => 'data:' . $_->{file_content_type} . ';base64,' . MIME::Base64::encode($_->{file_content},''), |
|
208 |
description => $_->{title}, |
|
209 |
position => $_->{position}, |
|
210 |
extension => 'jpg', # muss $extionsion sein |
|
211 |
path => $_->{filename}, # muss $path sein |
|
212 |
) } @{ $images } }; |
|
213 |
$main::lxdebug->dump(0, 'WH: IMAGES 2 ',\$images2); |
|
214 |
|
|
215 |
my @images3 = (); |
|
216 |
foreach my $img (@{ $images }) { |
|
217 |
$main::lxdebug->dump(0, 'WH: FOR: ', \$img); |
|
218 |
|
|
219 |
my ($path, $extension) = (split /\./, $img->{filename}); |
|
220 |
$main::lxdebug->message(0, "WH: PATH: $path Ext: $extension"); |
|
221 |
|
|
222 |
my $temp ={ |
|
223 |
( link => 'data:' . $img->{file_content_type} . ';base64,' . MIME::Base64::encode($img->{file_content},''), |
|
224 |
description => $img->{title}, |
|
225 |
position => $img->{position}, |
|
226 |
extension => $extension, |
|
227 |
path => $path, |
|
228 |
)} ; |
|
229 |
push( @images3, $temp); |
|
230 |
} |
|
231 |
$main::lxdebug->dump(0, 'WH: IMAGES 3 ',\@images3); |
|
232 |
|
|
233 |
my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true"); |
|
234 |
my $data_json = $data->content; |
|
235 |
my $import = SL::JSON::decode_json($data_json); |
|
236 |
$main::lxdebug->dump(0, 'WH: IMPORT', \$import); |
|
237 |
$main::lxdebug->dump(0, 'WH: Active', $shop_part->active); |
|
238 |
|
|
239 |
|
|
240 |
my %shop_data = ( name => $part->{description}, |
|
241 |
taxId => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00 |
|
242 |
mainDetail => { number => $part->{partnumber}, |
|
243 |
inStock => $part->{onhand}, |
|
244 |
prices => [ { from => 1, |
|
245 |
price => $part->{sellprice}, |
|
246 |
customerGroupKey => 'EK', |
|
247 |
}, |
|
248 |
], |
|
249 |
}, |
|
250 |
supplier => $cvars->{freifeld_7}->{value}, |
|
251 |
description => $shop_part->{shop_description}, |
|
252 |
active => $shop_part->active, |
|
253 |
images => [ @images3 ], |
|
254 |
__options_images => { replace => 1, }, |
|
255 |
categories => [ @cat ], #{ path => 'Deutsch|test2' }, ], #[ $categories ], |
|
256 |
|
|
257 |
) |
|
258 |
; |
|
259 |
$main::lxdebug->dump(0, 'WH: SHOPDATA', \%shop_data ); |
|
260 |
my $dataString = SL::JSON::to_json(\%shop_data); |
|
261 |
$dataString = encode_utf8($dataString); |
|
262 |
$main::lxdebug->message(0, 'WH: JSONDATA2 '.$dataString); |
|
263 |
if($import->{success}){ |
|
264 |
$main::lxdebug->message(0, "WH: if success: ". $import->{success}); |
|
265 |
my %del_img = ( images => [ {} ], ) ; |
|
266 |
my $del_imgString = SL::JSON::to_json(\%del_img); |
|
267 |
#my $delImg = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $del_imgString); |
|
268 |
#update |
|
269 |
my $upload = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $dataString); |
|
270 |
my $data_json = $upload->content; |
|
271 |
my $upload_content = SL::JSON::decode_json($data_json); |
|
272 |
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload); |
|
273 |
return $upload_content->{success}; |
|
274 |
}else{ |
|
275 |
#upload |
|
276 |
$main::lxdebug->message(0, "WH: else success: ". $import->{success}); |
|
277 |
my $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString); |
|
278 |
my $data_json = $upload->content; |
|
279 |
my $upload_content = SL::JSON::decode_json($data_json); |
|
280 |
$main::lxdebug->dump(0, "WH:2 else success: ", \$upload); |
|
281 |
return $upload_content->{success}; |
|
282 |
} |
|
178 | 283 |
|
179 |
sub set_article {
|
|
284 |
>>>>>>> b616804... Kategorien werden mit ID und Name in die DB geschrieben. Ein Komma im Name erzeugt noch Fehler. Der Pfad muss noch gemacht werden
|
|
180 | 285 |
} |
181 | 286 |
|
182 | 287 |
sub init_url { |
sql/Pg-upgrade2/shop_parts_2.sql | ||
---|---|---|
1 |
-- @tag: shop_parts_2 |
|
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/shop_part/categories.html | ||
---|---|---|
1 |
[%- USE HTML %] |
|
2 |
[%- USE T8 %] |
|
3 |
[%- USE L -%] |
|
4 |
[%- USE P -%] |
|
5 |
[%- USE LxERP -%] |
|
6 |
[%- USE Dumper -%] |
|
7 |
|
|
8 |
[% LxERP.t8("Part") %]: [% HTML.escape(SELF.shop_part.part.displayable_name) %]<br> |
|
9 |
[% LxERP.t8("Shop") %]: [% HTML.escape(SELF.shop_part.shop.description) %] |
|
10 |
<br> |
|
11 |
[% # Dumper.dump_html(SELF.shop_part.shop_category) %] |
|
12 |
<br> |
|
13 |
[% # Dumper.dump_html(CATEGORIES) %] |
|
14 |
|
|
15 |
<form action="controller.pl" method="post"> |
|
16 |
[% BLOCK recurse %] |
|
17 |
[% # path = '' %]<!-- TODO: Pfad wg neuer Kategorie im Shop anlegen --> |
|
18 |
[% FOREACH obj = data %] |
|
19 |
<ul> |
|
20 |
<li> |
|
21 |
[% checked = '' %] |
|
22 |
[% # path = path _ obj.name %] |
|
23 |
[% # test = path.split('\|') %] |
|
24 |
[% # Dumper.dump_html(SELF.shop_part.shop_category.size) %] |
|
25 |
[% IF SELF.shop_part.shop_category.1.grep(obj.name).size %] |
|
26 |
[% checked = 'checked' %] |
|
27 |
[% ELSE %] |
|
28 |
[% FOREACH cat_row = SELF.shop_part.shop_category %] |
|
29 |
[% IF cat_row.1.grep(obj.name).size %] |
|
30 |
[% checked = 'checked' %] |
|
31 |
[% END %] |
|
32 |
[% END %] |
|
33 |
[% END %] |
|
34 |
[% L.checkbox_tag('categories[]',value=obj.id _"," _ obj.name _ ",PFAD", checked=checked) %][% HTML.escape(obj.name) %]</li> |
|
35 |
[% IF obj.childrenCount >= 1 %] |
|
36 |
[% # path = path _ '|' %] |
|
37 |
[% INCLUDE recurse data=obj.children %] |
|
38 |
[% END %] |
|
39 |
</ul> |
|
40 |
[% END %] |
|
41 |
[% END %] |
|
42 |
<div><h2>[% LxERP.t8("Shopcategories") %]</h2> |
|
43 |
[% FOREACH row = CATEGORIES %] |
|
44 |
[% IF row.name == 'Root' %] |
|
45 |
[% IF row.childrenCount >= 1 %] |
|
46 |
[% path = '' %] |
|
47 |
[% INCLUDE recurse data=row.children path=path %] |
|
48 |
[% END %] |
|
49 |
[% END %] |
|
50 |
[% END %] |
|
51 |
</div> |
|
52 |
[% L.button_tag("kivi.shop_part.save_categories(" _ SELF.shop_part.id _", " _ SELF.shop_part.shop.id _")", LxERP.t8("Save")) %]</td> |
|
53 |
</form> |
|
54 |
|
templates/webpages/shop_part/edit.html | ||
---|---|---|
42 | 42 |
<td>[% LxERP.t8("Meta Tags") %]</td> |
43 | 43 |
<td>[% L.input_tag("shop_part.meta_tags", SELF.shop_part.meta_tags, size=2) %]</td> |
44 | 44 |
</tr> |
45 |
<tr> |
|
46 |
<td>[% LxERP.t8("Shop Category") %]</td> |
|
47 |
<td>[% L.input_tag("shop_part.shop_category", SELF.shop_part.category, size=2) %]</td> |
|
48 |
</tr> |
|
49 | 45 |
</table> |
50 | 46 |
[% # L.dump(SELF.shop_part) %] |
51 | 47 |
|
Auch abrufbar als: Unified diff
Shopmodul: Kategorien werden in die DB geschrieben
Conflicts:
SL/DB/MetaSetup/ShopPart.pm
Shoppart: Shopkategorien sind zugeordnet und werden mit checkbox angezeigt
Kategorien werden mit ID und Name in die DB geschrieben. Ein Komma im Name erzeugt noch Fehler. Der Pfad muss noch gemacht werden
Conflicts:
SL/ShopConnector/Shopware.pm
ShopPart: ArtikelKategorien werden über ID in den Shop dem Artikle zugeordnet