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



我的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();
            }
        });
    }
}

使用默认购物车项目删除按钮创建按钮。

<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>

在 "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;
}

最新更新