Click here to register.
      

Shop Talk

Design Squid
Shop Talk
hao · 6/30/2009 11:48 pm

I remember when the Internet became commercialized. There was a mix of excitement and fear. I lived on the side of fear, as others and I deplored the eventual loss of useless fun. The useless fun didn’t disappear—it evolved into monstrous beasts like Facebook and Twitter. The commercial half of the excitement has also evolved, but surprisingly, only recently has the user experience of shopping online improved dramatically and only in a few corners of the Web.

WebGUI has a Shop system. As with ecommerce support in many frameworks, WebGUI Shop gets the job done. But it is still evolving and could certainly use some updating.

One recent project had us adapting the Shop to provide a 1-click order form (instead of the usual add-to-cart-then-checkout process). Normally, the Shop front-end is basically a collection of SKU assets. Each SKU asset usually corresponds to a unique product which can be inventoried. Here, we used a SKU for the form and essentially had to bypass the Cart—which could have been easier.

There were a few tricks we had to throw in, but essentially our SKU had to call the Payment Driver directly:

    sub www_order {
        my $self        = shift;
        my $session = $self->session;

        my $driverId = $session->db->quickScalar( q{
            SELECT  paymentGatewayId
               FROM  paymentGateway
            WHERE  className = ‘WebGUI::Shop::PayDriver::OneClick’
        } );

        my $pd = WebGUI::Shop::PayDriver::OneClick->new( $session, $driverId );

        my $transaction = $pd->pay();

        if ( $transaction->isSuccessful ) {
            # Yay, order processed successfully
        }
        # Oops, try again
    }

As we used a SOAP gateway for the back-end credit authorization, one notable gotcha was in updating the transaction pricing on the fly. Here’s how we did that in the Payment Driver:

    sub processPayment {
        my $self             = shift;
        my $transaction = shift;
        my $price           = getPriceFromGateway();

        foreach my $transactionItem ( @{ $transaction->getItems } ) {
            $transactionItem->update( { 'price' => $price } );
            $amount += $price;
        }
        $transaction->update( { 'amount' => $amount } );
    }

There have been talk about updating the Shop to provide 1-click ordering like this. So in the near future, you may not need to go through the same hoops we did. Since WebGUI itself is open source, it’s easy enough to customize for individual feature requirements.

·
Stick
Lock
Subscribe