AMF-Perl
view release on metacpan or search on metacpan
doc/examples/petmarket/petmarket/api/cartservice.pm view on Meta::CPAN
"access" => "remote",
"returns" => "AMFObject"
},
"getCartTotal" => {
"description" => "Return the total number of items and total cost of the cart with the given ID",
"access" => "remote",
},
"newCart" => {
"description" => "Returns id of a new Cart object.",
"access" => "remote",
},
"addCartItem" => {
"description" => "Adds the given item to the given cart and returns the new totals",
"access" => "remote",
},
"updateCartItem" => {
"description" => "Updates the given item in the given cart and returns the new totals",
"access" => "remote",
},
"deleteCartItem" => {
"description" => "Deletes the given item from the given cart and returns the new totals",
"access" => "remote",
},
};
}
sub getStatesAndCountries
{
my ($self) = @_;
my %locations;
my @states = (
"AL", "AK", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "GU", "HI", "IA",
"ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT",
"NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "PR", "RI",
"SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY"
);
my @countries = ("USA");
$locations{"STATES_array"} = \@states;
$locations{"COUNTRIES_array"} = \@countries;
return \%locations;
}
sub getCreditCards
{
my ($self) = @_;
my @cards = ("American Express", "Discover/Novus", "MasterCard", "Visa");
return \@cards;
}
sub getShippingMethods
{
my @columns = ("shippingoid", "shippingname", "shippingdescription", "shippingprice", "shippingdays");
my @names = ("Ground", "2nd Day Air", "Next Day Air", "3 Day Select");
my @descriptions = (
"Prompt, dependable, low-cost ground delivery makes Ground an excellent choice for all your routine shipments. Ground reaches every address throughout the 48 contiguous states.",
"2nd Day Air provides guaranteed on-time delivery to every address throughout the United States (excluding intra-Alaska shipments) and Puerto Rico by the end of the second business day. This service is an economical alternative for time-sensi...
"Next Day Air features fast, reliable delivery to every address in all 50 states and Puerto Rico. We guarantee delivery by 10:30 a.m., noon, or end of day the next business day depending on destination (noon or 1:30 p.m. on Saturdays).",
"The ideal mix of economy and guaranteed on-time delivery, 3 Day Select guarantees delivery within three business days to and from every address in the 48 contiguous states."
);
my @prices = (13.00, 26.00, 39.00, 18.00);
my @days = (6, 2, 1, 3);
my @methods;
for (my $i = 0; $i < scalar @names; $i++)
{
my @row;
push @row, $i;
push @row, $names[$i];
push @row, $descriptions[$i];
push @row, $prices[$i];
push @row, $days[$i];
push @methods, \@row;
}
return AMF::Perl::Util::Object->pseudo_query(\@columns, \@methods);
}
sub validateCartOID
{
my ($self, $id) = @_;
return $id;
}
sub newCart
{
my ($self) = @_;
my ($id, $count);
do
{
$id = "cart" . time() . "." . (int(rand 1000000) + 1);
my $ary_ref = $self->dbh->selectall_arrayref("SELECT count(*) FROM cart_details WHERE cartid = '$id'");
$count = $ary_ref->[0]->[0];
}
while ($count > 0);
$self->dbh->do("INSERT INTO cart_details SET cartid='$id'");
return $id;
}
#TODO - where does the item quantity come from?
sub getCartItems
{
my ($self, $cartid) = @_;
my @result;
my $ary_ref = $self->dbh->selectall_arrayref("SELECT d.quantity, a.productid, a.itemid, unitcost, b.descn, attr1, c.name,e.catid FROM item a, item_details b, product_details c, cart_details d, product e WHERE a.itemid=b.itemid AND a.productid= c....
foreach my $rowRef (@$ary_ref)
{
my ($cartQuantity, $productid, $itemid, $unitcost, $descn, $attr, $productname, $catid) = @$rowRef;
my @row;
push @row, $itemid;
push @row, 999;
push @row, $itemid;
push @row, $attr;
push @row, $cartQuantity;
( run in 0.485 second using v1.01-cache-2.11-cpan-5b529ec07f3 )