Jump to content

Adding product image in Order History (Front Office)


Recommended Posts

I try to copy the code from cart but the result shows only the question mark image.

 

The product link is correct but seems it get the wrong image link.

 


		 <a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'medium_default')}" alt="{$product.name|escape:'htmlall':'UTF-8'}"></a>

post-570804-0-78816800-1375887315_thumb.png

Edited by whitehumorous (see edit history)
Link to comment
Share on other sites

this is the proper way, but in the order history products array isn't full.

What to do? you have to edit the history controller, untortunately there is no other way to achieve what you expect.

 

Can you give me some hint how to edit the history controller? Which file and the code.

Anyway thanks for your reply.

Link to comment
Share on other sites

  • 7 years later...

i write this code and it's work properly.3 files are important to add this in preatshop 1.7. i tested this code in preastashop 1.7.6.2

file 1:  Root/classes/order/Order.php (product image path return)

code:

/ GET ORDER PRODUCT IMAGE URL BY order id
    // @ return image url
    // $order is order id
    
    public function getOrderProductUrl($idOrder)
    {
        $imagePath = '';
        $order = new Order($idOrder);
        
        $product_id =Db::getInstance()->getValue(
                'SELECT product_id
                FROM `' . _DB_PREFIX_ . 'order_detail`
                WHERE `id_order` = ' .$idOrder
            );    
            
        $id_product = $product_id;
        $id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
        $image = Image::getCover($id_product);
        $product = new Product($id_product);
        $link = new Link;
         
        $imagePath = $link->getImageLink($product->link_rewrite[Context::getContext()->language->id], $image['id_image'], 'home_default');
         
        return "https://".$imagePath;
    }

file 2 - Root/controllers/front/HistoryController.php (Controller)

Code:  this code put inside the foreacjh loop. which id return for data. $order..

$orders[$customer_order['id_order']]['product_img'] = Order::getOrderProductUrl((int) $customer_order['id_order']);

 

File 3 - Root/themes/Your Theme/templates/customer/history.tpl

code: use this image tag where you want to show product image

<th><img src="{$order.product_img}" alt="product-image" width="216px"></th>

 

image.png.d8124dccc6f5832fba9f213d49eecebf.png

image.png

Link to comment
Share on other sites

  • 1 year later...

Hello,

Thanks for this code. But sadly I can't get it to work in Prestashop 8.x... I get an blank screen on the my account and history detail pages both. So the code is crashing for this Prestashop version.

Does somebody have a good solution for this? 

Thanks in advance.

Greetings

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...