详细:opencart多版本后台查看客户添加的购物车

本文档详细介绍了如何通过修改Opencart的后台代码,新增购物车管理功能,包括添加购物车状态字段、修改删除操作为设置状态为已删除、更新相关模型和控制器以显示和过滤购物车内容,以及更新数据库查询以支持这些变化。同时,还提供了语言包和视图文件的修改建议,以完善用户体验。
摘要由CSDN通过智能技术生成

可使用在多版本

本部分很长

小编搞这个研究了有一两天了才搞出来(后台的购物车没有筛选)

在这里插入图片描述

把admin/view/template/catalogproduct-list.twig 文件复制粘贴在上图文件夹里,并修改名称为shoppingcart.twig

打开:upload\admin\language\zh-cn\common\column_left.php 在底部添加语言

$_['text_dingdan'] = '購物車管理';
$_['text_gwc'] = '購物車列表';

打开:upload\admin\controller\common\column_left.php 在合适的地方添加下面语句

           // 购物车 shopping 
           $data['menus'][] = array(
   			'id'       => 'menu-shoppingcart',
   			'icon'	   => 'fa-shopping-bag',
   			'name'	   => $this->language->get('text_dingdan'),
   			'href'     => $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token']),
   			'children' => array()
   		);
   		

复制粘贴:复制upload\admin\controller\catalog\product.php 文件,放在下图位置,并修改类名
在这里插入图片描述
修改shoppingcart.php的类名

       class ControllerCommonShoppingcart extends Controller {

选择权限
在这里插入图片描述
可看到单页面在这里插入图片描述

接下来,开始代码了,接收来自代码人的恶意吧
数据库中 cart表添加两个字段,名为status 0为默认,1为删除(客户删除购物车内容),line_id

打开upload\system\library\cart\cart.php

//1.找到此代码,并屏蔽

$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");

//2.修改方法
        public function remove($cart_id)
       {
               // 		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
               $this->db->query("UPDATE " . DB_PREFIX . "cart set status = 1 WHERE cart_id = '" . (int)$cart_id . "' AND api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");


               $this->data = array();
       }
//3.修改方法 getProducts() ,添加条件and status = 0
$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'AND status = 0");

//4.修改add()方法
       public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0)
       {
             //添加查询条件 and  status = 0
               $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'and status = 0");
            
               if (!$query->row['total']) {
                   
                       $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()");

               } else {
                       $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'");
               }

               $this->data = array();
       }
