0

For those familiar with Opencart, on my website's cart page the "apply coupon," "apply shipping" and update item total buttons (the refresh symbol) aren't functioning. When clicked, the page refreshes as if it's updated the total/applied the coupon/shipping value, but nothing happens.

Looking at the error logs, I see this:

PHP Notice:  Undefined index: recurring in /home/[username]/public_html/catalog/view/theme/[custom_theme]/template/module/cart.tpl on line 19

These are lines 1-22 of cart.tpl:

<div id="cart">
  <div class="heading">
    <h4><?php echo $heading_title; ?></h4>
    <a><span id="cart-total"><?php echo $text_items; ?></span></a></div>
  <div class="content">
    <?php if ($products || $vouchers) { ?>
    <div class="mini-cart-info">
      <table>
        <?php foreach ($products as $product) { ?>
        <tr>
          <td class="image"><?php if ($product['thumb']) { ?>
            <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" /></a>
            <?php } ?></td>
          <td class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
            <div>
              <?php foreach ($product['option'] as $option) { ?>
              - <small><?php echo $option['name']; ?> <?php echo $option['value']; ?></small><br />
              <?php } ?>
              <?php if ($product['recurring']): ?>
              - <small><?php echo $text_payment_profile ?> <?php echo $product['profile']; ?></small><br />
              <?php endif; ?>

So I did some digging. It seems like the error isn't anything serious (PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"). I had a look at the top few solutions and I couldn't figure out how to properly alter the variable on line 19. I also had a look at this: How to correct PHP Notice: Undefined index but I'm not experienced enough with PHP to apply this solution to the code I'm dealing with.

I then migrated the entire site onto another server and domain and the cart page worked fine. The difference ended up being the SSL certificate - on the main site https is enabled on all pages, on the second server I don't have SSL installed.

EDIT: I then went back on my main server and disabled SSL in Opencart settings and disabled my htaccess https redirect. The cart then worked fine under http. But I'd like to have SSL enabled if possible.

I tried a stop-gap solution: forcing http on the cart page. I used this solution: mod_rewrite with exceptions to come up with this:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !/index.php?route=checkout/cart
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

But the site continues to force https on all pages, even when I type http:// in manually.

To summarize:

  • Should I be working to fix the undefined PHP index, or should I just disable SSL on the cart page (the only page affected by SSL issues)?
  • How can I best achieve the most appropriate solution in getting the cart page to function properly?
  • So you `$product` does not have `recurrying` key. How can this be connected to ssl? Did you check output of `$product` on your servers? – u_mulder Feb 04 '18 at 10:56
  • @u_mulder I tried turning off SSL in Opencart settings and removing the 301 redirect on my main site, after which the cart worked fine. So it must be something to do with SSL. I'm not sure how I would go about checking the output of $product on the two servers, how can I do that? – user9312112 Feb 04 '18 at 11:09
  • `print_r($products)` probably? – u_mulder Feb 04 '18 at 11:09
  • @u_mulder sorry but I know next to nothing about PHP at the moment - currently I'm just running CMSs from templates while learning basic HTML/CSS. Where would I run that function? I get the impression from http://php.net/manual/en/function.print-r.php that I would see the output in Firebug, is that correct? – user9312112 Feb 04 '18 at 11:26
  • @user9312112 `var_dump($products);die();` or `print_r($products);die();` the `$products` array to make sure there are no recurring keys causing this issue. You shall see the output on the browser page itself. Turning off `SSL` is a temporary & senseless solution. – Rohit Batra Feb 05 '18 at 04:40
  • @RohitBatra I put `` at the end of the cart.tpl file with SSL on (accessed the page with https). It printed the following: `Array ( [0] => Array ( [key] => 92:: [thumb] => (https://example.com/image.png) [name] => (item title) [model] => (item model) [option] => Array ( ) [quantity] => 1 **[price] => $4.95** [total] => $4.95 [href] => (http://example.com/item) ) )`. Please let me know if there's anything wrong with how I did it, seems to me like there isn't a recurring key as it showed the correct value for price but I'm not sure. – user9312112 Feb 05 '18 at 09:22
  • @user9312112 in `cart.tpl` please try changing this statement `` to `` – Rohit Batra Feb 05 '18 at 09:26
  • @RohitBatra Same thing happens as before with that change under SSL. Error logs print the same thing too unfortunately. – user9312112 Feb 05 '18 at 11:20
  • @user9312112 there seems to be a problem with the array creation of `$products`, somehow its not getting `recurring` index while creation. so the above statement should've checked it & only executed if there was an index `recurring` available in the `$products` array. – Rohit Batra Feb 05 '18 at 11:24
  • @RohitBatra I should also mention that the error log also prints these messages sometimes, but not nearly as often as the other message: `2018-02-05 11:05:40 - PHP Notice: Undefined variable: recurring in /home/[user]/public_html/vqmod/vqcache/vq2-catalog_view_theme_[theme]_template_module_account.tpl on line 20` and `2018-02-05 11:05:40 - PHP Notice: Undefined variable: text_recurring in /home/[user]/public_html/vqmod/vqcache/vq2-catalog_view_theme_[theme]_template_module_account.tpl on line 20` This is that file: https://pastebin.com/pX4x2H6T could that be something to do with it? – user9312112 Feb 05 '18 at 11:37
  • @user9312112 is this causing any problem on the website, ignore the error log for a moment? – Rohit Batra Feb 05 '18 at 11:39
  • @RohitBatra Yes. Certain functions on the cart page (apply shipping/coupons and updating the item quantity) don't work when SSL is enabled. Trying to use these functions causes the errors to print. – user9312112 Feb 05 '18 at 20:16
  • php array indices have nothing to do with ssl/tls enablement. also, the cart class is where that array is created and the fact that you have a missing key should be cause for concern since that class has apparently been modified in a not so good way. – But those new buttons though.. Feb 08 '18 at 08:05
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – But those new buttons though.. Feb 08 '18 at 08:07

0 Answers0