AMF-Perl

 view release on metacpan or  search on metacpan

doc/examples/petmarket/petmarket/api/cartservice.pm  view on Meta::CPAN

    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;
        push @row, $productid;
        push @row, $unitcost;
        push @row, "";
        push @row, $productname;
        push @row, $catid;
        push @row, "888888";
        push @result, \@row;
    }

    my @columnNames = ("ITEMOID", "ITEMQUANTITY", "ITEMID", "ITEMNAME", "QUANTITY", "PRODUCTOID", "LISTPRICE", "DESCRIPTION", "NAME", "CATEGORYOID", "COLOR");

    return AMF::Perl::Util::Object->pseudo_query(\@columnNames, \@result);
}

sub getCartTotal
{
    my ($self, $cartid) = @_;
    my ($count, $total);

    my $ary_ref = $self->dbh->selectall_arrayref("SELECT unitcost, quantity FROM cart_details a, item_details b WHERE a.itemid=b.itemid AND a.cartid='$cartid'");
    foreach my $rowRef (@$ary_ref)
    {
        my ($unitcost, $quantity) = @$rowRef;
        $total += $quantity * $unitcost;
        $count += $quantity;
    }

    my $result = new AMF::Perl::Util::Object;
    $result->{total} = $total;
    $result->{count} = $count;
    return $result;
}

sub addCartItem
{
    my ($self, $cartid, $itemid, $quantity) = @_;
    $self->dbh->do("INSERT INTO cart_details SET cartid='$cartid', itemid='$itemid', quantity=$quantity");
    my $result = $self->getCartTotal($cartid);
    $result->{"itemoid"} = $itemid;
    return $result;
}

sub updateCartItem
{
    my ($self, $cartid, $itemid, $quantity) = @_;
    $self->deleteCartItem($cartid, $itemid);
    return $self->addCartItem($cartid, $itemid, $quantity);
}

sub deleteCartItem
{
    my ($self, $cartid, $itemid) = @_;
    $self->dbh->do("DELETE FROM cart_details WHERE cartid='$cartid' AND itemid='$itemid'");
    my $result = $self->getCartTotal($cartid);
    $result->{"itemoid"} = $itemid;
    return $result;
}

1;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.220 second using v1.00-cache-2.02-grep-82fe00e-cpan-b63e86051f13 )