dougang6821 2019-02-19 10:53
浏览 146
已采纳

在opencart 3的订单历史记录页面中显示所有产品图片和名称

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

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 HERE :

enter image description here

  1. Front Page( Order History) SCREESHOT :

enter image description here

  • 写回答

1条回答 默认 最新

  • douzhao7445 2019-02-19 15:07
    关注

    The issue is in your loop. You are attaching the product to $data['products'], when you should be attaching it to $data['orders']['products']

    1. in your code rename the variable
        $data['products']
    

    to

        $order_products
    
    1. then add this to the order array
        $data['orders'][] = array(
            ...
            'order_products' => $order_products
            ...
        );
    
    1. and in the twig file change the for loop
        {% for order_product in order.order_products %}
        <li>{{ order_product.name }}</li>
        {% endfor %}
    

    Basically, what we are doing is extending the orders object to include the products info and then we are displaying it in the view.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波