Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

[mv] Adding items to cart basket via Perl+LWP?



******    message to minivend-users from "William Martin" <w.martin@angelfire.com>     ******

Adding items to cart basket via Perl+LWP?

Interchange: 4.6.0, Perl: 5.005.03, Redhat: 6.1

Hi,
I am looking for a way to add items to a cart via a Perl script (as we use Macromedia's Flash as a front end). As a test I cut the link for "Add to cart" from the source of a Interchange page on a session I was using and pasted it directly into the browser window. This worked fine and added the item to the cart. 

[snip]
http://mydomain.shop.com/cgi-bin/shoptest/ord/basket?mv_session_id=SuXRv7dw&mv_action=refresh&mv_order_item=os28108
[/snip]
- Adds the item with the code os28108 to the cart with that session_id.

Since that worked I assumed that I could probably do something very similar with LWP, but have not got it to work as somehow the session_id does not get picked up by Interchange in the way I expected. What gets returned is a page with the message "You must have cookies set to leave the basket. Check out now or forever lose your shopping cart." (Cookies are currently disabled in the browser but using URL munging it 'should' work?) and a page with a cart containing only the item I just added. The cart returned has a different session_id from the one I submitted. I double-checked and the session_id I used was still valid and the original items were still in the cart.. 

[Code sample 1:]
use LWP::Simple;
my $content = get "http://mydomain.shop.com/cgi-bin/shoptest/ord/basket?mv_session_id=SuXRv7dw&mv_action=refresh&mv_order_item=os28108";;
if (defined ($content)){
	print $content;
}else{
print "Nothing returned\n";
}
[/ Code]

I also tried using POST with similar results (i.e. new basket created instead of adding item to existing basket):

[Code sample2:]
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = POST 'http://mydomain.shop.com/cgi-bin/construct/ord/basket',
                [ mv_session_id => 'Yg7TAA8i', mv_order_item => 'os28108'];
print $ua->request($req)->as_string;
[/Code]

I would greatly appreciate it if someone could provide an example or advice toward a working script that adds an item/s to a carts basket  (assume we know the session_id).

Background:
The shop is part of a site that is completely front-ended by Flash. Users earn points as they use the site that they can then spend in the shop. As part of the security system all input from the front-end goes to a perl script which then passes the user requests to the appropriate part of the system (mail, chat, shop etc). In the Shop script we can pick up the mv_session_id when the shop index page is first accessed. The difficulty arises in adding things to the cart as outlined above.


Angelfire for your free web-based e-mail. http://www.angelfire.com
-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: