Jump to content

Form CGI POST 'Buy Now' Button in Product Description


Dave Coder

Recommended Posts

Love Cubecart!  I am only using CubeCart as a catalog, but I'm trying to add a simple Form CGI POST script for a 'Buy Now' button in the Product Description.  This will send a very small amount of product information to my bolt-on commerce cart (Americommerce). This works great in all of my websites (including Joomla Virtuemart), but within CubeCart it does nothing when I click on the 'Buy Now' button.  I imagine this may have to do with the 'security token' sanitizer.  Is there anyway to simply make a call to my bolt-on commerce cart using CGI script?  It's always been so easy within HTML and other PHP -based websites... works like a charm on all form data.  Any help would be appreciated.

PS.The reason I use the bolt-on cart to manage my commerce is that I have many websites being hosted across many domains.  I don't want to setup a new commerce system for each website.  I use a single bolt-on commerce system across all websites to manage shipping, customer communications, etc. from Americommerce without logging into 20 different instances of a shopping cart to do the same thing.

Link to comment
Share on other sites

Welcome Dave Coder! Glad to see you made it to the forums.

CubeCart has a "catalogue" mode. As such, CubeCart presents no method to add items to a shopping cart, to show a shopping cart, or to checkout the shopping cart from the store.

However, there is still a form element that contains much of the item's displayed matter: image, price, description (but not Customer Reviews nor anything after).

If you have this mode enabled, then I conclude you have incorporated a separate form element in the product's Description.

Only when CubeCart processes a POST payload is the security token examined and changed (that may change in CubeCart 6.2).

CubeCart also attaches javascript event viewers to the form element courtesy of the jquery Validate plugin.

Regardless, nested form elements are not permitted.

We may need to work out how to remove CubeCart's form element to allow yours to function.

Link to comment
Share on other sites

Thanks for the feedback, b. Yes, I only use catalog mode so CubeCart presents no method for adding to it's own shopping cart.  I simply paste html code into the product description area. It then add to my bolt-on shopping cart (Americommerce). See my example on this page: http://labdirect.net/index.php/carbamide-peroxide-teeth-whitening-gels/carbamide-peroxide-5ml-syringe-16-8-9-detail.  The same code in CubeCart is rendered non-functional so something's going on there. Any ideas, let me know. Lovin' CubeCart!

Link to comment
Share on other sites

Ok, I see that you have simply added an <input> tag to the description, and are relying on CubeCart to process the POST.

If you do not care how CubeCart manages your inventory, then you can rewrite the skin code to not POST to CubeCart (which is as an AJAX call - likely why you see no effect as there is nothing for the AJAX result function to change).

Instead, set the action attribute to your CGI script, and then have that script send a 302 redirect back to the browser to refetch the CubeCart page.

If you run your own server, you can certainly have your PHP allow for executing scripts that do not belong to CubeCart. We can use any of several hooks to call that script.

Link to comment
Share on other sites

Let's look at the Foundation skin template main.php.

Line 14 can be changed:

From:

<form action="{$VAL_SELF}" method="post" class="add_to_basket">

To:

<form action="http://www.cartserver.com/sc/cart.cgi" method="post">

Then, in the product's description, remove the <form> and </form> tags.

I don't see an <input> that will send the {$PRODUCT.product_id}.

Then, have an <input> that sends {$VAL_SELF} so that the script can send the visitor back to this page.

 

Link to comment
Share on other sites

Thanks B,  Looked at code in main.php at skins/foundation/templates/main.php.  I guess I'm showing a different file than you describe.  No 'form' code at all there to modify.  Sorry for the hassle and thanks so much for the help.  Seems so simple, but apparently not.  If you ever run across a simple way to send form data directly in from cubecart product description, let me know.  Thanks again.

Link to comment
Share on other sites

Thanks B!  I was able to get the form working by completely removing line 14 (<form>) in content.product.php and replacing it with my form and input data. The fix is a bit 'squirrelly', but it works. The RTF editor for product description still adds a token (that is now unused) after each edit (like a blockchain database... haha).   I'll continue playing with things and update this topic as I continue tweaking. Thanks for pointing me in the right direction. CubeCart Rocks and so do you!

Link to comment
Share on other sites

The login/register HTML in the displayed page is a common box - shown on all pages*.

So, in main.php, you can make this change:

From:

{include file='templates/box.session.php'}

To:

{* include file='templates/box.session.php' *}

This keeps the code but the syntax is a comment.

* If a visitor manages to get to the Checkout page, there is a form that can be filled out which will register a customer. Also, even with no links visible, one can manually enter the web address: www.store.com/register.html. The 100% positive measure to stop visitors from registering will require some code snippets.

Link to comment
Share on other sites

Thanks B. Fast and 'right on the money' as usual.  In file, box.sessions.php, I hardlinked the Login / Registration links directly to my bolt-on shopping cart.  Hooray! Now to start populating with products and go live (in a few days).  Thanks for the help. You da man!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...