epic-s6ts
[kivitendo-erp.git] / SL / ShopConnector / Base.pm
1 package SL::ShopConnector::Base;
2
3 use strict;
4
5 use parent qw(SL::DB::Object);
6 use Rose::Object::MakeMethods::Generic (
7   scalar => [ qw(config) ],
8 );
9
10 sub get_one_order  {
11   die 'get_one_order needs to be implemented';
12
13   my ($self, $ordnumber) = @_;
14   my %fetched_order;
15
16   # 1. fetch the order and import it as a kivi order
17   # 2. update the order state for report
18   # 3. return a hash with either success or error state
19   my $one_order; # REST call
20
21   my $error = $self->import_data_to_shop_order($one_order);
22
23   $self->set_orderstatus($one_order->{id}, "fetched") unless $error;
24
25   return \(
26       shop_id          => $self->config->id,
27       shop_description => $self->config->description,
28       number_of_orders => $error ? 0 : 1,
29       message          => $error ? "Error: $error->{msg}"  : '',
30       error            => $error ? 1 : 0,
31     );
32 }
33
34
35 sub get_new_orders { die 'get_order needs to be implemented' }
36
37 sub update_part    {
38   die 'update_part needs to be implemented';
39
40   my ($self, $shop_part, $todo) = @_;
41   #shop_part is passed as a param
42   die "Need a valid Shop Part for updating Part" unless ref($shop_part) eq 'SL::DB::ShopPart';
43   die "Invalid todo for updating Part"           unless $todo =~ m/(price|stock|price_stock|active|all)/;
44
45   my $part = SL::DB::Part->new(id => $shop_part->part_id)->load;
46   die "Shop Part but no kivi Part?" unless ref $part eq 'SL::DB::Part';
47
48   my $success;
49
50   return $success ? 1 : 0;
51 }
52
53 sub get_article    { die 'get_article needs to be implemented' }
54
55 sub get_categories { die 'get_categories needs to be implemented' }
56
57 sub get_version    {
58
59   die 'get_version needs to be implemented';
60   # has to return a hashref with this structure:
61   # version has to return the connection error message
62   my $connect = {};
63   $connect->{success}         = 0 || 1;
64   $connect->{data}->{version} = '1234';
65   return $connect;
66 }
67
68 sub set_orderstatus { die 'set_orderstatus needs to be implemented' }
69
70 1;
71
72 __END__
73
74 =encoding utf-8
75
76 =head1 NAME
77
78   SL::ShopConnectorBase - this is the base class for shop connectors
79
80 =head1 SYNOPSIS
81
82
83 =head1 DESCRIPTION
84
85 =head1 AVAILABLE METHODS
86
87 =over 4
88
89 =item C<get_one_order $ordnumber>
90
91 Needs a order number and fetch (one or more) orders
92 which are returned by the Shop system. The function
93 has to take care of getting the order including customer
94 and item information to kivi.
95 It has to return a hash with either the number of succesful
96 imported order or within the same hash structure a error message.
97
98
99
100 =item C<get_new_orders>
101
102 =item C<update_part $shop_part $todo>
103
104 Updates one Part including all metadata and Images in a Shop.
105 Needs a valid 'SL::DB::ShopPart' as first parameter and a requested action
106 as second parameter. Valid values for the second parameter are
107 "price, stock, price_stock, active, all".
108 The method updates either all metadata or a subset.
109 Name and action for the subsets:
110
111  price       => updates only the price
112  stock       => updates only the available stock (qty)
113  price_stock => combines both predecessors
114  active      => updates only the state of the shop part
115
116 Images should always be updated, regardless of the requested action.
117 Returns 1 if all updates were executed successful.
118
119
120
121 =item C<get_article>
122
123 =item C<get_categories>
124
125 =item C<get_version>
126
127 IMPORTANT: This call is used to test the connection and if succesful
128 it returns the version number of the shop. If not succesful the
129 returning function has to make sure a error string is returned in
130 the same data structure. Details of the returning hashref:
131
132  my $connect = {};
133  $connect->{success}         = 0 || 1;
134  $connect->{data}->{version} = '1234';
135  return $connect;
136
137 =item C<set_orderstatus>
138
139 Sets the state of the order in the Shop.
140 Valid values depend on the Shop API, common states
141 are delivered, fetched, paid, in progress ...
142
143
144 =back
145
146 =head1 SEE ALSO
147
148 L<SL::ShopConnector::ALL>
149
150 =head1 BUGS
151
152 None yet. :)
153
154 =head1 AUTHOR
155
156 G. Richardson <lt>information@kivitendo-premium.deE<gt>
157 W. Hahn E<lt>wh@futureworldsearch.netE<gt>
158
159 =cut