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

问题描述 投票:0回答:1

我想在订单历史记录中显示产品详细信息/获取所有产品图片名称,以实现相同我在代码循环中插入我的代码,就像下面的代码一样,但它只获取一个产品,同一产品是可见的每个订单。

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屏幕截图:

enter image description here

  1. 首页(订单历史)SCREENSHOT:

enter image description here

php opencart opencart-3
1个回答
0
投票

问题出在你的循环中。您将产品附加到$ data ['products'],当您将其附加到$ data ['orders'] ['products']时

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

    $order_products
  1. 然后将其添加到订单数组
    $data['orders'][] = array(
        ...
        'order_products' => $order_products
        ...
    );
  1. 并在twig文件中更改for循环
    {% for order_product in order.order_products %}
    <li>{{ order_product.name }}</li>
    {% endfor %}

基本上,我们正在做的是扩展订单对象以包含产品信息,然后我们在视图中显示它。

© www.soinside.com 2019 - 2024. All rights reserved.