Jump to content
Dave Coder

Form CGI POST 'Buy Now' Button in Product Description

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.

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

I am not able to assist as I believe the link provided is not a CubeCart page.

If you can provide a web address of a CubeCart store exhibiting the problem, we may have some advice.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Thanks B, I don' need inventory control. Just a simple input directly to my bolt-on shopping cart without AJAX handling it would be great.  I can't find where to rewrite the skin code to not POST to Cubecart.  Any help would be greatly appreciated.

Share this post


Link to post
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.

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

My bad. Must have been a long night.

Let's look in content.product.php.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Quickie.  May need to start a new post.  I will be disabling the 'Login / Register' links across the site.  Is there an easy way to do this? 

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Is there any way to disable the responsive main menu?  It's not necessary for my store (no login).  I've hidden all links to the login on desktop site, but for phones the responsive menu kicks in. Thanks!

Share this post


Link to post
Share on other sites

The side menu on mobile that slides out from the left. Menu items are 'Your Account > Login / Register' and 'Change Currency'.  I just need to disable that menu (or modify the links).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×