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

在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 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
  • ¥15 如何能达到用ping0.cc检测成这样?如图