Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

opencart2.x - Proper way to work using the real image of a product on OpenCart 2

I'm currently looking for the proper way to work on a theme using the real image of a product and not its thumbnail (identified as $thumb in the default theme).

I have found a abrupt trick by adding a line in the controller file:

$this->data['cover'] = $product_info['image'];

But does anybody have experienced a better method (eg with vqmod) to retrieve these real image data without changing controller content (for using in template pages, such as product.tpl or category.tpl for example)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With help from members of OpenCart forum, I managed to find a functional solution (using vQmod). It is thus require to create an .xml file placed in the vqmod/xml folder and containing, for example:

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <id>Recover Real Image</id>
    <version></version>
    <vqmver></vqmver>
    <author></author>
    <email></email>
    <website></website>
    <file name="catalog/controller/product/product.php">
    <operation>
        <search position="after"><![CDATA[
            $data['points'] = $product_info['points'];
        ]]></search>
        <add><![CDATA[
            $data['picture'] = HTTP_SERVER.'/image/'.$product_info['image'];
        ]]></add>
    </operation>
    </file>
</modification>

If product image can not be found and assuming a <default.jpg> is put the root of the <image> folder, the <add> element can be replaced by:

if(empty($product_info['image'])){
    $data['picture'] = HTTP_SERVER.'image/default.jpg';
}
else{
    $data['picture'] = HTTP_SERVER.'image/'.$product_info['image'];
}

Other possible suggestions, by using:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...