Amazon-MWS

 view release on metacpan or  search on metacpan

lib/Amazon/MWS/XML/Product.pm  view on Meta::CPAN

This accessor is read-write because L<Amazon::MWS::Uploader> may want
to throttle the inventory. Other code is discouraged to use this as a
modifier.

=item ship_in_days

The number of days between the order date and the ship date (a whole
number between 1 and 30). If not specified the info will not be set
and Amazon will use a default of 2 business days, so we use the
default of 2 here.

=item price

The standard price of the item. If the price is zero, it is assumed to
be a product which should be set as inactive without removing it,
flipping the inventory to zero and refraining to do pass
images/variants/price feeds.

The price is rounded via sprintf '%.2f' by the module.

=item currency

Valid values are: AUD BRL CAD CNY DEFAULT EUR GBP INR JPY MXN USD.

Defaults to EUR.

=item sale_price

A sale price (optional)

=item sale_start

A DateTime object with the sale start date

=item sale_end

A DateTime object with the sale end date

=item images

An (optional) arrayref of image urls. The first will become the main
image, the other one will become the PT1, etc.

Please note that B<only http:// links> are allowed. If you pass https://
links, they will be rejected by Amazon.

=item children

An (optional) arraryref of children sku.

=item search_terms

An (optional) arrayref of search terms (max 5)

=item features

An (optional) arrayref of strings with features (max 5)

=item condition

Possible values which validates correctly: Club CollectibleAcceptable
CollectibleGood CollectibleLikeNew CollectibleVeryGood New Refurbished
UsedAcceptable UsedGood UsedLikeNew UsedVeryGood

Defaults to C<New>

=item condition_note

An arbitrary string shorter than 2000 characters with comments about
the condition.

=item manufacturer

Maker of the product (max 50 chars)

=item manufacturer_part_number

Part number manufacturer.

=back

=cut

has sku => (is => 'ro', required => 1);

has feeds_needed => (is => 'rw', isa => ArrayRef,
                     default => sub { [qw/product inventory price image variants/] });

sub is_feed_needed {
    my ($self, $feed) = @_;
    return unless $feed;
    return scalar(grep { $_ eq $feed } @{ $self->feeds_needed });
}

has timestamp_string => (is => 'ro',
                         default => sub { '0' });
has ean => (is => 'ro',
           isa => sub { _check_length($_[0], 8, 16) });

has asin => (is => 'ro');

has title => (is => 'ro',
              isa => sub { _check_length($_[0], 1, 500) },
             );
has description => (is => 'ro',
                    isa => sub { _check_length($_[0], 0, 2000) },
                   );
has brand => (is => 'ro',
              isa => sub { _check_length($_[0], 0, 50) },
             );
has condition => (is => 'ro',
                  default => sub { 'New' },
                  isa => sub {
                      my %condition_map = (
                                           Club                   => 1,
                                           CollectibleAcceptable  => 1,
                                           CollectibleGood        => 1,
                                           CollectibleLikeNew     => 1,
                                           CollectibleVeryGood    => 1,
                                           New                    => 1,
                                           Refurbished            => 1,

lib/Amazon/MWS/XML/Product.pm  view on Meta::CPAN

    my $unit = $_[0];
    my %units = (
                 GR => 1,
                 KG => 1,
                 LB => 1,
                 MG => 1,
                 OZ => 1,
                );
    die "Wrong unit. Possible are :"
      . join(" ", keys %units) unless $units{$unit};
}

=over 4

=item package_weight

Weight of the package.

=item package_weight_unit

Unit for the package weight. Possible values are C<GR>, C<KG>, C<LB>,
C<MG>, C<OZ>. Defaults to C<GR>.

=item shipping_weight

Weight of the product when packaged to ship.

=item shipping_weight_unit

Unit for the package weight for shipping. Possible values are C<GR>,
C<KG>, C<LB>, C<MG>, C<OZ>. Defaults to C<GR>.

=back

=cut

has package_weight => (is => 'ro');

has package_weight_unit => (is => 'ro',
                            default => sub { 'GR' },
                            isa => \&_check_units,
                           );

has shipping_weight => (is => 'ro');

has shipping_weight_unit => (is => 'ro',
                             default => sub { 'GR' },
                             isa => \&_check_units,
                            );

has inventory => (is => 'rw',
                  default => sub { '0' },
                  isa => Int);

has ship_in_days => (is => 'ro',
                     isa => Int,
                     default => sub { '2' });

has price => (is => 'ro',
              required => 1,
              isa => \&_validate_price);

sub _validate_price {
    my ($price) = @_;
    die "$price is not a number" unless is_Num($price);
    die "$price is negative" if $price < 0;
}


has sale_price => (is => 'ro',
                   isa => \&_validate_price);

has sale_start => (is => 'ro',
                   isa => sub {
                       die "Not a datetime"
                         unless $_[0]->isa('DateTime');
                   });

has sale_end => (is => 'ro',
                   isa => sub {
                       die "Not a datetime"
                         unless $_[0]->isa('DateTime');
                   });

has currency => (is => 'ro',
                 isa => sub {
                     my %currency = map { $_ => 1 } (qw/AUD BRL CAD CNY DEFAULT
                                                        EUR GBP INR JPY MXN USD/);
                     die "Not a valid currency" unless $currency{$_[0]};
                 },
                 default => sub { 'EUR' });

has images => (is => 'ro',
               isa => sub {
                   die "Not an arrayref" unless is_ArrayRef($_[0]);
                   foreach my $url (@{ $_[0] }) {
                       my $check = URI->new($url)->as_string;
                       die "Non-URI character in url $url (should be $check)"
                         if $check ne $url;
                   }
               });
               
has children => (is => 'rw',
                 isa => ArrayRef);


# has restock_date => (is => 'ro');


=head1 METHODS

=head2 price_is_zero

Return true if the price is 0.

=cut

sub price_is_zero {
    my $self = shift;
    my $price = $self->price;
    if ($price > 0) {
        return 0;
    }
    else {
        return 1;
    }
}

=head2 is_inactive

Return true if price is 0 or inventory is 0. Inactive items will not



( run in 0.543 second using v1.01-cache-2.11-cpan-140bd7fdf52 )