我正在使用opencart版本2.0.1.1并且我根据我的要求修改了常见的cart.tpl我的意思是对齐所以在我更改之后如果我将任何产品添加到购物车意味着它将显示成功消息甚至产品正在添加到购物车但是当我点击购物车按钮时它显示“ul”但是在ul里面,li是没有显示的,如果我加载页面意味着它将在购物车中显示产品,否则不显示。
请任何人帮助我。
以下是cart.tpl,
<a id="cart_close_1">X</a>
<div id="cart" class="btn-group btn-block">
<button type="button" data-toggle="dropdown" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-inverse btn-block btn-lg dropdown-toggle animate"><i class="crtIcon animAll"></i><!-- <span id="cart-total"><?php echo $text_items; ?></span> --></button>
<ul class="dropdown-menu pull-right <?php echo $class_cart; ?> " id="remove_cart">
<?php if ($products || $vouchers) { ?>
<li><div class="cart-container cf">
<?php $count=0;
foreach ($products as $product) { $count++;
?>
<div class="qckimg-vd">
<div class="quck-img">
<?php if ($product['thumb']) { ?>
<!-- <img src="image/10-cm-blue-sparklers.jpg" alt="10-cm-blue-sparklers"> -->
<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" /></a>
<?php }?>
</div><!-- quck-img -->
<div class="proqty">
<div class="nobTn">
<button type="button" class="btn-number" data-type="minus" data-field="input-quantity_<?php echo $product['product_id']; ?>" data-price="<?php echo $product['product_id']; ?>">
<input type="hidden" class="min_order_amount" data-value="<?php echo "3400";?>"/>
<span>-</span>
</button>
</div>
<input type="text" name="quantity" min="1" max="100" value="1" size="2" id="input-quantity_<?php echo $product['product_id']; ?>" class="pro_class" data-id="<?php echo $product['product_id']; ?>" maxlength="3" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;">
<div class="nobTn">
<button type="button" class="btn-number" data-type="plus" data-field="input-quantity_<?php echo $product['product_id']; ?>" data-price="<?php echo $product['product_id']; ?>">
<span>+</span>
</button>
</div>
<span id="error" style="color: Red; display: none">Input digits (0 - 9)</span>
<input type="hidden" name="product_id" id="p_id" value="<?php echo $product['product_id']; ?>">
</div>
</div><!-- qckimg-vd -->
<div class="shoping-cart-desc">
<h2><?php echo $product['name']; ?></h2>
<h3><?php echo $product['attribute_value']; ?></h3>
<h4><!-- <span class="qty_total <?php echo "count_".$count;?>" data-count="<?php echo $count;?>"><?php echo $product['quantity']; ?> X </span> --><span class="orgprice count_total" id="or_price_<?php echo $product['product_id']; ?>" data-actprice="<?php echo str_replace( ',', '', $product['price'] ); ?>"><?php echo $product['price']; ?></span></h4>
<!-- <a href="">Remove</a> -->
<a href="javascript:;" onclick="cart.remove('<?php echo $product['key']; ?>');" title="<?php echo $button_remove; ?>">Remove</a>
</div><!-- shoping-cart-desc -->
<?php }?>
</div><!-- cart-container -->
<div class="sub-tot">
<?php $count=0;foreach($products as $product){$count++;?>
<?php } ?>
<?php foreach ($totals as $total) {?>
<?php }?>
<div class="cf">
<h4 class="lft">Subtotal (<?php echo $count;?> item(s))</h4>
<h4 class="rght total_price" data-type="minus plus" data-total="<?php echo str_replace( ',', '', $total['text'] ); ?>"><?php echo $total['text']; ?></h4>
<!-- <h4 class="lft">Shipping</h4>
<h4 class="rght">NA</h4> -->
</div>
<div class="total cf">
<h4 class="lft">Total</h4>
<h4 class="rght total_price"><?php echo $total['text']; ?></h4>
</div>
</div><!-- sub-tot -->
<div class="shp-btns">
<a class="chckout" href="<?php echo $checkout; ?>">Checkout</a>
</div><!-- shp-btns -->
<div class="min-ordr">
<h3>Minimum order amount should be
Rs.3400 to checkout.</h3>
</div><!-- min-ordr -->
</li>
<?php }else{?>
<li style="height:auto;">
<p class="text-center tCeTxt"><?php echo $text_empty; ?></p>
</li>
<?php }?>
</ul>
</div>
js cart功能,
'add': function(product_id, quantity) {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
success: function(json) {
var error_msg = false;
$('.alert, .text-danger').remove();
$('#cart > button').button('reset');
//For Showing Product Stock Error
if (json['error_warning']) {
error_msg = true;
$('#cart_id').parent().before('<div class="alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error_warning'] + '<button type="button" class="close" data-dismiss="modal">×</button></div>');
$('#cart-total').html(json['total']);
}
if (json['redirect'] && error_msg == false) {
location = json['redirect'];
}
if (json['success']) {
$('#cart_id').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="modal">×</button></div>');
$('#cart-total').html(json['total']);
/*$('html, body').animate({ scrollTop: 0 }, 'slow');*/
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
},
控制器,
<?php
class ControllerCommonCart extends Controller {
public function index() {
$this->load->language('common/cart');
// Totals
$this->load->model('extension/extension');
$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_extension_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('total/' . $result['code']);
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}
$sort_order = array();
foreach ($total_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $total_data);
}
$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_shipping'] = $this->language->get('text_shipping');
$data['text_minimum_ord_amount'] = $this->language->get('text_minimum_ord_amount');
$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));
$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) {
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
} else {
$image = '';
}
$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),
'type' => $option['type']
);
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
} else {
$total = false;
}
//For Getting Pieces/Items per box
$product_attribute = $this->model_catalog_product->getSpecificProductAttribute($product['product_id']);
$attribute_value = '';
if($product_attribute) {
$attribute_value = $product_attribute['text'];
}
$data['products'][] = array(
'key' => $product['key'],
'product_id'=> $product['product_id'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
'quantity' => $product['quantity'],
'price' => $price,
'attribute_value'=> $attribute_value,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'])
);
}
}
$data['totals'] = array();
foreach ($total_data as $result) {
$data['totals'][] = array(
'title' => $result['title'],
'text' => $this->currency->format($result['value']),
);
}
$data['cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/cart.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/cart.tpl', $data);
} else {
return $this->load->view('default/template/common/cart.tpl', $data);
}
}
public function info() {
$this->response->setOutput($this->index());
}
}