1 package SL::ShopConnector::Base;
 
   5 use parent qw(SL::DB::Object);
 
   6 use Rose::Object::MakeMethods::Generic (
 
   7   scalar => [ qw(config) ],
 
  11   die 'get_one_order needs to be implemented';
 
  13   my ($self, $ordnumber) = @_;
 
  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
 
  21   my $error = $self->import_data_to_shop_order($one_order);
 
  23   $self->set_orderstatus($one_order->{id}, "fetched") unless $error;
 
  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,
 
  35 sub get_new_orders { die 'get_order needs to be implemented' }
 
  38   die 'update_part needs to be implemented';
 
  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)/;
 
  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';
 
  50   return $success ? 1 : 0;
 
  53 sub get_article    { die 'get_article needs to be implemented' }
 
  55 sub get_categories { die 'get_categories needs to be implemented' }
 
  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
 
  63   $connect->{success}         = 0 || 1;
 
  64   $connect->{data}->{version} = '1234';
 
  68 sub set_orderstatus { die 'set_orderstatus needs to be implemented' }
 
  78   SL::ShopConnectorBase - this is the base class for shop connectors
 
  85 =head1 AVAILABLE METHODS
 
  89 =item C<get_one_order $ordnumber>
 
  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.
 
 100 =item C<get_new_orders>
 
 102 =item C<update_part $shop_part $todo>
 
 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:
 
 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
 
 116 Images should always be updated, regardless of the requested action.
 
 117 Returns 1 if all updates were executed successful.
 
 123 =item C<get_categories>
 
 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:
 
 133  $connect->{success}         = 0 || 1;
 
 134  $connect->{data}->{version} = '1234';
 
 137 =item C<set_orderstatus>
 
 139 Sets the state of the order in the Shop.
 
 140 Valid values are dependant on the Shop API, common states
 
 141 are delivered, fetched, paid, in progress ...
 
 148 L<SL::ShopConnector::ALL>
 
 156 G. Richardson <lt>information@kivitendo-premium.deE<gt>
 
 157 W. Hahn E<lt>wh@futureworldsearch.netE<gt>