4

I'm building a VERY simple store setup to demonstrate its capabilities to a client. I setup a quick and dirty EE site, added Structure, Wygwam and Store. EE and all the add-ons are current versions. I then created my field types, my product channel, and linked the two. I added a store home page in Structure and told it to use the store_example/index template. I added a single product then went to the site. So far so good. I went to the product page, clicked on add to cart and nothing appears in the sidebar cart after the page reloaded. Is there some step I've missed or a reason why my add to cart button wouldn't work?Remember, these are the default templates that are installed with Store, I haven't changed anything other then that main navigation on top. and linked to a common bootstrap.css file.

UPDATE: I'm not sure how relevant this is but I started looking at other Store examples on the web and I noticed that the exp:store:product tag was outputting a form tag with an action. Mine is missing the action parameter for some strange reason.

UPDATE 2: .htaccess file contents:

# remove index.php
RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

# EE 404 page for missing pages
ErrorDocument 404 /index.php/site/404

# remove www
# RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

The removal of index.php is from the documentation for Structure and has worked for all sites I've ever built with it. The 404 was added recently due to EE not working without it. I never could figure out why. The removal of www is commented out because this is a test site.

Commenting out the removal of index.php and updating my $config['site_index'] does work but I'd like to be able to remove index.php from the URLs.

  • The form action parameter was intentionally removed, all browsers treat this as "post to currrent page". It's almost certainly an issue with your htaccess file - can you post that (or try removing it)? Also a screenshot of the chrome developer tools/firebug network tab of your form post would be useful. – Adrian Macneil Jan 23 '13 at 0:08
  • @AdrianMacneil I've added my .htaccess file and a brief explanation to an update above. – Stuart McCoy Jan 28 '13 at 13:59
3

The 404 line is almost certainly the problem. I've seen this a couple times before now.

Basically Apache is treating every page load as a 404 and sending it through to ExpressionEngine. At this point EE sees the URL and displays the page you expect. While this works well enough for most pages, it also happens to destroy any POST data, which is why no products are added to your cart. It's more of an accident that your site is working at all, and you should really try to avoid this situation.

Rule of thumb: Never use ErrorDocument 404 in an ExpressionEngine htaccess file. It does more harm than good, and masks the underlying issue.

You should always start by testing only the official htaccess method:

RewriteEngine On

# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Note you should leave out the <IfModule mod_rewrite.c> lines, because all they do is hide errors when mod_require isn't enabled (and it's much better to know about this problem than to spend hours trying to figure out why rewrite isn't working, trust me).

It doesn't look like you're using it, but for the record, always avoid NSM Htaccess Generator, it often breaks form submissions (precisely because it adds an ErrorDocument 404 line like you have used above). Also always start from the smallest htaccess possible, then add back in lines as necessary (I've seen people with htaccess files 3 pages long wondering why their site isn't working).

If the official htaccess isn't working, try changing the RewriteRule line to one of these:

  • RewriteRule ^(.*)$ index.php/$1 [L]
  • RewriteRule ^(.*)$ /index.php?/$1 [L]
  • RewriteRule ^(.*)$ index.php?/$1 [L]
  • RewriteRule . index.php [L]

If that still doesn't work, try changing the $config['uri_protocol'] setting in config.php. I find PATH_INFO or ORIG_PATH_INFO work more often than not on stubborn servers:

$config['uri_protocol'] = 'ORIG_PATH_INFO';

Finally, if none of those suggestions work, it's probably time to start talking to your web host - often they have much better knowledge of how their servers are configured (alternatively, find a host with a more standard setup).

  • I'll give this a shot but removing ErrorDocument 404 also seems to break my EE sites. I actually discovered this by taking an NSM .htaccess Generator created .htaccess file from an older site and started removing things to see why another site wasn't working. The lack of this line was the culprit. You can comment this out in the NSM .htaccess Generator extension settings, by the way. I'll research this a little more to see why my sites won't work without it. As for hosting issues, currently this is running on a local dev desktop using Apache 2.2 and PHP 5.3.15 in OSX Mountain Lion. – Stuart McCoy Jan 28 '13 at 15:15
  • Great, let me know how you get on. Like I said, the ErrorDocument fall through does work, but for the wrong reasons. You should get to the bottom of why mod_rewrite isn't working instead (because currently the ErrorDocument line is the only thing actually being used in your htaccess). – Adrian Macneil Jan 29 '13 at 5:19
  • I think I'm going to need to do a little more research into .htaccess. I got this half working. I was able to add products to the cart but when I tried to add a different product or more of an existing product nothing happened. Sometimes I could refresh a few times and the cart would update but this was hit or miss. For my purposes of a quick 5 minute demo this worked though. – Stuart McCoy Jan 31 '13 at 21:43
  • That sounds really odd. Do you have any caching on your product or cart templates? – Adrian Macneil Feb 1 '13 at 1:04
  • Adrian, I've finally started working on the store section of this new site and I'm running into the same issue as mentioned above. It appears that the checkout page isn't updating when I change the amount value. The sidebar cart on the home page displays the correct value. I'm currently using the sample templates to test the functionality before I start integrating it with the rest of the site. – Stuart McCoy May 15 '13 at 20:22
0

I experienced the same problem and it was related to the .htaccess file. That would be the place to investigate.

  • Can you elaborate on this so it could more readily help the poster? How was the problem related to your .htaccess file? What did you change to remedy it? – Derek Hogue Jan 23 '13 at 13:09
  • Yeah, I'd like to know more about what was causing the problem and how you resolved it specifically. – Stuart McCoy Jan 28 '13 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.