Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 64ab69bc

Von Werner Hahn vor mehr als 6 Jahren hinzugefügt

  • ID 64ab69bcb3cfd58cd26a2f1be959b5232d3376e8
  • Vorgänger 60f92e55
  • Nachfolger 67afa30b

Shopmodul: Shoppart - Alle Daten werden angezeigt (Lager Lokal/Shop, Preisquelle, Preis) Lastupload Zeit wird in DB geschrieben und auch angezeigt

Shoppart: Alle Daten werden angezeigt (Lager Lokal/Shop, Preisquelle, Preis) Lastupload Zeit wird in DB geschrieben und auch angezeigt.
Formatierungen in den js für Zahlen fehlen noch Kleinere TODOs

Conflicts:
SL/Controller/ShopPart.pm
SL/ShopConnector/Shopware.pm
templates/webpages/ic/tabs/_shop.html

Shoppart: Last Upload article is written in db

Conflicts:
SL/ShopConnector/Shopware.pm

Conflicts:
SL/Controller/ShopPart.pm
SL/ShopConnector/Shopware.pm
js/kivi.shop_part.js

Unterschiede anzeigen:

SL/Controller/ShopPart.pm
8 8
use Data::Dumper;
9 9
use SL::Locale::String qw(t8);
10 10
use SL::DB::ShopPart;
11
use SL::DB::File;
12
use SL::Controller::FileUploader;
11 13
use SL::DB::Default;
12 14
use SL::Helper::Flash;
13 15

  
14 16
use Rose::Object::MakeMethods::Generic
15 17
(
16
  'scalar --get_set_init' => [ qw(shop_part js) ],
18
   scalar                 => [ qw(price_sources) ],
19
  'scalar --get_set_init' => [ qw(shop_part file) ],
17 20
);
18 21

  
19 22
__PACKAGE__->run_before('check_auth');
20 23
__PACKAGE__->run_before('add_javascripts', only => [ qw(edit_popup) ]);
24
__PACKAGE__->run_before('load_pricesources',    only => [ qw(create_or_edit_popup) ]);
25

  
21 26
#
22 27
# actions
23 28
#
......
36 41
  require SL::Shop;
37 42
  my $shop = SL::Shop->new( config => $shop_part->shop );
38 43

  
39
  # TODO: generate data to upload to shop
44
  # data to upload to shop. Goes to SL::Connector::XXXConnector.
40 45
  my $part_hash = $shop_part->part->as_tree;
41 46
  my $json      = SL::JSON::to_json($part_hash);
42 47
  my $return    = $shop->connector->update_part($self->shop_part, $json);
43 48

  
44 49
  # the connector deals with parsing/result verification, just needs to return success or failure
