Myles_UA Posted November 10, 2018 Share Posted November 10, 2018 Hi. I'm trying to display just ordered products in order history without displaying orders and clicking on every order to display product. I'm a bit rewriting history.tpl and HistoryController, adding there lines from OrderDetailController. But as the result I'm getting Notice: Undefined index: products .... eval()'d code on line 218 and Notice: Trying to get property of non-object in ... eval()'d code on line 218 What am I doing wrong here? Link to comment Share on other sites More sharing options...
joseantgv Posted November 12, 2018 Share Posted November 12, 2018 (edited) On 10/11/2018 at 4:36 PM, Myles_UA said: Hi. I'm trying to display just ordered products in order history without displaying orders and clicking on every order to display product. I'm a bit rewriting history.tpl and HistoryController, adding there lines from OrderDetailController. But as the result I'm getting Notice: Undefined index: products .... eval()'d code on line 218 and Notice: Trying to get property of non-object in ... eval()'d code on line 218 What am I doing wrong here? Please paste your code Edited November 13, 2018 by joseantgv (see edit history) Link to comment Share on other sites More sharing options...
Myles_UA Posted November 12, 2018 Author Share Posted November 12, 2018 12 hours ago, joseantgv said: Deberías copiar el código. Here's controller and tpl class DostupControllerCore extends FrontController { public $auth = true; public $php_self = 'dostup'; public $authRedirection = 'dostup'; public $ssl = true; public function setMedia() { parent::setMedia(); $this->addCSS(array( _THEME_CSS_DIR_.'history.css', _THEME_CSS_DIR_.'addresses.css' )); $this->addJS(array( _THEME_JS_DIR_.'history.js', _THEME_JS_DIR_.'tools.js' // retro compat themes 1.5 )); } public function orderhistoryproducts($order, $template_vars = false) { $result = Db::getInstance()->getRow(' SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, os.`pdf_invoice`, os.`pdf_delivery` FROM `'._DB_PREFIX_.'order_detail` oh LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order` LEFT JOIN `'._DB_PREFIX_.'products` c ON o.`product_id` = c.`product_id` LEFT JOIN `'._DB_PREFIX_.'product_name` os ON oh.`product_name` = os.`product_name` LEFT JOIN `'._DB_PREFIX_.'order_detail` osl ON (os.`id_order_detail` = osl.`id_order_detail` AND osl.`id_lang` = o.`id_lang`) WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1'); if (isset($result['template']) && Validate::isEmail($result['email'])) { ShopUrl::cacheMainDomainForShop($order->id_shop); $topic = $result['osname']; $order_details = $order->getProducts(); $product_var_tpl_list = array(); foreach ($order_details as $id => &$order_detail) { $product_var_tpl = array( 'products' => $order_detail['product_name'], 'reference' => $order_detail['product_reference'], 'name' => $order_detail['product_name'].(isset($order_detail['product_attributes']) ? ' - '.$order_detail['product_attributes'] : ''), 'unit_price' => Tools::displayPrice($order_detail['unit_price_tax_incl'], $this->context->currency, false), 'price' => Tools::displayPrice($order_detail['total_price_tax_incl'], $this->context->currency, false), 'quantity' => $order_detail['product_quantity'], 'customization' => $order_detail['customizedDatas'] ); $product_var_tpl_list[] = $product_var_tpl; } // $product_list_txt = ''; $product_list_html = ''; if (count($product_var_tpl_list) > 0) { $product_list_txt = $this->getEmailTemplateContent('order_conf_product_list.txt', Mail::TYPE_TEXT, $product_var_tpl_list); $product_list_html = $this->getEmailTemplateContent('order_conf_product_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list); } /* GET THE DISCOUNTS */ $cart_rules = $order->getCartRules(); foreach ($cart_rules as $id => &$cart_rule) { $cart_rules_list[] = array( 'voucher_name' => $cart_rule['name'], 'voucher_reduction' => ($cart_rule['value'] != 0.00 ? '-' : '').Tools::displayPrice($cart_rule['value'], $this->context->currency, false) ); } $cart_rules_list_txt = ''; $cart_rules_list_html = ''; if (count($cart_rules_list) > 0) { $cart_rules_list_txt = $this->getEmailTemplateContent('order_conf_cart_rules.txt', Mail::TYPE_TEXT, $cart_rules_list); $cart_rules_list_html = $this->getEmailTemplateContent('order_conf_cart_rules.tpl', Mail::TYPE_HTML, $cart_rules_list); } $invoice_address = new Address((int)$order->id_address_invoice); $invoiceAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true); $deliveryAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true); $country = new Country((int)$invoice_address->id_country); $delivery_address = null; $formatted_delivery_address = ''; if (isset($order->id_address_delivery) && $order->id_address_delivery) { $delivery_address = new Address((int)$order->id_address_delivery); } $carrier = new Carrier((int)($order->id_carrier), $order->id_lang); $data = array( '{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => (int)$this->id_order, '{delivery_block_txt}' => AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, ', ', ' '), '{invoice_block_txt}' => AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, ', ', ' '), '{delivery_block_html}' => AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, '<br />',' ', array( 'firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>' )), '{invoice_block_html}' => AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, '<br />',' ', array( 'firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>' )), '{delivery_company}' => $delivery_address->company, '{delivery_firstname}' => $delivery_address->firstname, '{delivery_lastname}' => $delivery_address->lastname, '{delivery_address1}' => $delivery_address->address1, '{delivery_address2}' => $delivery_address->address2, '{delivery_city}' => $delivery_address->city, '{delivery_postal_code}' => $delivery_address->postcode, '{delivery_country}' => $delivery_address->country, '{delivery_state}' => $delivery_address->id_state ? $delivery_state->name : '', '{delivery_phone}' => ($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile, '{delivery_other}' => $delivery_address->other, '{invoice_company}' => $invoice_address->company, '{invoice_vat_number}' => $invoice_address->vat_number, '{invoice_firstname}' => $invoice_address->firstname, '{invoice_lastname}' => $invoice_address->lastname, '{invoice_address2}' => $invoice_address->address2, '{invoice_address1}' => $invoice_address->address1, '{invoice_city}' => $invoice_address->city, '{invoice_postal_code}' => $invoice_address->postcode, '{invoice_country}' => $invoice_address->country, '{invoice_state}' => $invoice_address->id_state ? $invoice_state->name : '', '{invoice_phone}' => ($invoice_address->phone) ? $invoice_address->phone : $invoice_address->phone_mobile, '{invoice_other}' => $invoice_address->other, '{order_name}' => $order->getUniqReference(), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 1), '{carrier}' => (!isset($carrier->name)) ? Tools::displayError('No carrier') : $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $product_list_html, '{products_txt}' => $product_list_txt, '{discounts}' => $cart_rules_list_html, '{discounts_txt}' => $cart_rules_list_txt, '{total_paid}' => Tools::displayPrice($order->total_paid, $this->context->currency, false), '{total_products}' => Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $this->context->currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $this->context->currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $this->context->currency, false), '{total_tax_paid}' => Tools::displayPrice(($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $this->context->currency, false) ); } } /** * Assign template vars related to page content * @see FrontController::initContent() */ 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); } } } $this->context->smarty->assign(array( 'orders' => $orders, 'invoiceAllowed' => (int)Configuration::get('PS_INVOICE'), 'reorderingAllowed' => !(bool)Configuration::get('PS_DISALLOW_HISTORY_REORDERING'), 'slowValidation' => Tools::isSubmit('slowvalidation') )); $this->setTemplate(_PS_THEME_DIR_.'dostup.tpl'); } } {foreach from=$order_detail item=product name=products} {if !isset($product.deleted)} {assign var='productId' value=$product.product_id} {assign var='productAttributeId' value=$product.product_attribute_id} {if isset($product.customizedDatas)} {assign var='productQuantity' value=$product.product_quantity-$product.customizationQuantityTotal} {else} {assign var='productQuantity' value=$product.product_quantity} {/if} <!-- Classic products --> {if $product.product_quantity > $product.customizationQuantityTotal} <tr class="item"> <td class="order_cb"><input type="checkbox" id="cb_{$product.id_order_detail|intval}" name="ids_order_detail[{$product.id_order_detail|intval}]" value="{$product.id_order_detail|intval}" /></td> <td><label for="cb_{$product.id_order_detail|intval}">{if $product.product_reference}{$product.product_reference|escape:'html':'UTF-8'}{else}--{/if}</label></td> <td class="bold"> <label for="cb_{$product.id_order_detail|intval}"> {if $product.download_hash && $logable && $product.display_filename != '' && $product.product_quantity_refunded == 0 && $product.product_quantity_return == 0} {if isset($is_guest) && $is_guest} <a href="{$link->getPageLink('get-file', true, NULL, "key={$product.filename|escape:'html':'UTF-8'}-{$product.download_hash|escape:'html':'UTF-8'}&id_order={$order->id}&secure_key={$order->secure_key}")|escape:'html':'UTF-8'}" title="{l s='Download this product'}"> {else} <a href="{$link->getPageLink('get-file', true, NULL, "key={$product.filename|escape:'html':'UTF-8'}-{$product.download_hash|escape:'html':'UTF-8'}")|escape:'html':'UTF-8'}" title="{l s='Download this product'}"> {/if} <img src="{$img_dir}icon/download_product.gif" class="icon" alt="{l s='Download product'}" /> </a> {if isset($is_guest) && $is_guest} <a href="{$link->getPageLink('get-file', true, NULL, "key={$product.filename|escape:'html':'UTF-8'}-{$product.download_hash|escape:'html':'UTF-8'}&id_order={$order->id}&secure_key={$order->secure_key}")|escape:'html':'UTF-8'}" title="{l s='Download this product'}"> {$product.product_name|escape:'html':'UTF-8'} </a> {else} <a href="{$link->getPageLink('get-file', true, NULL, "key={$product.filename|escape:'html':'UTF-8'}-{$product.download_hash|escape:'html':'UTF-8'}")|escape:'html':'UTF-8'}" title="{l s='Download this product'}"> {$product.product_name|escape:'html':'UTF-8'} </a> {/if} {else} {$product.product_name|escape:'html':'UTF-8'} {/if} </label> </td> <td class="return_quantity"> <input class="order_qte_input form-control grey" name="order_qte_input[{$product.id_order_detail|intval}]" type="text" size="2" value="{$productQuantity|intval}" /> <div class="clearfix return_quantity_buttons"> <a href="#" class="return_quantity_down btn btn-default button-minus"><span><i class="icon-minus"></i></span></a> <a href="#" class="return_quantity_up btn btn-default button-plus"><span><i class="icon-plus"></i></span></a> </div> <label for="cb_{$product.id_order_detail|intval}"><span class="order_qte_span editable">{$productQuantity|intval}</span></label></td> {if $order->hasProductReturned()} <td> {$product['qty_returned']} </td> {/if} <td class="price"> <label for="cb_{$product.id_order_detail|intval}"> {convertPriceWithCurrency price=$product.unit_price_tax_incl currency=$currency} </label> </td> <td class="price"> <label for="cb_{$product.id_order_detail|intval}"> {if $group_use_tax} {convertPriceWithCurrency price=$product.total_price_tax_incl currency=$currency} {else} {convertPriceWithCurrency price=$product.total_price_tax_excl currency=$currency} {/if} </label> </td> </tr> {/if} {/if} {/foreach} {foreach from=$discounts item=discount} <tr class="item"> <td>{$discount.name|escape:'html':'UTF-8'}</td> <td>{l s='Voucher'} {$discount.name|escape:'html':'UTF-8'}</td> <td><span class="order_qte_span editable">1</span></td> <td> </td> <td>{if $discount.value != 0.00}-{/if}{convertPriceWithCurrency price=$discount.value currency=$currency}</td> </tr> {/foreach} </tbody> <p class="info-title">{l s='Here are the orders you\'ve placed since your account was created.'}</p> {if $slowValidation} <p class="alert alert-warning">{l s='If you have just placed an order, it may take a few minutes for it to be validated. Please refresh this page if your order is missing.'}</p> {/if} <div class="block-center" id="block-history"> {if $orders && count($orders)} <table id="order-list" class="table table-bordered footab"> <thead> <tr> <th class="first_item" data-sort-ignore="true">{l s='Order reference'}</th> <th class="item">{l s='Date'}</th> <th data-hide="phone" class="item">{l s='Total price'}</th> <th data-sort-ignore="true" data-hide="phone,tablet" class="item">{l s='Payment'}</th> <th class="item">{l s='Status'}</th> <th data-sort-ignore="true" data-hide="phone,tablet" class="item">{l s='Invoice'}</th> <th data-sort-ignore="true" data-hide="phone,tablet" class="last_item"> </th> </tr> </thead> <tbody> {foreach from=$orders item=order name=myLoop} <tr class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{/if}"> <td class="history_link bold"> {if isset($order.invoice) && $order.invoice && isset($order.virtual) && $order.virtual} <img class="icon" src="{$img_dir}icon/download_product.gif" alt="{l s='Products to download'}" title="{l s='Products to download'}" /> {/if} <a class="color-myaccount" href="javascript:showOrder(1, {$order.id_order|intval}, '{$link->getPageLink('order-detail', true, NULL, "id_order={$order.id_order|intval}")|escape:'html':'UTF-8'}');"> {Order::getUniqReferenceOf($order.id_order)} </a> </td> <td data-value="{$order.date_add|regex_replace:"/[\-\:\ ]/":""}" class="history_date bold"> {dateFormat date=$order.date_add full=0} </td> <td class="history_price" data-value="{$order.total_paid}"> <span class="price"> {displayPrice price=$order.total_paid currency=$order.id_currency no_utf8=false convert=false} </span> </td> <td class="history_method">{$order.payment|escape:'html':'UTF-8'}</td> <td{if isset($order.order_state)} data-value="{$order.id_order_state}"{/if} class="history_state"> {if isset($order.order_state)} <span class="label{if isset($order.order_state_color) && Tools::getBrightness($order.order_state_color) > 128} dark{/if}"{if isset($order.order_state_color) && $order.order_state_color} style="background-color:{$order.order_state_color|escape:'html':'UTF-8'}; border-color:{$order.order_state_color|escape:'html':'UTF-8'};"{/if}> {$order.order_state|escape:'html':'UTF-8'} </span> {/if} </td> <td class="history_invoice"> {if (isset($order.invoice) && $order.invoice && isset($order.invoice_number) && $order.invoice_number) && isset($invoiceAllowed) && $invoiceAllowed == true} <a class="link-button" href="{$link->getPageLink('pdf-invoice', true, NULL, "id_order={$order.id_order}")|escape:'html':'UTF-8'}" title="{l s='Invoice'}" target="_blank"> <i class="icon-file-text large"></i>{l s='PDF'} </a> {else} - {/if} </td> <td class="history_detail"> <a class="btn btn-default button button-small" href="javascript:showOrder(1, {$order.id_order|intval}, '{$link->getPageLink('order-detail', true, NULL, "id_order={$order.id_order|intval}")|escape:'html':'UTF-8'}');"> <span> {l s='Details'}<i class="icon-chevron-right right"></i> </span> </a> {if isset($opc) && $opc} <a class="link-button" href="{$link->getPageLink('order-opc', true, NULL, "submitReorder&id_order={$order.id_order|intval}")|escape:'html':'UTF-8'}" title="{l s='Reorder'}"> {else} <a class="link-button" href="{$link->getPageLink('order', true, NULL, "submitReorder&id_order={$order.id_order|intval}")|escape:'html':'UTF-8'}" title="{l s='Reorder'}"> {/if} {if isset($reorderingAllowed) && $reorderingAllowed} <i class="icon-refresh"></i>{l s='Reorder'} {/if} </a> </td> </tr> {/foreach} Link to comment Share on other sites More sharing options...
joseantgv Posted November 13, 2018 Share Posted November 13, 2018 (edited) Which is the content of $order_detail in the TPL? Edited November 13, 2018 by joseantgv (see edit history) Link to comment Share on other sites More sharing options...
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