Jump to content
thirty bees forum
  • 0

Product Images on Order History


SakuraKitKats

Question

I am using the Community Theme and want to have my order history look like the attached picture, how can I add the product images to it?

I have found some PS 1.6 related code, but it does not seem to work and does not display the pictures. This is what I used:

In HistoryController.php:

 public function initContent()
    {
        
        parent::initContent();

        if ($orders = Order::getCustomerOrders($this->context->customer->id)) {

            foreach ($orders as &$order) {
                $myOrder = new Order((int)$order['id_order']);

                if (Validate::isLoadedObject($myOrder)) {
                    $order['virtual'] = $myOrder->isVirtual(false);
                }

                    
            }
        }    

                           $myOrder = new Order((int)$order['id_order']);   
                            $products = $myOrder->getProducts();
                            $product_ids = array();
                            foreach ($products as $product){
                            $product_ids[] = (int)$product['id_product'];
                            }
                  
                            $cover = Image::getCover((int)$product['id_product']); // array image

                            if (sizeof($cover['id_image']) > 0) {
                                $folder = Image::getImgFolderStatic($cover['id_image']);  // folders inside /img/p/
                                $image = '<img src="../img/p/'.$folder.$cover['id_image'].'-medium_default.jpg" alt="" width="125" height="125" class="imgm img-thumbnail" />';
                            } else {
                                $image = '<img src="../img/p/en-default-medium_default.jpg" alt="" width="125" height="125" class="imgm img-thumbnail" />';
                            }

        $this->context->smarty->assign(array(
            'orders' => $orders,
            'images' => $image,
            'invoiceAllowed' => (int)Configuration::get('PS_INVOICE'),
            'reorderingAllowed' => !(bool)Configuration::get('PS_DISALLOW_HISTORY_REORDERING'),
            'slowValidation' => Tools::isSubmit('slowvalidation')
        ));

    $this->setTemplate(_PS_THEME_DIR_.'history.tpl');
    }
} 


And in OrderDetailController, initContent(), after $products = $order->getProducts();

foreach ($products as &$product) {
    $id_image = false;
    if (isset($product['image']->id_image)) {
        $id_image = $product['image']->id_image;
    } else {
        $cover = Product::getCover($product['id_product']);
        if ($cover) {
            $id_image = $cover['id_image'];
        }

    }

    if ($id_image) {
        $product_object = new Product($product['id_product'], false, $this->context->language->id);
        $image_url = $this->context->link->getImageLink($product_object->link_rewrite, $product['image']->id_image, 'home_default');
        $product['image_url'] = $image_url;
    }
}


Any help would be kindly appreciated!!

Screenshot 2024-06-29 185146.png

Edited by SakuraKitKats
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

you dont need to modify any controller.

Order->getProducts() already contains image information.

you can just add to your order-detail.tpl

{$link->getImageLink($product.link_rewrite, $product.image->id_image, 'medium_default')|escape:'html':'UTF-8'}

 

Link to comment
Share on other sites

  • 0

yes, inside order-detail.tpl

just look for this line 

<div id="order-detail-content" class="table_block table-responsive">

and after that line you the table. just add another th in the thead and another td to tbody.

you will also need to modify the tfoot colspans to match the extra column.

dont forget that 

{$link->getImageLink($product.link_rewrite, $product.image->id_image, 'medium_default')|escape:'html':'UTF-8'}

only return the url to the image, so you will need to wrap it inside src tag

Link to comment
Share on other sites

  • 0

i dont understand what you mean by default niara medium and not the image of the product.

you can choose which thumbnail to show based on your image types.

on the sample i sent its taking the medium_default.

order history is the page that shows all my purchases history, order-detail is the template that render the order it self (when you click on an order).

Link to comment
Share on other sites

  • 0
Posted (edited)

@yaniv14 Sorry, now I properly understand. I thought this would already pull the image of the product automatically. I didn't notice it was only using the medium_default as example...
Basically, I want it to show the image of the products from the order like this (attached picture)

I have found this code for determinding the product photo by ID on a PrestaShop 1.6 forum thread, but it's for the HistoryController.php file:

$cover = Image::getCover((int)$product['id_product']); // array image

                            if (sizeof($cover['id_image']) > 0) {
                                $folder = Image::getImgFolderStatic($cover['id_image']);  // folders inside /img/p/
                                $image = '<img src="../img/p/'.$folder.$cover['id_image'].'-medium_default.jpg" alt="" width="125" height="125" class="imgm img-thumbnail" />';
                            } else {
                                $image = '<img src="../img/p/en-default-medium_default.jpg" alt="" width="125" height="125" class="imgm img-thumbnail" />';
                            }

How could I implement it in order-detail?

 

Screenshot 2024-06-30 193455.png

Edited by SakuraKitKats
Link to comment
Share on other sites

  • 0

just add img src where ever you want it on the file.

<img src="{$link->getImageLink($product.link_rewrite, $product.image->id_image, 'medium_default')|escape:'html':'UTF-8'}">

 

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...