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

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 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){
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 已知隐函数其中一个变量的,求另外一个变量
  • ¥15 echarts图表制作
  • ¥15 halcon根据玻璃面板纹路取区域
  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究
  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理
  • ¥50 webrtc-streamer TCP rtsp