我的Magento 1.7.0.2无法从Ajax购物车中删除商品
我们以https身份运营 检查Chrome“混合内容:页面位于...”
的错误后我检查了Ajax Cart的js文件 我想避免混合ssl 我该怎么办?
function deleteItem(){
$$('a').each(function(el){
if(el.href.search('checkout/cart/delete') != -1 && el.href.search('javascript:ajax_del') == -1){
el.href = 'javascript:ajax_del(\'' + el.href +'\')';
}
if(el.up('.truncated')){
var a = el.up('.truncated');
a.observe('mouseover', function() {
a.down('.truncated_full_value').addClassName('show');
});
a.observe('mouseout', function() {
a.down('.truncated_full_value').removeClassName('show');
});
}
});
}
function ajax_del(url){
var check = $('shopping-cart-table');
if(check){
window.location.href = url;
}else{
var tmp = url.search("checkout/cart/");
var baseurl = url.substr(0,tmp);
var tmp_2 = url.search("/id/")+4;
var tmp_3 = url.search("/uenc/");
var id = url.substr(tmp_2,tmp_3-tmp_2);
var link = baseurl+'ajaxcart/index/delete/id/'+id;
em_box.open();
new Ajax.Request(link, {
onSuccess: function(data) {
var html = data.responseText.evalJSON();
$$('.top_cart .cartqty').each(function (el){
el.innerHTML = html.qty;
});
$$('.block-cart').each(function (el){
var newElement = new Element('div');
newElement.update(html.sidebar);
var div = newElement.select('div')[0];
el.update(div.innerHTML);
});
em_box.close();
deleteItem();
}
});
}
}
答案 0 :(得分:1)
使用默认购物车项目删除按钮创建一个按钮。
<a onclick="removeCartItemAjax('<?php echo $this->getDeleteUrl();?>')" title="<?php echo $this->__('Remove Item') ?>" >Remove Item</a>
现在右边的ajax代码调用删除功能。
<script>
function removeCartItemAjax(url){
url += 'isAjax/1';
url = url.replace("/delete/","/ajaxdelete/");
url = url.replace("checkout/cart","ajax/index");
jQuery('#cartSidebarLoader').show();
try {
jQuery.ajax( {
url : url,
dataType : 'json',
success : function(data) {
window.crtitm=data.cartitem;
jQuery('#cartSidebarLoader').hide();
if(jQuery('#cart-sidebar')){
jQuery('#cart-sidebar').html(data.sidebar);
}
jQuery("#ajax-mini-cart2 .cart-value").html(data.qty);
}
});
} catch (e) {
}
}
</script>
在&#34; ajax / index&#34;中创建一个ajaxdeleteAction()函数。网址。
public function ajaxdeleteAction()
{
$id = (int) $this->getRequest()->getParam('id');
$response = array();
if ($id) {
try {
$this->_getCart()->removeItem($id)
->save();
$response['status'] = 'SUCCESS';
$this->loadLayout();
$toplink = $this->getLayout()->getBlock('top.links')->toHtml();
$sidebar_block = $this->getLayout()->getBlock('cart_sidebar');
Mage::register('referrer_url', $this->_getRefererUrl());
$sidebar = $sidebar_block->toHtml();
} catch (Exception $e) {
$this->_getSession()->addError($this->__('Cannot remove the item.'));
Mage::logException($e);
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
return;
}