epic-s6ts
[kivitendo-erp.git] / SL / Shop.pm
1 package SL::Shop;
2
3 use strict;
4
5 use parent qw(Rose::Object);
6 use SL::ShopConnector::ALL;
7 use SL::DB::Part;
8
9 use Rose::Object::MakeMethods::Generic (
10   'scalar'                => [ qw(config) ],
11   'scalar --get_set_init' => [ qw(connector) ],
12 );
13
14 sub updatable_parts {
15   my ($self, $last_update) = @_;
16   $last_update ||= DateTime->now(); # need exact timestamp, with minutes
17
18   my $parts;
19   my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
20   foreach my $shop ( @{ $active_shops } ) {
21     # maybe run as an iterator? does that make sense with with_objects?
22     my $update_parts = SL::DB::Manager::ShopPart->get_all(query => [
23              and => [
24                 'active' => 1,
25                 'shop_id' => $shop->id,
26                 # shop => '1',
27                 or => [ 'part.mtime' => { ge => $last_update },
28                         'part.itime' => { ge => $last_update },
29                         'itime'      => { ge => $last_update },
30                         'mtime'      => { ge => $last_update },
31                       ],
32                     ]
33              ],
34              with_objects => ['shop', 'part'],
35              # multi_many_ok   => 1,
36           );
37     push( @{ $parts }, @{ $update_parts });
38   };
39   return $parts;
40
41 };
42
43 sub check_connectivity {
44   my ($self) = @_;
45   my $version = $self->connector->get_version;
46   return $version;
47 }
48
49 sub init_connector {
50   my ($self) = @_;
51   # determine the connector from the connector type in the webshop config
52   return SL::ShopConnector::ALL->shop_connector_class_by_name($self->config->connector)->new( config => $self->config);
53
54 };
55
56 1;
57
58 __END__
59
60 =encoding utf8
61
62 =head1 NAME
63
64 SL::Shop - Do stuff with WebShop instances
65
66 =head1 SYNOPSIS
67
68 my $config = SL::DB::Manager::Shop->get_first();
69 my $shop = SL::Shop->new( config => $config );
70
71 From the config we know which Connector class to load, save in $shop->connector
72 and do stuff from there:
73
74 $shop->connector->get_new_orders;
75
76 =head1 FUNCTIONS
77
78 =over 4
79
80 =item C<updatable_parts>
81
82 =item C<check_connectivity>
83
84 =item C<init_connector>
85
86 =back
87
88 =head1 BUGS
89
90 Nothing here yet.
91
92 =head1 AUTHOR
93
94 G. Richardson <lt>information@kivitendo-premium.deE<gt>
95
96 =cut