簡體   English   中英

在opencart 3的訂單歷史記錄頁面中顯示所有產品圖片和名稱

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

我想在訂單歷史記錄中顯示商品詳細信息/在訂單中獲取所有商品圖片的名稱,以實現相同的目的,我已將我的代碼插入到結果循環中,就像下面的代碼一樣,但是它僅獲取一個商品並且該商品可見每個訂單。

1.catalog /控制器/帳戶/ order.php

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
            }
}
  1. order-list.twig SCREENSHOT在這里:

在此處輸入圖片說明

  1. 首頁(訂購歷史)SCREESHOT:

在此處輸入圖片說明

問題出在你的循環中。 當您將產品附加到$ data ['orders'] ['products']時,您會將產品附加到$ data ['products']

  1. 在您的代碼中重命名變量
    $data['products']

    $order_products
  1. 然后將其添加到訂單數組
    $data['orders'][] = array(
        ...
        'order_products' => $order_products
        ...
    );
  1. 並在樹枝文件中更改for循環
    {% for order_product in order.order_products %}
    <li>{{ order_product.name }}</li>
    {% endfor %}

基本上,我們正在做的是擴展訂單對象以包括產品信息,然后在視圖中顯示它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM