OpenCart仅SSL环境异常:购物车按钮失效及cart.tpl索引未定义报错
Hey there, let's work through this issue step by step—those PHP notices and unresponsive buttons are likely linked, so we'll tackle them together:
Resolve the "Undefined index: recurring" Notice First
The error at line 19 ofcart.tplhappens because the template is trying to access$product['recurring']without checking if that index actually exists. This is super common when products don't have a recurring subscription option enabled.- Open your theme's
catalog/view/theme/[your-theme]/template/checkout/cart.tplfile - Jump to line 19 and find the code referencing
$product['recurring'] - Wrap that section in an existence check to block the notice:
<?php if (isset($product['recurring']) && !empty($product['recurring'])) { ?> <!-- Your existing code that uses $product['recurring'] --> <?php } ?>
PHP notices can break JavaScript execution in the background, which is a huge reason your buttons aren't working—fixing this removes that roadblock.
- Open your theme's
Fix SSL-Related Form/AJAX Blocking
In SSL-only mode, browsers block mixed content (HTTP requests sent from an HTTPS page), which is almost certainly why your buttons just refresh without doing anything:- Check Form Action URLs: Make sure your cart form's
actionattribute uses a valid HTTPS URL. Incart.tpl, this should be using the$actionvariable passed from the controller (generated via OpenCart's$this->url->link()method). If you have a hardcoded HTTP URL here, replace it with<?php echo $action; ?>. - Verify Config Settings: Double-check your
config.phpandadmin/config.phpfiles:- Set
HTTPS_SERVERto your full HTTPS domain (e.g.,https://yourstore.com/) - Set
HTTPS_CATALOGto the same HTTPS domain
- Set
- Audit AJAX Requests: If the refresh icon or other buttons use AJAX, ensure the call URLs are generated with
$this->url->link()(not hardcoded HTTP) to avoid mixed-content blocks.
- Check Form Action URLs: Make sure your cart form's
Clean Up Other PHP Notices
Those extra "Undefined variable" or "Undefined index" warnings can also mess with page functionality. Go through your error log and fix each one:- For undefined variables: Make sure the cart controller (
catalog/controller/checkout/cart.php) initializes every variable passed to the template (e.g.,$data['some_variable'] = '';even if it's empty) - For undefined indexes: Add
isset()checks in the template wherever you access array elements, just like we did for therecurringindex.
- For undefined variables: Make sure the cart controller (
Clear All Caches
Finally, wipe any cached content to ensure your changes take effect:- OpenCart's internal cache (via Admin > System > Maintenance > Cache)
- Your browser cache (do a hard refresh with
Ctrl+Shift+RorCmd+Shift+R) - If you're using a CDN or server-side cache, clear that too
These steps should get your cart buttons working again and eliminate those PHP notices in your SSL-only environment.
内容的提问来源于stack exchange,提问作者user9312112

