Add to Cart, with Multiple Variants - how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Code: Select all

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="custom" value="575757575">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="youremail@mail.com">
<input type="hidden" name="currency_code" value="US">

<input type="hidden" name="item_name_1" value="beach ball">
<input type="hidden" name="amount_1" value="15">

<input type="hidden" name="item_name_2" value="towel">
<input type="hidden" name="amount_2" value="20">

<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
It then stores that 575757575 in the Cart DB Table by each item under cart_id. And when ti comes back, it assigns that Cart ID as paid.
And I guess when they despatch it, it will mark is as depsatched. Or a despatched field.

In your opinion, is this a better way of doing it, than important something like X-Cart?

Is a listener very important? I guess it's whether or not one feels these items values will be "messed with" by someone who knows what they are doing.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

Doesn't matter if the values are messed with. They're your products. You know what the prices are. If what you get back from PayPal doesn't match, if the prices are off, don't process the order.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

And just refund with a note saying something or other. Cool.
So what about Sage... any ideas?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

How do I post this kind of XML through a <form>? This is the kind aof thing Sage would need posted through.

Code: Select all

<basket><agentId>johnsmith</agentId>-<item><description>DVD 1</description><productSku>TIMESKU</productSku><productCode>1234567</productCode><quantity>2</quantity><unitNetAmount>24.50</unitNetAmount><unitTaxAmount>00.50</unitTaxAmount><unitGrossAmount>25.00</unitGrossAmount><totalGrossAmount>50.00</totalGrossAmount><recipientFName>firstname</recipientFName><recipientLName>lastname</recipientLName><recipientMName>M</recipientMName><recipientSal>MR</recipientSal><recipientEmail>firstname.lastname@test.com</recipientEmail><recipientPhone>1234567890</recipientPhone><recipientAdd1>add1</recipientAdd1><recipientAdd2>add2</recipientAdd2><recipientCity>city</recipientCity><recipientState>CA</recipientState><recipientCountry>GB</recipientCountry><recipientPostCode>ha412t</recipientPostCode><itemShipNo>1123</itemShipNo><itemGiftMsg>Happy Birthday</itemGiftMsg></item><item><description>DVD 2</description><productSku>TIMESKU</productSku><productCode>1234567</productCode><quantity>1</quantity><unitNetAmount>24.99</unitNetAmount>
<unitTaxAmount>00.99</unitTaxAmount><unitGrossAmount>25.98</unitGrossAmount><totalGrossAmount>25.98</totalGrossAmount><recipientFName>firstname</recipientFName><recipientLName>lastname</recipientLName><recipientMName>M</recipientMName><recipientSal>MR</recipientSal><recipientEmail>firstname.lastname@test.com</recipientEmail><recipientPhone>1234567890</recipientPhone><recipientAdd1>add1</recipientAdd1><recipientAdd2>add2</recipientAdd2><recipientCity>city</recipientCity><recipientState>CA</recipientState><recipientCountry>GB</recipientCountry><recipientPostCode>ha412t</recipientPostCode><itemShipNo>1123</itemShipNo><itemGiftMsg>Congrats</itemGiftMsg></item><deliveryNetAmount>4.02</deliveryNetAmount><deliveryTaxAmount>20.00</deliveryTaxAmount><deliveryGrossAmount>24.02</deliveryGrossAmount><shipId>SHIP00002</shipId><shippingMethod>N</shippingMethod><shippingFaxNo>1234567890</shippingFaxNo></basket>
EDIT: Am trying this solution but I cannot see how you POST in a form, that firings of data in the header to the Sage page URL.
http://www.codediesel.com/php/posting-xml-from-php/
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

In all likelihood, you don't. Why do you think this needs to be done via a form?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Honestly... no idea. I've never ever done this with XML before.
I dont' know what has to go where.
I've only ever done it in normal form fields.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

You haven't really mentioned what any of this is for. I'm going to guess you're trying to capture form data from a user and then relay that to Sage in the XML format they require. Nothing says that needs to be a single step. Why not submit the form to somewhere on your own site, process the form as needed, build up your XML, and then use Guzzle to send it to Sage?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

This would be a cart. so a cart page shows everything in the cart. If they opt for PayPal, it would sho wa PayPal buy now type button. If they opt for Sage, it would show a Sage buy now button which would "somehow" post the XML to Sage. It's that last bit I am trying to understand.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

See my previous post, then. Post the form to a processing function, then send it out from there.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

I had a little at Guzzle, and I cannot make head nor tail of it.
I guess I need to learn it. to say "post the form to a processing function then send it out from there", means nothing to be at this stage, sadly!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

Instead of pointing your form's action to Sage, point it somewhere on your own site. Perform whatever processing you need to do there -- extract values, create XML, etc -- and then use Guzzle (or cURL, if you prefer) to send a POST request to Sage's endpoint.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Does this happen via Ajax? Or does the external file then direct the user to Sage?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

Couldn't tell you. I have never used (or even heard of) Sage. Given that they're expecting XML, I'd assume you'd already have collected user information but that leaves you handling credit cards. Best to consult their documentation.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Add to Cart, with Multiple Variants - how?

Post by Christopher »

simonmlewis wrote:Does this happen via Ajax? Or does the external file then direct the user to Sage?
It wouldn't happen via Ajax. When the page makes a request to your server (via link, form submit or Ajax) that script uses Guzzle/cURL to make a request to the Sage server with XML it generates. Guzzle/cURL returns the response from Sage to the script which inspects the result and generates a page for the user as appropriate.
(#10850)
Post Reply