//5.添加方法
      public function getCartlist($data = array())
       {
           
                if (!$this->data) {
                     
                        $cart_query = "SELECT * FROM " . DB_PREFIX . "cart";
               
                       $sort_data = array(
                               'name',
                               'product_id',
                               'date_added',
                               'cart_id',
                               'quantity',
                               'status',
                               'sort_order'
                       );
               
                       if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
                               $cart_query .= " ORDER BY " . $data['sort'];
                       } else {
                               $cart_query .= " ORDER BY quantity";
                       }
               
                       if (isset($data['order']) && ($data['order'] == 'DESC')) {
                               $cart_query .= " DESC";
                       } else {
                               $cart_query .= " ASC";
                       }
               
                       if (isset($data['start']) || isset($data['limit'])) {
                               if ($data['start'] < 0) {
                                       $data['start'] = 0;
                               }
               
                               if ($data['limit'] < 1) {
                                       $data['limit'] = 20;
                               }
               
                               $cart_query .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
                       }
                       
                       $cart_query = $this->db->query($cart_query);

                       foreach ($cart_query->rows as $cart) {
                               $stock = true;

                               $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store p2s LEFT JOIN " . DB_PREFIX . "product p ON (p2s.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2s.product_id = '" . (int)$cart['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

                               if ($product_query->num_rows && ($cart['quantity'] > 0)) {
                                       $option_price = 0;
                                       $option_points = 0;
                                       $option_weight = 0;

                                       $option_data = array();

                                       foreach (json_decode($cart['option']) as $product_option_id => $value) {
                                               $option_query = $this->db->query("SELECT po.product_option_id, po.option_id, od.name, o.type FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_option_id = '" . (int)$product_option_id . "' AND po.product_id = '" . (int)$cart['product_id'] . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "'");

                                               if ($option_query->num_rows) {
                                                       if ($option_query->row['type'] == 'select' || $option_query->row['type'] == 'radio') {
                                                               $option_value_query = $this->db->query("SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = '" . (int)$value . "' AND pov.product_option_id = '" . (int)$product_option_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");

                                                               if ($option_value_query->num_rows) {
                                                                       if ($option_value_query->row['price_prefix'] == '+') {
                                                                               $option_price += $option_value_query->row['price'];
                                                                       } elseif ($option_value_query->row['price_prefix'] == '-') {
                                                                               $option_price -= $option_value_query->row['price'];
                                                                       }

                                                                       if ($option_value_query->row['points_prefix'] == '+') {
                                                                               $option_points += $option_value_query->row['points'];
                                                                       } elseif ($option_value_query->row['points_prefix'] == '-') {
                                                                               $option_points -= $option_value_query->row['points'];
                                                                       }

                                                                       if ($option_value_query->row['weight_prefix'] == '+') {
                                                                               $option_weight += $option_value_query->row['weight'];
                                                                       } elseif ($option_value_query->row['weight_prefix'] == '-') {
                                                                               $option_weight -= $option_value_query->row['weight'];
                                                                       }

                                                                       if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $cart['quantity']))) {
                                                                               $stock = false;
                                                                       }

                                                                       $option_data[] = array(
                                                                               'product_option_id'       => $product_option_id,
                                                                               'product_option_value_id' => $value,
                                                                               'option_id'               => $option_query->row['option_id'],
                                                                               'option_value_id'         => $option_value_query->row['option_value_id'],
                                                                               'name'                    => $option_query->row['name'],
                                                                               'value'                   => $option_value_query->row['name'],
                                                                               'type'                    => $option_query->row['type'],
                                                                               'quantity'                => $option_value_query->row['quantity'],
                                                                               'subtract'                => $option_value_query->row['subtract'],
                                                                               'price'                   => $option_value_query->row['price'],
                                                                               'price_prefix'            => $option_value_query->row['price_prefix'],
                                                                               'points'                  => $option_value_query->row['points'],
                                                                               'points_prefix'           => $option_value_query->row['points_prefix'],
                                                                               'weight'                  => $option_value_query->row['weight'],
                                                                               'weight_prefix'           => $option_value_query->row['weight_prefix']
                                                                       );
                                                               }
                                                       } elseif ($option_query->row['type'] == 'checkbox' && is_array($value)) {
                                                               foreach ($value as $product_option_value_id) {
                                                                       $option_value_query = $this->db->query("SELECT pov.option_value_id, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix, ovd.name FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (pov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_option_id = '" . (int)$product_option_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");

                                                                       if ($option_value_query->num_rows) {
                                                                               if ($option_value_query->row['price_prefix'] == '+') {
                                                                                       $option_price += $option_value_query->row['price'];
                                                                               } elseif ($option_value_query->row['price_prefix'] == '-') {
                                                                                       $option_price -= $option_value_query->row['price'];
                                                                               }

                                                                               if ($option_value_query->row['points_prefix'] == '+') {
                                                                                       $option_points += $option_value_query->row['points'];
                                                                               } elseif ($option_value_query->row['points_prefix'] == '-') {
                                                                                       $option_points -= $option_value_query->row['points'];
                                                                               }

                                                                               if ($option_value_query->row['weight_prefix'] == '+') {
                                                                                       $option_weight += $option_value_query->row['weight'];
                                                                               } elseif ($option_value_query->row['weight_prefix'] == '-') {
                                                                                       $option_weight -= $option_value_query->row['weight'];
                                                                               }

                                                                               if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $cart['quantity']))) {
                                                                                       $stock = false;
                                                                               }

                                                                               $option_data[] = array(
                                                                                       'product_option_id'       => $product_option_id,
                                                                                       'product_option_value_id' => $product_option_value_id,
                                                                                       'option_id'               => $option_query->row['option_id'],
                                                                                       'option_value_id'         => $option_value_query->row['option_value_id'],
                                                                                       'name'                    => $option_query->row['name'],
                                                                                       'value'                   => $option_value_query->row['name'],
                                                                                       'type'                    => $option_query->row['type'],
                                                                                       'quantity'                => $option_value_query->row['quantity'],
                                                                                       'subtract'                => $option_value_query->row['subtract'],
                                                                                       'price'                   => $option_value_query->row['price'],
                                                                                       'price_prefix'            => $option_value_query->row['price_prefix'],
                                                                                       'points'                  => $option_value_query->row['points'],
                                                                                       'points_prefix'           => $option_value_query->row['points_prefix'],
                                                                                       'weight'                  => $option_value_query->row['weight'],
                                                                                       'weight_prefix'           => $option_value_query->row['weight_prefix']
                                                                               );
                                                                       }
                                                               }
                                                       } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') {
                                                               $option_data[] = array(
                                                                       'product_option_id'       => $product_option_id,
                                                                       'product_option_value_id' => '',
                                                                       'option_id'               => $option_query->row['option_id'],
                                                                       'option_value_id'         => '',
                                                                       'name'                    => $option_query->row['name'],
                                                                       'value'                   => $value,
                                                                       'type'                    => $option_query->row['type'],
                                                                       'quantity'                => '',
                                                                       'subtract'                => '',
                                                                       'price'                   => '',
                                                                       'price_prefix'            => '',
                                                                       'points'                  => '',
                                                                       'points_prefix'           => '',
                                                                       'weight'                  => '',
                                                                       'weight_prefix'           => ''
                                                               );
                                                       }
                                               }
                                       }

                                       $price = $product_query->row['price'];

                                       // Product Discounts
                                       $discount_quantity = 0;

                                       foreach ($cart_query->rows as $cart_2) {
                                               if ($cart_2['product_id'] == $cart['product_id']) {
                                                       $discount_quantity += $cart_2['quantity'];
                                               }
                                       }

                                       $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");

                                       if ($product_discount_query->num_rows) {
                                               $price = $product_discount_query->row['price'];
                                       }

                                       // Product Specials
                                       $product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1");

                                       if ($product_special_query->num_rows) {
                                               $price = $product_special_query->row['price'];
                                       }

                                       // Reward Points
                                       $product_reward_query = $this->db->query("SELECT points FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'");

                                       if ($product_reward_query->num_rows) {
                                               $reward = $product_reward_query->row['points'];
                                       } else {
                                               $reward = 0;
                                       }

                                       // Downloads
                                       $download_data = array();

                                       $download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download p2d LEFT JOIN " . DB_PREFIX . "download d ON (p2d.download_id = d.download_id) LEFT JOIN " . DB_PREFIX . "download_description dd ON (d.download_id = dd.download_id) WHERE p2d.product_id = '" . (int)$cart['product_id'] . "' AND dd.language_id = '" . (int)$this->config->get('config_language_id') . "'");

                                       foreach ($download_query->rows as $download) {
                                               $download_data[] = array(
                                                       'download_id' => $download['download_id'],
                                                       'name'        => $download['name'],
                                                       'filename'    => $download['filename'],
                                                       'mask'        => $download['mask']
                                               );
                                       }

                                       // Stock
                                       if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) {
                                               $stock = false;
                                       }

                                       $recurring_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "recurring r LEFT JOIN " . DB_PREFIX . "product_recurring pr ON (r.recurring_id = pr.recurring_id) LEFT JOIN " . DB_PREFIX . "recurring_description rd ON (r.recurring_id = rd.recurring_id) WHERE r.recurring_id = '" . (int)$cart['recurring_id'] . "' AND pr.product_id = '" . (int)$cart['product_id'] . "' AND rd.language_id = " . (int)$this->config->get('config_language_id') . " AND r.status = 1 AND pr.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'");

                                       if ($recurring_query->num_rows) {
                                               $recurring = array(
                                                       'recurring_id'    => $cart['recurring_id'],
                                                       'name'            => $recurring_query->row['name'],
                                                       'frequency'       => $recurring_query->row['frequency'],
                                                       'price'           => $recurring_query->row['price'],
                                                       'cycle'           => $recurring_query->row['cycle'],
                                                       'duration'        => $recurring_query->row['duration'],
                                                       'trial'           => $recurring_query->row['trial_status'],
                                                       'trial_frequency' => $recurring_query->row['trial_frequency'],
                                                       'trial_price'     => $recurring_query->row['trial_price'],
                                                       'trial_cycle'     => $recurring_query->row['trial_cycle'],
                                                       'trial_duration'  => $recurring_query->row['trial_duration']
                                               );
                                       } else {
                                               $recurring = false;
                                       }

                                       $this->data[] = array(
                                               'cart_id'         => $cart['cart_id'],
                                               'status'         => $cart['status'],
                                               'date_added'         => $cart['date_added'],
                                               'product_id'      => $product_query->row['product_id'],
                                               'name'            => $product_query->row['name'],
                                               'model'           => $product_query->row['model'],
                                               'shipping'        => $product_query->row['shipping'],
                                               'image'           => $product_query->row['image'],
                                               'option'          => $option_data,
                                               'download'        => $download_data,
                                               'quantity'        => $cart['quantity'],
                                               'minimum'         => $product_query->row['minimum'],
                                               'subtract'        => $product_query->row['subtract'],
                                               'stock'           => $stock,
                                               'price'           => ($price + $option_price),
                                               'total'           => ($price + $option_price) * $cart['quantity'],
                                               'reward'          => $reward * $cart['quantity'],
                                               'points'          => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $cart['quantity'] : 0),
                                               'tax_class_id'    => $product_query->row['tax_class_id'],
                                               'weight'          => ($product_query->row['weight'] + $option_weight) * $cart['quantity'],
                                               'weight_class_id' => $product_query->row['weight_class_id'],
                                               'length'          => $product_query->row['length'],
                                               'width'           => $product_query->row['width'],
                                               'height'          => $product_query->row['height'],
                                               'length_class_id' => $product_query->row['length_class_id'],
                                               'recurring'       => $recurring
                                       );
                               } else {
                                       $this->remove($cart['cart_id']);
                               }
                       }
               }

               return $this->data;
       }

