Jump to content

[Solved] How to display Product description in order detail ?


Recommended Posts

HI,

 

Im working on prestashop 1.5.2 and i would like to display the product'description when a client go to his account on "History and details of my orders" after paying his order.

 

i think it's in order-detail.tpl page but i don't know what's the write variable to use..

 

Any ideas ??

 

Thanks!

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

well, in this case modification of the controller is necessary because by default there is no variable for description.

but what, when for example, you remove product from store, then there will be no description

  • Like 1
Link to comment
Share on other sites

it's not as easy as it seems, because you have to:

 

1) modify the HistoryController.php

 

you've got there smarty array:

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

with $orders object.

 

 

you need to modify this object.

 

make a foreach loop, then for each product you have to add description field (query to the mysql database)

  • Like 1
Link to comment
Share on other sites

Thanks again!

 

I have to admitt my php language is very poor, i found the $orders objetc, but i'm kind of lost ..

haw can i add the description field here ?

 

will it be like this ?..

 

foreach ($orders as &$order)
  {
   $myOrder = new Order((int)$order['id_order']);
   if (Validate::isLoadedObject($myOrder))
 $order['virtual'] = $myOrder->isVirtual(false);
			    foreach ($product as &$product)

			    {
				    $product_description = Db::getInstance()->executeS('
				    SELECT *
				    FROM `'._DB_PREFIX_.'product_lang` pl
				    LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = pl.id_product)
				    WHERE od.`id_order` = '.(int)($this->id));

			    }
  }

 

Thanks!

Link to comment
Share on other sites

hello

 

for the first i want to apologise for long waiting time to my reply, i was offline today but now im available :)

 

i checked it once again

 

you have to edit the order-detail.tpl file and OrderDetailController.php

 

there is a call to $order->getProducts();

i think that it will be better to change this function

 

$products = $order->getProducts();

 

this function make another call to the getProductsDetail() function from order class (class/order/Order.php)

 

edit this function, use this code:

public function getProductsDetail()
{
 return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
 SELECT *
 FROM `'._DB_PREFIX_.'order_detail` od
 LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
    LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
 LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
 WHERE od.`id_order` = '.(int)($this->id));
}

 

then you will be able to use {$product.description} variable in the order-detail.tpl file

 

 

effect (i added {$product.description} to the quantity field you can ofcourse create new <td></td> with description)

X0Gbd2l.png

 

 

let me know if this works for you :)

 

regards

  • Like 1
Link to comment
Share on other sites

Hi Vekia !! thanks a lot for your answer!

 

I tried it on "normal" products and it worked very welll!! ut not with virtual products :/

i did the same thig on "getVirtualProducts" function in Order.php

public function getVirtualProducts()
{
 $sql = '
  SELECT `product_id`, `product_attribute_id`, `download_hash`, `download_deadline`
  FROM `'._DB_PREFIX_.'order_detail` od
  LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
   LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
  WHERE od.`id_order` = '.(int)($this->id).'
   AND `download_hash` <> \'\'';
 return Db::getInstance()->executeS($sql);
}

 

Didi i missed something?

 

thanks a lot again!!

Link to comment
Share on other sites

thanks for information that everything works well :)

im glad to hear it :) to mark thread as solved:

[sOLVED] Topic

If, after posting a topic, you find a solution to your problem, please indicate it in your post and describe the solution.

Furthermore if you are the author of the topic for which a solution has been found, please edit your topic title to mark it as [sOLVED].

 

To mark a topic as [solved] :

- Edit the first post of your topic by clicking on the "Edit" button,

- Click on the "Use full editor" button,

 

- Add the "[solved]" string at the beginning of your topic title and click on the "Submit Modified Post" button.

Link to comment
Share on other sites

  • 4 months later...

Hello everyone i'm sorry but i'm following the instructions but I really don't know what to change 

so for example in  order-detail.tpl file 

 

If I add something like <th class="cart_description item">{$product.description} </th>

it should work???? I don't get it

 

 

 

 

you have to edit the order-detail.tpl file and OrderDetailController.php

there is a call to $order->getProducts();
i think that it will be better to change this function

$products = $order->getProducts();
this function make another call to the getProductsDetail() function from order class (class/order/Order.php)

edit this function, use this code:
public function getProductsDetail()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'
._DB_PREFIX_.'order_detail` od
LEFT JOIN `'
._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
     LEFT JOIN `'
