Page 1 of 1

Show all products image and name in order history page in opencart 3

Posted: Tue Feb 19, 2019 8:37 pm
by prosenjeet123
I want to show product details/get all products images names inside an order in order history, to achieve the same I have inserted my code inside a result loop just like the below code but it is fetching only one product and that same product is visible to each orders.

1.catalog/controller/account/order.php

Code: Select all

public function index() {
...
foreach ($results as $result) {
...

//for product for loop

            $order_info = $this->model_account_order->getOrder($result['order_id']);

            if ($order_info) {
            $this->load->model('catalog/product');
            $this->load->model('tool/upload');



            // Products


            $data['products'] = array();

            $products = $this->model_account_order->getOrderProducts($result['order_id']);

            foreach ($products as $product) {
                $option_data = array();

                $options = $this->model_account_order->getOrderOptions($result['order_id'], $product['order_product_id']);

                foreach ($options as $option) {
                    if ($option['type'] != 'file') {
                        $value = $option['value'];
                    } else {
                        $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

                        if ($upload_info) {
                            $value = $upload_info['name'];
                        } else {
                            $value = '';
                        }
                    }

                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
                    );
                }

                $product_info = $this->model_catalog_product->getProduct($product['product_id']);

                if ($product_info) {
                    $reorder = $this->url->link('account/order/reorder', 'order_id=' . $result['order_id'] . '&order_product_id=' . $product['order_product_id'], true);
                } else {
                    $reorder = '';
                }

                $data['products'][] = array(
                    'name'     => $product['name'],
                    'model'    => $product['model'],
                    'option'   => $option_data,
                    'quantity' => $product['quantity'],
                    'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
                    'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
                    'reorder'  => $reorder,
                    'return'   => $this->url->link('account/return/add', 'order_id=' . $result['order_id'] . '&product_id=' . $product['product_id'], true)
                );

                // Totals
                $data['totals'] = array();

                $totals = $this->model_account_order->getOrderTotals($result['order_id']);

                    foreach ($totals as $total) {
                    $data['totals'][] = array(
                        'title' => $total['title'],
                        'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
                    );
                }




            }

            //end for loop of product
            }
}

2.order-list.twig SCREENSHOT HERE :
Image
3.Front Page( Order History) SCREESHOT :
Image

Re: Show all products image and name in order history page in opencart 3

Posted: Tue Feb 19, 2019 11:03 pm
by xxvirusxx

Re: Show all products image and name in order history page in opencart 3

Posted: Tue Feb 19, 2019 11:53 pm
by prosenjeet123
Hi,
Thanks for the quick response, well i want to show product details in order history page of user not admin.

Thanks

Re: Show all products image and name in order history page in opencart 3

Posted: Wed Feb 20, 2019 12:06 am
by xxvirusxx

Re: Show all products image and name in order history page in opencart 3

Posted: Wed Feb 20, 2019 12:32 am
by prosenjeet123
The link you shared is for admin/invoice/order information(not order history which is different e.g when you click on order history the first page you can see is order history after clicking on view details it will take you to order info page, i want to show product details in order history)

I really appreciate your help dear but its not related to my subject i need help for order history page not order info page which comes after order history page/Order list page. I want to show product details like images quantity and all the other info inside each orders.

Let me know if you can help me with that. I am bit close to the solution but stuck in this part only.

Re: Show all products image and name in order history page in opencart 3

Posted: Wed Feb 20, 2019 1:10 am
by xxvirusxx
ok, so you need in Orders history list not Order Info

Why customers need this?

Re: Show all products image and name in order history page in opencart 3

Posted: Wed Feb 20, 2019 1:42 am
by prosenjeet123
xxvirusxx wrote:
Wed Feb 20, 2019 1:10 am
ok, so you need in Orders history list not Order Info

Why customers need this?
Well it's not a good practice users cant just decide by the product name before they click on "View order Details" in my point of view users must see the product image and other few details like images, size what he had ordered in the past before he clicks on any details. Even many Giant Ecom companies follow the same UI practice. Why would they waste users clicks if we can show the details in Order history only.

Re: Show all products image and name in order history page in opencart 3

Posted: Fri Feb 22, 2019 3:51 pm
by prosenjeet123
prosenjeet123 wrote:
Tue Feb 19, 2019 8:37 pm
I want to show product details/get all products images names inside an order in order history, to achieve the same I have inserted my code inside a result loop just like the below code but it is fetching only one product and that same product is visible to each orders.

1.catalog/controller/account/order.php

Code: Select all

public function index() {
...
foreach ($results as $result) {
...

//for product for loop

            $order_info = $this->model_account_order->getOrder($result['order_id']);

            if ($order_info) {
            $this->load->model('catalog/product');
            $this->load->model('tool/upload');



            // Products


            $data['products'] = array();

            $products = $this->model_account_order->getOrderProducts($result['order_id']);

            foreach ($products as $product) {
                $option_data = array();

                $options = $this->model_account_order->getOrderOptions($result['order_id'], $product['order_product_id']);

                foreach ($options as $option) {
                    if ($option['type'] != 'file') {
                        $value = $option['value'];
                    } else {
                        $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

                        if ($upload_info) {
                            $value = $upload_info['name'];
                        } else {
                            $value = '';
                        }
                    }

                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
                    );
                }

                $product_info = $this->model_catalog_product->getProduct($product['product_id']);

                if ($product_info) {
                    $reorder = $this->url->link('account/order/reorder', 'order_id=' . $result['order_id'] . '&order_product_id=' . $product['order_product_id'], true);
                } else {
                    $reorder = '';
                }

                $data['products'][] = array(
                    'name'     => $product['name'],
                    'model'    => $product['model'],
                    'option'   => $option_data,
                    'quantity' => $product['quantity'],
                    'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
                    'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
                    'reorder'  => $reorder,
                    'return'   => $this->url->link('account/return/add', 'order_id=' . $result['order_id'] . '&product_id=' . $product['product_id'], true)
                );

                // Totals
                $data['totals'] = array();

                $totals = $this->model_account_order->getOrderTotals($result['order_id']);

                    foreach ($totals as $total) {
                    $data['totals'][] = array(
                        'title' => $total['title'],
                        'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
                    );
                }




            }

            //end for loop of product
            }
}

2.order-list.twig SCREENSHOT HERE :
Image
3.Front Page( Order History) SCREESHOT :
Image
UPDATE: I got answer from member of dreamvention and he helped me to fix the issue follow the answer here:
https://stackoverflow.com/questions/547 ... redirect=1