SakuraKitKats Posted June 29 Posted June 29 (edited) 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!! Edited June 29 by SakuraKitKats
0 yaniv14 Posted June 29 Posted June 29 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'}
0 SakuraKitKats Posted June 30 Author Posted June 30 @yaniv14 Thank you! Silly question but where exactly do I add it inside of order-detail.tpl?
0 yaniv14 Posted June 30 Posted June 30 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
0 SakuraKitKats Posted June 30 Author Posted June 30 @yaniv14 Everything works, thank you lots for your help!! But there is still one problem, it only gives me the default niara medium image and not the image of the product. Also, this only shows on order detail and not on order history or?
0 yaniv14 Posted June 30 Posted June 30 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).
0 SakuraKitKats Posted June 30 Author Posted June 30 (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? Edited June 30 by SakuraKitKats
0 SakuraKitKats Posted July 2 Author Posted July 2 @yaniv14 Do you know how I could get the product cover?
0 yaniv14 Posted July 2 Posted July 2 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'}">
Question
SakuraKitKats
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:
And in OrderDetailController, initContent(), after $products = $order->getProducts();
Any help would be kindly appreciated!!
8 answers to this question
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now