我想在订单历史记录中显示商品详细信息/在订单中获取所有商品图片名称,为实现相同的目的,我已将我的代码插入到结果循环中,就像下面的代码一样,但它仅获取一个商品并且该商品相同每个订单都可以看到该产品。
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
}
}
答案 0 :(得分:0)
问题出在您的循环中。当您将产品附加到$ data ['orders'] ['products']
时,就是将产品附加到$ data ['products'] $data['products']
到
$order_products
$data['orders'][] = array(
...
'order_products' => $order_products
...
);
{% for order_product in order.order_products %}
<li>{{ order_product.name }}</li>
{% endfor %}
基本上,我们正在做的是扩展orders对象以包括产品信息,然后将其显示在视图中。