-sub action_get_shop_parts {
- my ( $self ) = @_;
- $main::lxdebug->dump(0, "TST: ShopPart get_shop_parts form", $::form);
- my $parts_fetched;
- my $new_parts;
-
- my $type = $::form->{type};
- if ( $type eq "get_one" ) {
- my $shop_id = $::form->{shop_id};
- my $part_number = $::form->{part_number};
-
- if ( $shop_id && $part_number ) {
- my $shop_config = SL::DB::Manager::Shop->get_first(query => [ id => $shop_id, obsolete => 0 ]);
- my $shop = SL::Shop->new( config => $shop_config );
- unless ( SL::DB::Manager::Part->get_all_count( query => [ partnumber => $part_number ] )) {
- $new_parts = $shop->connector->get_shop_parts($part_number);
- push @{ $parts_fetched }, $new_parts ;
- } else {
- flash_later('error', t8('From shop "#1" : Number: #2 #3 ', $shop->config->description, $part_number, t8('Partnumber is already exist')));
- }
- } else {
- flash_later('error', t8('Shop or partnumber not selected.'));
- }
- } elsif ( $type eq "get_new" ) {
- my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
- foreach my $shop_config ( @{ $active_shops } ) {
- my $shop = SL::Shop->new( config => $shop_config );
-
- $new_parts = $shop->connector->get_shop_parts;
- push @{ $parts_fetched }, $new_parts ;
- }
- }
-
- foreach my $shop_fetched(@{ $parts_fetched }) {
- if($shop_fetched->{error}){
- flash_later('error', t8('From shop "#1" : #2 ', $shop_fetched->{shop_description}, $shop_fetched->{message},));
- }else{
- flash_later('info', t8('From shop #1 : #2 parts have been imported.', $shop_fetched->{description}, $shop_fetched->{number_of_parts},));
- }
- }
-
- $self->redirect_to(controller => "ShopPart", action => 'list_articles');
-}
-