kivitendo/SL/Shop.pm @ 7e2e8c30
a9ffbf8c | Geoffrey Richardson | package SL::Shop;
|
||
use strict;
|
||||
use parent qw(Rose::Object);
|
||||
be4b49e5 | Werner Hahn | use SL::ShopConnector::ALL;
|
||
use SL::DB::Part;
|
||||
a9ffbf8c | Geoffrey Richardson | |||
# __PACKAGE__->run_before('check_auth');
|
||||
use Rose::Object::MakeMethods::Generic (
|
||||
'scalar' => [ qw(config) ],
|
||||
'scalar --get_set_init' => [ qw(connector) ],
|
||||
);
|
||||
be4b49e5 | Werner Hahn | sub updatable_parts {
|
||
my ($self, $last_update) = @_;
|
||||
$last_update ||= DateTime->now(); # need exact timestamp, with minutes
|
||||
my $parts;
|
||||
my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
|
||||
foreach my $shop ( @{ $active_shops } ) {
|
||||
# maybe run as an iterator? does that make sense with with_objects?
|
||||
my $update_parts = SL::DB::Manager::ShopPart->get_all(query => [
|
||||
and => [
|
||||
'active' => 1,
|
||||
'shop_id' => $shop->id,
|
||||
# shop => '1',
|
||||
or => [ 'part.mtime' => { ge => $last_update },
|
||||
'part.itime' => { ge => $last_update },
|
||||
'itime' => { ge => $last_update },
|
||||
'mtime' => { ge => $last_update },
|
||||
],
|
||||
]
|
||||
],
|
||||
with_objects => ['shop', 'part'],
|
||||
# multi_many_ok => 1,
|
||||
);
|
||||
push( @{ $parts }, @{ $update_parts });
|
||||
};
|
||||
return $parts;
|
||||
};
|
||||
a9ffbf8c | Geoffrey Richardson | sub init_connector {
|
||
my ($self) = @_;
|
||||
# determine the connector from the connector type in the webshop config
|
||||
be4b49e5 | Werner Hahn | return SL::ShopConnector::ALL->shop_connector_class_by_name($self->config->connector)->new( config => $self->config);
|
||
a9ffbf8c | Geoffrey Richardson | |||
};
|
||||
1;
|
||||
__END__
|
||||
=encoding utf8
|
||||
=head1 NAME
|
||||
be4b49e5 | Werner Hahn | SL::Shop - Do stuff with WebShop instances
|
||
a9ffbf8c | Geoffrey Richardson | |||
=head1 SYNOPSIS
|
||||
be4b49e5 | Werner Hahn | my $config = SL::DB::Manager::Shop->get_first();
|
||
a9ffbf8c | Geoffrey Richardson | my $shop = SL::WebShop->new( config => $config );
|
||
be4b49e5 | Werner Hahn | From the config we know which Connector class to load, save in $shop->connector
|
||
and do stuff from there:
|
||||
a9ffbf8c | Geoffrey Richardson | |||
$shop->connector->get_new_orders;
|
||||
=head1 FUNCTIONS
|
||||
=head1 BUGS
|
||||
be4b49e5 | Werner Hahn | Nothing here yet.
|
||
a9ffbf8c | Geoffrey Richardson | |||
=head1 AUTHOR
|
||||
be4b49e5 | Werner Hahn | G. Richardson <lt>information@kivitendo-premium.deE<gt>
|
||
a9ffbf8c | Geoffrey Richardson | |||
=cut
|