在结帐页面 Opencart:2.3.0.2 中获取页面加载时的产品详细信息

我想在结帐页面的页面加载时获取添加到购物车的产品详细信息。

正如我们在结帐页面中所知,通常有六个下订单步骤,每个步骤的信息都在

<div class="panel-body"></div>

在我们到达那一步之前,它一直是空的。因此,产品详细信息在要获取的最后一步(第 6 步)下。但我想获取我将在右侧显示的产品详细信息

<div classs="col-md-4"> </div>


德玛西亚99
浏览 181回答 1
1回答

一只斗牛犬

理想情况下,您将要为此创建一个 OCMOD,但这超出了回答此问题的范围。由于您正在考虑将“购物车”的内容插入页面,因此您需要从购物车“模块”控制器复制控制器逻辑catalog/controller/common/cart.php并从视图中复制标记catalog/view/theme/default/template/common/cart.tpl(根据您的模板进行更改)。从控制器文件中获取这些行(公共函数 index()):$this->load->language('common/cart');// Totals$this->load->model('extension/extension');$totals = array();$taxes = $this->cart->getTaxes();$total = 0;// Because __call can not keep var references so we put them into an array.$total_data = array(&nbsp; &nbsp; 'totals' => &$totals,&nbsp; &nbsp; 'taxes'&nbsp; => &$taxes,&nbsp; &nbsp; 'total'&nbsp; => &$total);// Display pricesif ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {&nbsp; &nbsp; $sort_order = array();&nbsp; &nbsp; $results = $this->model_extension_extension->getExtensions('total');&nbsp; &nbsp; foreach ($results as $key => $value) {&nbsp; &nbsp; &nbsp; &nbsp; $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');&nbsp; &nbsp; }&nbsp; &nbsp; array_multisort($sort_order, SORT_ASC, $results);&nbsp; &nbsp; foreach ($results as $result) {&nbsp; &nbsp; &nbsp; &nbsp; if ($this->config->get($result['code'] . '_status')) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this->load->model('extension/total/' . $result['code']);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // We have to put the totals in an array so that they pass by reference.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this->{'model_extension_total_' . $result['code']}->getTotal($total_data);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; $sort_order = array();&nbsp; &nbsp; foreach ($totals as $key => $value) {&nbsp; &nbsp; &nbsp; &nbsp; $sort_order[$key] = $value['sort_order'];&nbsp; &nbsp; }&nbsp; &nbsp; array_multisort($sort_order, SORT_ASC, $totals);}$data['text_empty'] = $this->language->get('text_empty');$data['text_cart'] = $this->language->get('text_cart');$data['text_checkout'] = $this->language->get('text_checkout');$data['text_recurring'] = $this->language->get('text_recurring');$data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));$data['text_loading'] = $this->language->get('text_loading');$data['button_remove'] = $this->language->get('button_remove');$this->load->model('tool/image');$this->load->model('tool/upload');$data['products'] = array();foreach ($this->cart->getProducts() as $product) {&nbsp; &nbsp; if ($product['image']) {&nbsp; &nbsp; &nbsp; &nbsp; $image = $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_cart_width'), $this->config->get($this->config->get('config_theme') . '_image_cart_height'));&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; $image = '';&nbsp; &nbsp; }&nbsp; &nbsp; $option_data = array();&nbsp; &nbsp; foreach ($product['option'] as $option) {&nbsp; &nbsp; &nbsp; &nbsp; if ($option['type'] != 'file') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $value = $option['value'];&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($upload_info) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $value = $upload_info['name'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $value = '';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; $option_data[] = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'name'&nbsp; => $option['name'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'type'&nbsp; => $option['type']&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; }&nbsp; &nbsp; // Display prices&nbsp; &nbsp; if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {&nbsp; &nbsp; &nbsp; &nbsp; $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; $price = false;&nbsp; &nbsp; }&nbsp; &nbsp; // Display prices&nbsp; &nbsp; if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {&nbsp; &nbsp; &nbsp; &nbsp; $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']);&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; $total = false;&nbsp; &nbsp; }&nbsp; &nbsp; $data['products'][] = array(&nbsp; &nbsp; &nbsp; &nbsp; 'cart_id'&nbsp; &nbsp;=> $product['cart_id'],&nbsp; &nbsp; &nbsp; &nbsp; 'thumb'&nbsp; &nbsp; &nbsp;=> $image,&nbsp; &nbsp; &nbsp; &nbsp; 'name'&nbsp; &nbsp; &nbsp; => $product['name'],&nbsp; &nbsp; &nbsp; &nbsp; 'model'&nbsp; &nbsp; &nbsp;=> $product['model'],&nbsp; &nbsp; &nbsp; &nbsp; 'option'&nbsp; &nbsp; => $option_data,&nbsp; &nbsp; &nbsp; &nbsp; 'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),&nbsp; &nbsp; &nbsp; &nbsp; 'quantity'&nbsp; => $product['quantity'],&nbsp; &nbsp; &nbsp; &nbsp; 'price'&nbsp; &nbsp; &nbsp;=> $price,&nbsp; &nbsp; &nbsp; &nbsp; 'total'&nbsp; &nbsp; &nbsp;=> $total,&nbsp; &nbsp; &nbsp; &nbsp; 'href'&nbsp; &nbsp; &nbsp; => $this->url->link('product/product', 'product_id=' . $product['product_id'])&nbsp; &nbsp; );}// Gift Voucher$data['vouchers'] = array();if (!empty($this->session->data['vouchers'])) {&nbsp; &nbsp; foreach ($this->session->data['vouchers'] as $key => $voucher) {&nbsp; &nbsp; &nbsp; &nbsp; $data['vouchers'][] = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'key'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=> $key,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'description' => $voucher['description'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'amount'&nbsp; &nbsp; &nbsp; => $this->currency->format($voucher['amount'], $this->session->data['currency'])&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; }}$data['totals'] = array();foreach ($totals as $total) {&nbsp; &nbsp; $data['totals'][] = array(&nbsp; &nbsp; &nbsp; &nbsp; 'title' => $total['title'],&nbsp; &nbsp; &nbsp; &nbsp; 'text'&nbsp; => $this->currency->format($total['value'], $this->session->data['currency']),&nbsp; &nbsp; );}在文件夹中创建一个新文件catalog/controller/common/,调用它products.php并使用以下结构:<?php&nbsp;class ControllerCommonProducts extends Controller {&nbsp; &nbsp; public function index(){&nbsp; &nbsp; &nbsp; &nbsp; //placeholder&nbsp; &nbsp; &nbsp; &nbsp; return $data;&nbsp; &nbsp; }}将复制的文本粘贴到替换该//placeholder行的新文件中。编辑catalog/controller/checkout/checkout.php文件,插入这一行以将我们刚刚创建的控制器中的数据加载到结帐页面视图中: $data['products_view'] = $this->load->controller('common/products');将其插入到这一行的正上方:$this->response->setOutput($this->load->view('checkout/checkout', $data));现在编辑视图catalog/view/theme/default/template/checkout/checkout.tpl,您现在将拥有一个新数组products_view,您可以根据需要在视图上使用它。从数组的 var_dump 开始,以查看您必须使用哪些数据。摘要:我们在这里所做的是复制现有的控制器(1、2 和 3)——不包括将数据加载到视图中的控制器逻辑。然后,我们编辑了我们正在显示数据的页面的控制器的索引操作 (3),并将新控制器 (4) 加载到一个数组中,以便在前端视图 (5) 上使用。
打开App,查看更多内容
随时随地看视频慕课网APP