Recently, I’ve been working on a new site for a client that required the wp-ecommerce plugin for wordpress. From the install, everything looked fine. As some of you may know, I’ve dumped apache web server for nginx. I quickly run into a problem with wp-ecommerce’s add to cart function. It seem to hang when you click add to cart. So I used my handy dandy firebug add-on to debug the issue… and come to find out… there is an issue with the ajax post. Apprently, the jquery post function used by wp-ecommerce seems to reach a 404 when adding to cart. This is because the way I done my rewrite rules for my wordpress sites. But don’t worry… there is a fix. After some research and messing around with this… This is how you get around it:
Open /wp-content/plugins/wp-e-commerce/js/wp-e-commerce.js (line 118):
Find and Comment out:
jQuery.post( ‘index.php?ajax=true’, form_values, function(returned_data) {
to
//jQuery.post( ‘index.php?ajax=true’, form_values, function(returned_data) {
Then add the follow below or above it (it doesnt matter):
jQuery.post( ‘?ajax=true’, form_values, function(returned_data) {
Now, wp-ecommerce’s add to cart button will work as it should.
Another alternative to making the add to cart function work and keep the index.php filename in the jquery post function is to add a beginning slash to index.php and that should make it work with both nginx and apache. So it would be something like this:
jQuery.post( ‘/index.php?ajax=true’, form_values, function(returned_data) {
Big thanks to cs for the add to cart stuff.
I also ran into other bugs that used the jquery post function. So your best bet is to find and replace the index.php references (inside of jquery post) and use /index.php instead.
For instance, the shopping cart ajax request for the shopping cart. If it keeps saying “Loading…”, You can simply fix that by chaning line 201 by changing:
jQuery.post( ‘index.php?wpsc_ajax_action=get_cart’, form_values, function(returned_data) {
to
jQuery.post( ‘/index.php?wpsc_ajax_action=get_cart’, form_values, function(returned_data) {
0 Comments