Jump to content

Get image at order history page


jonyellery

Recommended Posts

Good afternoon.

Version 1.6.x

I am trying to put the photo of each product in the Order History. I've already managed to show images on the history page, but it is repeated in all orders. I'm going to paste here the code I made so far in the HistoryController.php controller

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');
    }
}

Someone could help me?

Thank you

Link to comment
Share on other sites

  • 1 year later...

Hi,

Changes must be made 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;
    }
}

 

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 year later...

@Ress

Hi, I used the code below to show product images on order history, but for and uncknow reason some of the products have no image url showed.

{foreach from=$order.products item=product}
	<img src="{$product.cover.bySize.small_default.url}" width="98" height="98" />
{/foreach}

All the products have images and I see them into product detain and order detail.

Any idea on why this happens?

 

Link to comment
Share on other sites

  • 2 months later...
9 minutes ago, redfordnl said:

All the other methods on the forum are outdated or incomplete/unanswered. 

How about giving us more details. Shop theme and version. Then what you woule like to archive.

Link to comment
Share on other sites

Hello Nickz,

Thanks for your answer. I meant my comment in general. Most of the users of prestashop nowdays use PS 1.7 or new version 8.X (I use for my new shop 8.0.1).

It would be nice if somebody can make a step by step instruction how to add images to order history on customers order-history page (see screenshot).

Thanks in advance!

screenshot.jpg

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