._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
LEFT JOIN `'
._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
WHERE od.`id_order` = '
.(int)($this->id));
}
then you will be able to use {$product.description} variable in the order-detail.tpl file

 

Can someone please explain me what should I change and where on $products = $order->getProducts(); I found this on OrderDetailController but nothing to change????

 

public function getProductsDetail()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'
._DB_PREFIX_.'order_detail` od
LEFT JOIN `'
._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
     LEFT JOIN `'
._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
LEFT JOIN `'
._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
WHERE od.`id_order` = '
.(int)($this->id));
}

 

on this one I already got the function in Classes\Order\order.php but changed with adding the new leftjoin

 

and on the end should I need to change in the HistoryController.php ????? and can someone tell me what to change if that so???

 

Thanks in advance

Link to comment
Share on other sites

Hello everyone i'm sorry but i'm following the instructions but I really don't know what to change 

so for example in  order-detail.tpl file 

 

If I add something like <th class="cart_description item">{$product.description} </th>

it should work???? I don't get it

 

 

 

Can someone please explain me what should I change and where on $products = $order->getProducts(); I found this on OrderDetailController but nothing to change????

 

public function getProductsDetail()

{

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('

SELECT *

FROM `'._DB_PREFIX_.'order_detail` od

LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)

     LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product

LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)

WHERE od.`id_order` = '.(int)($this->id));

}

 

on this one I already got the function in Classes\Order\order.php but changed with adding the new leftjoin

 

and on the end should I need to change in the HistoryController.php ????? and can someone tell me what to change if that so???

 

Thanks in advance

 

Hello,

 

First you have to change the class getProductsDetail() in "order.php" (classes/order/)

 

For material products

public function getProductsDetail()
{
  return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
  SELECT *
  FROM `'._DB_PREFIX_.'order_detail` od
  LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
		    LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
  LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
  WHERE od.`id_order` = '.(int)($this->id));
}

For Virtual products

public function getVirtualProducts()
{
  $sql = '
   SELECT `product_id`, `product_attribute_id`, `download_hash`, `download_deadline`
   FROM `'._DB_PREFIX_.'order_detail` od
   LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
    LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
   WHERE od.`id_order` = '.(int)($this->id).'
    AND `download_hash` <> \'\'';
  return Db::getInstance()->executeS($sql);
}

only then, you can put the variable  {$product.description} in order-detail.tpl wherever you want.

 

Hope it will help you.

Link to comment
Share on other sites

Hello,

 

First you have to change the class getProductsDetail() in "order.php" (classes/order/)

 

For material products

public function getProductsDetail()
{
  return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
  SELECT *
  FROM `'._DB_PREFIX_.'order_detail` od
  LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
		    LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
  LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
  WHERE od.`id_order` = '.(int)($this->id));
}

For Virtual products

public function getVirtualProducts()
{
  $sql = '
   SELECT `product_id`, `product_attribute_id`, `download_hash`, `download_deadline`
   FROM `'._DB_PREFIX_.'order_detail` od
   LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id)
    LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product
   WHERE od.`id_order` = '.(int)($this->id).'
    AND `download_hash` <> \'\'';
  return Db::getInstance()->executeS($sql);
}

only then, you can put the variable  {$product.description} in order-detail.tpl wherever you want.

 

Hope it will help you.

 

 

Hello and many thanks for your reply, I did changed what you said in in "order.php" (classes/order/)

 

But even when I try to add the variable {$product.description} in order-detail.tpl  that doesnt work here is the sample

<div id="order-detail-content" class="table_block">
	<table class="std">
		<thead>
			<tr>
				{if $return_allowed}<th class="first_item"><input type="checkbox" /></th>{/if}
				<th class="{if $return_allowed}item{else}first_item{/if}">{l s='Reference'}</th>
				<th class="item"> {$product.description}</th>
				<th class="item">{l s='Quantity'}</th>
				{if $order->hasProductReturned()}
					<th class="item">{l s='Returned'}</th>
				{/if}
				<th class="item">{l s='Unit price'}</th>
				<th class="last_item">{l s='Total price'}</th>
			</tr>
		</thead>

that doesnt change anything, I just would like to change since I don't know why adding the description of the product in the case but no :'( as you can see it only give the name of the product and not his description

 

I add the screen for more infos 35hrd7c.png

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

  • 2 years later...

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