Shop: Base Class get_one_order etwas ausführlicher dokumentiert
[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    { die 'update_part needs to be implemented' }
38
39 sub get_article    { die 'get_article needs to be implemented' }
40
41 sub get_categories { die 'get_categories needs to be implemented' }
42
43 sub get_version    {
44
45   die 'get_version needs to be implemented';
46   # has to return a hashref with this structure:
47   # version has to return the connection error message
48   my $connect = {};
49   $connect->{success}         = 0 || 1;
50   $connect->{data}->{version} = '1234';
51   return $connect;
52 }
53
54 sub set_orderstatus { die 'set_orderstatus needs to be implemented' }
55
56 1;
57
58 __END__
59
60 =encoding utf-8
61
62 =head1 NAME
63
64   SL::ShopConnectorBase - this is the base class for shop connectors
65
66 =head1 SYNOPSIS
67
68
69 =head1 DESCRIPTION
70
71 =head1 AVAILABLE METHODS
72
73 =over 4
74
75 =item C<get_one_order $ordnumber>
76
77 Needs a order number and fetch (one or more) orders
78 which are returned by the Shop system. The function
79 has to take care of getting the order including customer
80 and item information to kivi.
81 It has to return a hash with either the number of succesful
82 imported order or within the same hash structure a error message.
83
84
85
86 =item C<get_new_orders>
87
88 =item C<update_part>
89
90 =item C<get_article>
91
92 =item C<get_categories>
93
94 =item C<get_version>
95
96 IMPORTANT: This call is used to test the connection and if succesful
97 it returns the version number of the shop. If not succesful the
98 returning function has to make sure a error string is returned in
99 the same data structure. Details of the returning hashref:
100
101  my $connect = {};
102  $connect->{success}         = 0 || 1;
103  $connect->{data}->{version} = '1234';
104  return $connect;
105
106 =item C<set_orderstatus>
107
108 Sets the state of the order in the Shop.
109 Valid values are dependant on the Shop API, common states
110 are delivered, fetched, paid, in progress ...
111
112
113 =back
114
115 =head1 SEE ALSO
116
117 L<SL::ShopConnector::ALL>
118
119 =head1 BUGS
120
121 None yet. :)
122
123 =head1 AUTHOR
124
125 G. Richardson <lt>information@kivitendo-premium.deE<gt>
126 W. Hahn E<lt>wh@futureworldsearch.netE<gt>
127
128 =cut