简体   繁体   English

无法从Ajax购物车中删除商品

[英]can not remove items from Ajax cart

My Magento 1.7.0.2 can not remove items from Ajax cart 我的Magento 1.7.0.2无法从Ajax购物车中删除商品

We are operating as https After checking the error of Chrome "Mixed Content: The page at ..." 我们检查了Chrome浏览器“混合内容:位于...的页面”的错误后,以https操作

I checked the js file of Ajax Cart I want to avoid mixed ssl What should I do? 我检查了Ajax购物车的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();
            }
        });
    }

}

Create a button with default cart item delete button. 创建一个带有默认购物车项目删除按钮的按钮。

<a onclick="removeCartItemAjax('<?php echo $this->getDeleteUrl();?>')" title="<?php echo $this->__('Remove Item') ?>" >Remove Item</a>

Now right bellow ajax code to call delete function. 现在对下面的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>

Create a ajaxdeleteAction() function in "ajax/index" url. 在“ ajax / index” URL中创建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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM