du9698
du9698
2015-06-18 19:53
浏览 54
已采纳

Opencart搜索和特殊页面图像错误

There is error in product search and special offers page. When I run product search and get results (or check special offers page). Put mouse on product image and get:

"Notice: Undefined index: image_add in /home/database/public_html/catalog/view/theme/marcus/template/product/search.tpl on line 105Notice: Undefined index: image_add in /home/database/public_html/catalog/view/theme/marcus/template/product/search.tpl on line 115"... (also I add pic of problem)

Code of that part where undefined index is:

<?php
                    if($product['image_add'] != ''){
                        $file_headers = @get_headers($product['image_add']);
                        if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
                            $exists = false;
                        }
                        else {
                            $exists = true;
                        }
                    }

                    if($product['image_add'] != '' && $exists){
?> 

Wierd part bout this problem is that same parts of code used in other pages, but only in those two pages (special offers and search result page) that problem exist.

My OC version is 1.5.6.4 And theme link:

I'm not really a programmer, but know little bit bout coding (apperantly not enough to fix these kinda issues). So if its possible (and if you know how to fix this) writte answer as simple as possible.

P.s.

I contact theme creatore for supp but till today I get no answer from him.

Regards,

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhazhuo0572
    dongzhazhuo0572 2015-06-18 22:28
    已采纳

    Since the index in question (apparently) does not exist, php is going to throw an error when you check it's value. To avoid this error you can simply add some logic to make sure it exists:

    <?php
        if(isset($product['image_add']) && $product['image_add'] != ''){
            $file_headers = @get_headers($product['image_add']);
            if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
                $exists = false;
            } else {
                $exists = true;
            }
        }
        if(isset($product['image_add']) && $product['image_add'] != '' && $exists){
    ?> 
    
    点赞 评论

相关推荐