【问题标题】:SUPEE 7405 and Cannot Remove the Cart ItemSUPEE 7405 无法移除购物车项目
【发布时间】:2016-01-23 14:29:54
【问题描述】:

基本上我在 SUPEE 7405 更新后遇到了这个问题。每当我将某些东西添加到购物车然后单击 AJAX 购物车中的删除项目时,它都会告诉我“无法删除该项目。”

我必须刷新页面,然后才能成功删除该项目。 基本上添加然后立即删除 item=Doesnt 工作。我需要添加,刷新页面(或转到网站的其他页面),然后单击删除。

我注意到补丁被覆盖了 app/code/core/Mage/Checkout/controllers/CartController.php

补丁前的代码

/**
 * Delete shoping cart item action
 */
public function deleteAction()
{
    $id = (int) $this->getRequest()->getParam('id');
    if ($id) {
        try {
            $this->_getCart()->removeItem($id)
              ->save();
        } catch (Exception $e) {
            $this->_getSession()->addError($this->__('Cannot remove the item.'));
            Mage::logException($e);
        }
    }
    $this->_redirectReferer(Mage::getUrl('*/*'));
}

补丁后的代码

  /**
 * Delete shoping cart item action
 */
public function deleteAction()
{
    if ($this->_validateFormKey()) {
        $id = (int)$this->getRequest()->getParam('id');
        if ($id) {
            try {
                $this->_getCart()->removeItem($id)
                    ->save();
            } catch (Exception $e) {
                $this->_getSession()->addError($this->__('Cannot remove the item.'));
                Mage::logException($e);
            }
        }
    } else {
        $this->_getSession()->addError($this->__('Cannot remove the item.'));
    }

    $this->_redirectReferer(Mage::getUrl('*/*'));
}

我的文件中的补丁覆盖了什么导致此问题?

【问题讨论】:

    标签: magento magento-1.7 patch


    【解决方案1】:

    您需要更新购物车商品模板 [design_package/theme]/template/checkout/cart/item/default.phtml

    查找<a href="<?php echo $this->getDeleteUrl() ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Remove Item')) ?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove Item') ?></a>

    替换为

    <a href="<?php echo $this->getDeleteUrl() ?>form_key/<?php echo $formKey = Mage::getSingleton('core/session')->getFormKey();?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Remove Item')) ?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove Item') ?></a>
    

    【讨论】:

    • 感谢您提供可能的解决方案。但它似乎不适用于我的情况,因为我安装了 ajax。我打开了一个不同的主题来解释侧边栏购物车删除按钮面临的问题。 magento.stackexchange.com/questions/103764/…
    【解决方案2】:

    正如您在 deleteAction 函数中看到的那样,SUPEE7405 为购物车删除添加了表单密钥验证,以防止恶意跨站请求。如果您在主题中覆盖了购物车项目模板 (checkout/cart/item/default.phtml),或者正在使用覆盖此模板的主题,则需要对其进行更新以包含 formkey 隐藏输入字段。您可以从base/default/checkout/cart/item/default.phtml 中提取相关更改。

    【讨论】:

    • 您能告诉我确切的表单键/我应该使用哪个代码吗? (我还在学习):)
    • 如果你打开我链接的文件 (base/default/checkout/cart/item/default.phtml) 和你当前主题中的版本,然后比较“删除”按钮,你会注意到 base/default 中的那个有不同的 HTML 结构,使用包含表单键的 onclick 属性。这就是您需要添加到模板版本中以与修补的控制器保持一致的内容。
    • 太好了,我会尝试回复结果:)
    • 我刚试过,我确实看到删除行在 base/default/checkout/cart/item/default.phtml 和 MYTHEME/default/checkout/cart/item/default.phtml 中略有不同.,但出现相同的错误“无法删除该项目。”
    • 基本文件删除操作代码:__('Remove item')?> MYTHEME 文件删除代码:__('de​​lete')?>
    【解决方案3】:

    在我的情况下,编译已启用。所以我意识到编译的文件不兼容或识别新补丁(SUPEE 7405)

    我做了什么?

    1. 删除补丁sh patch_name.sh -R
    2. 禁用编译
    3. 清除 magento 缓存
    4. 再次应用补丁sh patch_name.sh
    5. 再次清除 magento 缓存
    6. 启用编译
    7. 运行编译过程

    希望对你有帮助

    【讨论】:

    • 刚试了,没用,反正我的编译是禁用的。感谢您的想法!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    相关资源
    最近更新 更多