打开模型 upload\admin\model\catalog\product.php

//添加方法
   // 购物车总数
   public function getTotalCart($data = array()) {
   	$sql = "SELECT COUNT(DISTINCT cart_id) AS total FROM " . DB_PREFIX . "cart" ;

   	$query = $this->db->query($sql);

   	return $query->row['total'];
   }

打开控制器 upload\admin\controller\common\shopping.php,编辑代码(现成的代码,可复制)

<?php
class ControllerCommonShoppingcart extends Controller
{
  public function index()
  {

  	$this->load->language('common/shoppingcart');

  	$this->document->setTitle($this->language->get('heading_title'));

  	$this->load->model('tool/image');
  	$this->load->model('tool/upload');
  	$this->load->model('catalog/product');


  	$data['products'] = array();

  	$this->getlist();
  }

  public function getlist()
  {
  	$this->document->addScript('view/javascript/jquery/switch/bootstrap-switch.min.js');


  	if (isset($this->request->get['filter_name'])) {
  		$filter_name = $this->request->get['filter_name'];
  	} else {
  		$filter_name = '';
  	}

  	if (isset($this->request->get['filter_model'])) {
  		$filter_model = $this->request->get['filter_model'];
  	} else {
  		$filter_model = '';
  	}

  	if (isset($this->request->get['date_added'])) {
  		$filter_price = $this->request->get['date_added'];
  	} else {
  		$filter_price = '';
  	}

  	if (isset($this->request->get['filter_quantity'])) {
  		$filter_quantity = $this->request->get['filter_quantity'];
  	} else {
  		$filter_quantity = '';
  	}

  	if (isset($this->request->get['filter_status'])) {
  		$filter_status = $this->request->get['filter_status'];
  	} else {
  		$filter_status = '';
  	}

  	if (isset($this->request->get['filter_category'])) {
  		$filter_category = $this->request->get['filter_category'];
  	} else {
  		$filter_category = '';
  	}

  	if (isset($this->request->get['filter_image'])) {
  		$filter_image = $this->request->get['filter_image'];
  	} else {
  		$filter_image = '';
  	}

  	if (isset($this->request->get['sort'])) {
  		$sort = $this->request->get['sort'];
  	} else {
  		$sort = 'pd.name';
  	}

  	if (isset($this->request->get['order'])) {
  		$order = $this->request->get['order'];
  	} else {
  		$order = 'ASC';
  	}

  	if (isset($this->request->get['page'])) {
  		$page = $this->request->get['page'];
  	} else {
  		$page = 1;
  	}

  	$url = '';

  	if (isset($this->request->get['filter_name'])) {
  		$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  	}

  	if (isset($this->request->get['filter_model'])) {
  		$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  	}

  	if (isset($this->request->get['date_added'])) {
  		$url .= '&filter_price=' . $this->request->get['date_added'];
  	}

  	if (isset($this->request->get['filter_quantity'])) {
  		$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  	}

  	if (isset($this->request->get['filter_status'])) {
  		$url .= '&filter_status=' . $this->request->get['filter_status'];
  	}

  	if (isset($this->request->get['filter_category'])) {
  		$url .= '&filter_category=' . $this->request->get['filter_category'];
  	}

  	if (isset($this->request->get['filter_image'])) {
  		$url .= '&filter_image=' . $this->request->get['filter_image'];
  	}

  	if (isset($this->request->get['sort'])) {
  		$url .= '&sort=' . $this->request->get['sort'];
  	}

  	if (isset($this->request->get['order'])) {
  		$url .= '&order=' . $this->request->get['order'];
  	}

  	if (isset($this->request->get['page'])) {
  		$url .= '&page=' . $this->request->get['page'];
  	}


  	$filter_data = array(
  		'filter_name'	  => $filter_name,
  		
  		'date_added'	  => $filter_price,
  		'filter_quantity' => $filter_quantity,
  	
  		'filter_status'   => $filter_status,
  		'filter_image'    => $filter_image,
  		'sort'            => $sort,
  		'order'           => $order,
  		'start'           => ($page - 1) * $this->config->get('config_limit_admin'),
  		'limit'           => $this->config->get('config_limit_admin')
  	);

//获取总数
  	$product_total = $this->model_catalog_product->getTotalCart($filter_data);

  	//获取购物车里面的内容并输出
  	$products = $this->cart->getCartlist($filter_data);

  	foreach ($products as $product) {

  		$image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));