45 50
  if ( $return == 1 ) {
46
    # TODO: write update time to DB
47 51
    my $now = DateTime->now;
52
    my $attributes->{last_update} = $now;
53
    $self->shop_part->assign_attributes(%{ $attributes });
54
    $self->shop_part->save;
48 55
    $self->js->html('#shop_part_last_update_' . $shop_part->id, $now->to_kivitendo('precision' => 'minute'))
49 56
           ->flash('info', t8("Updated part [#1] in shop [#2] at #3", $shop_part->part->displayable_name, $shop_part->shop->description, $now->to_kivitendo('precision' => 'minute') ) )
50 57
           ->render;
......
61 68
  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 69

  
63 70
  $self->render('shop_part/_list_images', { header => 0 }, IMAGES => $images);
71
}
72

  
73
sub action_ajax_upload_file{
74
  my ($self, %params) = @_;
75

  
76
  my $attributes                   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
77

  
78
  $attributes->{filename} = ((($::form->{ATTACHMENTS} || {})->{ $::form->{form_prefix} } || {})->{file_content} || {})->{filename};
79

  
80
  my @errors;
81
  my @file_errors = SL::DB::File->new(%{ $attributes })->validate;
82
  push @errors,@file_errors if @file_errors;
83

  
84
  my @type_error = SL::Controller::FileUploader->validate_filetype($attributes->{filename},$::form->{aft});
85
  push @errors,@type_error if @type_error;
86

  
87
  return $self->js->error(@errors)->render($self) if @errors;
88

  
89
  $self->file->assign_attributes(%{ $attributes });
90
  $self->file->file_update_type_and_dimensions;
91
  $self->file->save;
92

  
93
  $self->js
94
    ->dialog->close('#jqueryui_popup_dialog')
95
    ->run('kivi.shop_part.show_images',$self->file->trans_id)
96
    ->render();
97
}
98

  
99
sub action_ajax_update_file{
100
  my ($self, %params) = @_;
101

  
102
  my $attributes                   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
103

  
104
  if (!$attributes->{file_content}) {
105
    delete $attributes->{file_content};
106
  } else {
107
    $attributes->{filename} = ((($::form->{ATTACHMENTS} || {})->{ $::form->{form_prefix} } || {})->{file_content} || {})->{filename};
108
  }
109

  
110
  my @errors;
111
  my @type_error = SL::Controller::FileUploader->validate_filetype($attributes->{filename},$::form->{aft});
112
  push @errors,@type_error if @type_error;
113
  $self->file->assign_attributes(%{ $attributes });
114
  my @file_errors = $self->file->validate if $attributes->{file_content};;
115
  push @errors,@file_errors if @file_errors;
116

  
117

  
118
  return $self->js->error(@errors)->render($self) if @errors;
119

  
120
  $self->file->file_update_type_and_dimensions if $attributes->{file_content};
121
  $self->file->save;
122

  
123
  $self->js
124
    ->dialog->close('#jqueryui_popup_dialog')
125
    ->run('kivi.shop_part.show_images',$self->file->trans_id)
126
    ->render();
127
}
128

  
129
sub action_ajax_delete_file {
130
  my ( $self ) = @_;
131
  $self->file->delete;
64 132

  
133
  $self->js
134
    ->run('kivi.shop_part.show_images',$self->file->trans_id)
135
    ->render();
65 136
}
66 137

  
67 138
sub action_get_categories {
68 139
  my ($self) = @_;
69 140

  
70
#  my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
71
#  die unless $shop_part;
72 141
  require SL::Shop;
73 142
  my $shop = SL::Shop->new( config => $self->shop_part->shop );
74 143
  my $categories = $shop->connector->get_categories;
......
77 146
    ->run(
78 147
      'kivi.shop_part.shop_part_dialog',
79 148
      t8('Shopcategories'),
80
      $self->render('shop_part/categories', { output => 0 }, CATEGORIES => $categories ) #, shop_part => $self->shop_part)
149
      $self->render('shop_part/categories', { output => 0 }, CATEGORIES => $categories )
81 150
    )
82 151
    ->reinit_widgets;
83 152

  
......
99 168
  $self->create_or_update;
100 169
}
101 170

  
171
sub action_show_price_n_pricesource {
172
  my ($self) = @_;
173

  
174
  my ( $price, $price_src_str ) = $self->get_price_n_pricesource($::form->{pricesource});
175

  
176
  #TODO Price must be formatted. $price_src_str must be translated
177
  $self->js->html('#price_' . $self->shop_part->id, $price)
178
           ->html('#active_price_source_' . $self->shop_part->id, $price_src_str)
179
           ->render;
180
}
181

  
182
sub action_show_stock {
183
  my ($self) = @_;
184
  my ( $stock_local, $stock_onlineshop );
185

  
186
  require SL::Shop;
187
  my $shop = SL::Shop->new( config => $self->shop_part->shop );
188
  my $shop_article = $shop->connector->get_article($self->shop_part->part->partnumber);
189

  
190
  $stock_local = $self->shop_part->part->onhand;
191
  $stock_onlineshop = $shop_article->{data}->{mainDetail}->{inStock};
192

  
193
  $self->js->html('#stock_' . $self->shop_part->id, $stock_local."/".$stock_onlineshop)
194
           ->render;
195
}
196

  
197

  
102 198
sub create_or_update {
103 199
  my ($self) = @_;
104 200

  
......
111 207

  
112 208
  $self->shop_part->save;
113 209

  
210
  my ( $price, $price_src_str ) = $self->get_price_n_pricesource($self->shop_part->active_price_source);
211

  
212
  #TODO Price must be formatted. $price_src_str must be translated
114 213
  flash('info', $is_new ? t8('The shop part has been created.') : t8('The shop part has been saved.'));
115 214
  # $self->js->val('#partnumber', 'ladida');
116 215
  $self->js->html('#shop_part_description_' . $self->shop_part->id, $self->shop_part->shop_description)
117 216
           ->html('#shop_part_active_' . $self->shop_part->id, $self->shop_part->active)
217
           ->html('#price_' . $self->shop_part->id, $price)
218
           ->html('#active_price_source_' . $self->shop_part->id, $price_src_str)
118 219
           ->run('kivi.shop_part.close_dialog')
119 220
           ->flash('info', t8("Updated shop part"))
120 221
           ->render;
......
183 284
  $::request->{layout}->add_javascripts(qw(kivi.shop_part.js));
184 285
}
185 286

  
287
sub load_pricesources {
288
  my ($self) = @_;
289

  
290
  # the price sources to use for the article: sellprice, lastcost,
291
  # listprice, or one of the pricegroups. It overwrites the default pricesource from the shopconfig.
292
  # TODO: implement valid pricerules for the article
293
  my $pricesources;
294
  push( @{ $pricesources } , { id => "master_data/sellprice", name => t8("Master Data")." - ".t8("Sellprice") },
295
                             { id => "master_data/listprice", name => t8("Master Data")." - ".t8("Listprice") },
296
                             { id => "master_data/lastcost",  name => t8("Master Data")." - ".t8("Lastcost") }
297
                             );
298
  my $pricegroups = SL::DB::Manager::Pricegroup->get_all;
299
  foreach my $pg ( @$pricegroups ) {
300
    push( @{ $pricesources } , { id => "pricegroup/".$pg->id, name => t8("Pricegroup") . " - " . $pg->pricegroup} );
301
  };
302

  
303
  $self->price_sources( $pricesources );
304
}
305

  
306
sub get_price_n_pricesource {
307
  my ($self,$pricesource) = @_;
308

  
309
  my ( $price_src_str, $price_src_id ) = split(/\//,$pricesource);
310

  
311
  require SL::DB::Pricegroup;
312
  require SL::DB::Part;
313
  #TODO Price must be formatted. Translations for $price_grp_str
314
  my $price;
315
  if ($price_src_str eq "master_data") {
316
    my $part = SL::DB::Manager::Part->get_all( where => [id => $self->shop_part->part_id], with_objects => ['prices'],limit => 1)->[0];
317
    $price = $part->$price_src_id;
318
    $price_src_str = $price_src_id;
319
  }else{
320
    my $part = SL::DB::Manager::Part->get_all( where => [id => $self->shop_part->part_id, 'prices.'.pricegroup_id => $price_src_id], with_objects => ['prices'],limit => 1)->[0];
321
    my $pricegrp = SL::DB::Manager::Pricegroup->find_by( id => $price_src_id )->pricegroup;
322
    $price =  $part->prices->[0]->price;
323
    $price_src_str = $pricegrp;
324
  }
325
  return($price,$price_src_str);
326
}
327

  
186 328
sub check_auth {
187 329
  return 1; # TODO: implement shop rights
188 330
  # $::auth->assert('shop');

Auch abrufbar als: Unified diff