  		$option_data = array();

  		foreach ($product['option'] 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)
  			);
  		}

  		// Display prices
  		if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
  			$unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));

  			$price = $this->currency->format($unit_price, $this->session->data['currency']);
  			$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
  		} else {
  			$price = false;
  			$total = false;
  		}


  		$data['products'][] = array(
  			'cart_id'   => $product['cart_id'],
  			'status'   => $product['status'],
  			'date_added'   => $product['date_added'],
  			'thumb'     => $image,
  			'name'      => $product['name'],
  			'model'     => $product['model'],
  			'option'    => $option_data,
  			'quantity'  => $product['quantity'],
  			'stock'     => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
  			'reward'    => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
  			'price'     => $price,
  			'total'     => $total,
  			'href'      => $this->url->link('common/shoppingcart', 'cart_id=' . $product['cart_id'])
  		);
  	}

  	$data['user_token'] = $this->session->data['user_token'];

  	if (isset($this->error['warning'])) {
  		$data['error_warning'] = $this->error['warning'];
  	} else {
  		$data['error_warning'] = '';
  	}

  	if (isset($this->session->data['success'])) {
  		$data['success'] = $this->session->data['success'];

  		unset($this->session->data['success']);
  	} else {
  		$data['success'] = '';
  	}

  	if (isset($this->request->post['selected'])) {
  		$data['selected'] = (array)$this->request->post['selected'];
  	} else {
  		$data['selected'] = array();
  	}

  	$url = '';

  	if (isset($this->request->get['filter_name'])) {
  		$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  	}

  	if (isset($this->request->get['filter_model'])) {
  		$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
  	}

  	if (isset($this->request->get['filter_quantity'])) {
  		$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  	}

  	if (isset($this->request->get['filter_status'])) {
  		$url .= '&filter_status=' . $this->request->get['filter_status'];
  	}

  	if (isset($this->request->get['filter_image'])) {
  		$url .= '&filter_image=' . $this->request->get['filter_image'];
  	}

  	if ($order == 'ASC') {
  		$url .= '&order=DESC';
  	} else {
  		$url .= '&order=ASC';
  	}

  	if (isset($this->request->get['page'])) {
  		$url .= '&page=' . $this->request->get['page'];
  	}

  	$data['sort_id'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=cart_id' . $url);
  	$data['sort_name'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_name' . $url);
  	$data['sort_status'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url);
  	$data['sort_quantity'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_quantity' . $url);
  	$data['sort_date_added'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_date_added' . $url);
  	$data['sort_model'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_model' . $url);
  	$data['sort_price'] = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_price' . $url);

  	$url = '';

  	if (isset($this->request->get['filter_name'])) {
  		$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
  	}

  	if (isset($this->request->get['filter_quantity'])) {
  		$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  	}

  	if (isset($this->request->get['filter_status'])) {
  		$url .= '&filter_status=' . $this->request->get['filter_status'];
  	}

  	if (isset($this->request->get['filter_image'])) {
  		$url .= '&filter_image=' . $this->request->get['filter_image'];
  	}
  
  	$pagination = new Pagination();
  	$pagination->total = $product_total;
  	$pagination->page = $page;
  	$pagination->limit = $this->config->get('config_limit_admin');
  	$pagination->url = $this->url->link('common/shoppingcart', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}');

  	$data['pagination'] = $pagination->render();

  	$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin')));

  	$data['filter_name'] = $filter_name;
  	$data['filter_model'] = $filter_model;
  	$data['date_added'] = $filter_price;
  	$data['filter_quantity'] = $filter_quantity;
  	$data['filter_status'] = $filter_status;
  	$data['filter_image'] = $filter_image;
  	$data['filter_category'] = $filter_category;

  	$data['sort'] = $sort;
  	$data['order'] = $order;

  	$data['header'] = $this->load->controller('common/header');
  	$data['column_left'] = $this->load->controller('common/column_left');
  	$data['footer'] = $this->load->controller('common/footer');
  	
  	$this->response->setOutput($this->load->view('common/shoppingcart', $data));
  }
}

打开语言包,在common里面添加shoppingcart.php语言包,并编辑

// Heading
$_['heading_title']              = '购物车管理';
$_['column_id']                  = 'cart_ID';
$_['column_name']                = '商品名稱';
$_['column_model']               = '商品型號';
$_['column_image']               = '圖片';
$_['column_price']               = '價格';
$_['column_quantity']            = '數量';
$_['column_status']              = '狀態';
$_['column_action']              = '时间';

最后,修改common\shoppingcart.twig的视图(可自己修改要什么内容,不要什么内容)

{{ header }}{{ column_left }}
<div id="content">
<div class="page-header">
  <div class="container-fluid">
    <div class="pull-right hidden">
      <button type="button" data-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-product').toggleClass('hidden-sm hidden-xs');" class="btn btn-default hidden-md hidden-lg"><i class="fa fa-filter"></i></button>
      <a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
      <button type="submit" form="form-product" formaction="{{ copy }}" data-toggle="tooltip" title="{{ button_copy }}" class="btn btn-default"><i class="fa fa-copy"></i></button>
      <button type="button" form="form-product" formaction="{{ delete }}" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-product').submit() : false;"><i class="fa fa-trash-o"></i></button>
    </div>
    <h1>{{ heading_title }}</h1>
    <ul class="breadcrumb">
      {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
      {% endfor %}
    </ul>
  </div>
</div>
<div class="container-fluid">{% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
  {% endif %}
  {% if success %}
    <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
  {% endif %}
  <div class="row">
    <div id="filter-product" class="col-sm-12 hidden-sm hidden-xs">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title"><i class="fa fa-filter"></i> {{ text_filter }}</h3>
        </div>

      </div>
    </div>
    <div class="col-sm-12">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title"><i class="fa fa-list"></i> {{ text_list }}</h3>
        </div>
        <div class="panel-body">
          <form action="{{ delete }}" method="post" enctype="multipart/form-data" id="form-product">
            <div class="table-responsive">
              <table class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').trigger('click');"/></td>
                    <td class="text-left">{% if sort == 'product_id' %}<a href="{{ sort_id }}" class="{{ order|lower }}">{{ column_id }}</a>{% else %}<a href="{{ sort_id }}">{{ column_id }}</a> {% endif %}</td>
                    <td class="text-center">{{ column_image }}</td>
                    <td class="text-left">{% if sort == 'name' %}<a href="{{ sort_name }}" class="{{ order|lower }}">{{ column_name }}</a>{% else %}<a href="{{ sort_name }}">{{ column_name }}</a> {% endif %}</td>
                    <td class="text-left">{% if sort == 'model' %}<a href="{{ sort_model }}" class="{{ order|lower }}">{{ column_model }}</a>{% else %}<a href="{{ sort_model }}">{{ column_model }}</a> {% endif %}</td>
                    <td class="text-right">{% if sort == 'price' %}<a href="{{ sort_price }}" class="{{ order|lower }}">{{ column_price }}</a>{% else %}<a href="{{ sort_price }}">{{ column_price }}</a> {% endif %}</td>
                    <td class="text-right">{% if sort == 'quantity' %}<a href="{{ sort_quantity }}" class="{{ order|lower }}">{{ column_quantity }}</a>{% else %}<a href="{{ sort_quantity }}">{{ column_quantity }}</a> {% endif %}</td>
                    <td class="text-right">{% if sort == 'date_added' %}<a href="{{ sort_date_added }}" class="{{ order|lower }}">{{ column_quantity }}</a>{% else %}<a href="{{ sort_date_added }}">{{ column_action }}</a> {% endif %}</td>
          
                  </tr>
                </thead>
                <tbody>
                  {% if products %}
                    {% for product in products %}
                      <tr>
                       
                        <td class="text-center">{% if product.cart_id in selected %}
                            <input type="checkbox" name="selected[]" value="{{ product.cart_id }}" checked="checked"/>
                          {% else %}
                            <input type="checkbox" name="selected[]" value="{{ product.cart_id }}"/>
                          {% endif %}</td> 
                          <td class="text-center">
                          <span>{{ product.cart_id }}</span>
                        </td>
                        <td class="text-center">{% if product.thumb %}<img src="{{ product.thumb }}" alt="{{ product.name }}" class="img-thumbnail"/>{% else %}<span class="img-thumbnail list"><i class="fa fa-camera fa-2x"></i></span>{% endif %}</td>
                        <td class="text-left">{{ product.name }}</td>
                        <td class="text-left">{{ product.model }}</td>
                        <td class="text-right">{% if product.special %}<span style="text-decoration: line-through;">{{ product.price }}</span>
                            <br/>
                            <div class="text-danger">{{ product.special }}</div>
                          {% else %}
                            {{ product.price }}
                          {% endif %}</td>
                        <td class="text-right">{% if product.quantity <= 0 %}<span class="label label-warning">{{ product.quantity }}</span>{% elseif product.quantity <= 5 %}<span class="label label-danger">{{ product.quantity }}</span>{% else %}<span class="label label-success">{{ product.quantity }}</span>{% endif %}</td>
                         
                        <td class="text-right">{{ product.date_added  }}
                        </td>
                      
                      </tr>
                    {% endfor %}
                  {% else %}
                    <tr>
                      <td class="text-center" colspan="9">{{ text_no_results }}</td>
                    </tr>
                  {% endif %}
                </tbody>
              </table>
            </div>
          </form>
          <div class="row">
            <div class="col-sm-6 text-left">{{ pagination }}</div>
            <div class="col-sm-6 text-right">{{ results }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
<script type="text/javascript"><!--
$('#button-filter').on('click', function() {
  var url = '';

  var filter_name = $('input[name=\'filter_name\']').val();

  if (filter_name) {
  	url += '&filter_name=' + encodeURIComponent(filter_name);
  }

  var filter_model = $('input[name=\'filter_model\']').val();

  if (filter_model) {
  	url += '&filter_model=' + encodeURIComponent(filter_model);
  }

  var filter_price = $('input[name=\'date_added\']').val();

  if (filter_price) {
  	url += '&date_added=' + encodeURIComponent(filter_price);
  }

  var filter_quantity = $('input[name=\'filter_quantity\']').val();

  if (filter_quantity) {
  	url += '&filter_quantity=' + encodeURIComponent(filter_quantity);
  }

  var filter_status = $('select[name=\'filter_status\']').val();

if (filter_status !== '') {
  url += '&filter_status=' + encodeURIComponent(filter_status);
}

var filter_category = $('select[name=\'filter_category\']').val();

if (filter_category !== '') {
  url += '&filter_category=' + encodeURIComponent(filter_category);
}

var filter_image = $('select[name=\'filter_image\']').val();

  if (filter_image !== '') {
  	url += '&filter_image=' + encodeURIComponent(filter_image);
  }

  location = 'index.php?route=common/shoppingcart&user_token={{ user_token }}' + url;
});
//--></script>
<script type="text/javascript"><!--
// IE and Edge fix!
$('button[form=\'form-product\']').on('click', function(e) {
  $('#form-product').attr('action', $(this).attr('formaction'));
});

$('input[name=\'filter_name\']').autocomplete({
  'source': function(request, response) {
  	$.ajax({
  		url: 'index.php?route=common/shoppingcart&user_token={{ user_token }}&filter_name=' + encodeURIComponent(request),
  		dataType: 'json',
  		success: function(json) {
  			response($.map(json, function(item) {
  				return {
  					label: item['name'],
  					value: item['product_id']
  				}
  			}));
  		}
  	});
  },
  'select': function(item) {
  	$('input[name=\'filter_name\']').val(item['label']);
  }
});

$('input[name=\'filter_model\']').autocomplete({
  'source': function(request, response) {
  	$.ajax({
  		url: 'index.php?route=common/shoppingcart&user_token={{ user_token }}&filter_model=' + encodeURIComponent(request),
  		dataType: 'json',
  		success: function(json) {
  			response($.map(json, function(item) {
  				return {
  					label: item['model'],
  					value: item['product_id']
  				}
  			}));
  		}
  	});
  },
  'select': function(item) {
  	$('input[name=\'filter_model\']').val(item['label']);
  }
});
/*
$("[name='product-status-toggle']").bootstrapSwitch({
onText: '{{ text_enabled }}',
offText: '{{ text_disabled }}',
labelText: '{{ entry_status }}',
size: 'mini',
});

$('input[name="product-status-toggle"]').on('switchChange.bootstrapSwitch', function(event, state) {
var switcher = $(this);
$.ajax({
  url: 'index.php?route=ccommon/shoppingcart&user_token={{ user_token }}&product_id=' + $(this).data('id') + '&status=' + (state ? 1 : 0),
  dataType: 'json',
  beforeSend: function () {
    switcher.bootstrapSwitch('toggleReadonly', true);
  },
  success: function (json) {
    switcher.bootstrapSwitch('toggleReadonly', false);
    if (json['status'] !== 1) {
      switcher.bootstrapSwitch('state', !state, true);
    }
  },
  error: function () {
    switcher.bootstrapSwitch('toggleReadonly', false);
    switcher.bootstrapSwitch('state', !state, true);
  }
});
});*/
//--></script>
{{ footer }}

至此,完结
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_42456392

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值