如何生成产品的“从购物车中删除”URL? (马真托)

发布于 2024-10-30 19:09:37 字数 75 浏览 2 评论 0原文

是否可以为具有自定义功能的产品创建“从购物车中删除”Url,以便我可以将该功能放置在我的自定义块中,从而允许用户从购物车中删除商品...

Is it possible to create "Remove from cart" Url for a product with a custom function, so that i can place that function in my custom block which allows user to remove an item from cart...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

羁绊已千年 2024-11-06 19:09:37

对我有用的是直接访问源代码:

添加:

Mage::getUrl( 'checkout/cart/add', array( 'id' => $item->getId() ) );

编辑:

Mage::getUrl( 'checkout/cart/configure', array( 'id' => $item->getId() ) );

删除:

Mage::getUrl( 'checkout/cart/delete', array( 'id' => $item->getId() ) );

What worked for me is going directly to the source:

add:

Mage::getUrl( 'checkout/cart/add', array( 'id' => $item->getId() ) );

edit:

Mage::getUrl( 'checkout/cart/configure', array( 'id' => $item->getId() ) );

delete:

Mage::getUrl( 'checkout/cart/delete', array( 'id' => $item->getId() ) );
苦笑流年记忆 2024-11-06 19:09:37

如果您检查 app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php 并找到方法: getDeleteUrl() 将提供有关其生成方式的一些见解:

/**
 * Get item delete url
 *
 * @return string
 */
public function getDeleteUrl()
{
    return $this->getUrl(
        'checkout/cart/delete',
        array(
            'id'=>$this->getItem()->getId(),
            Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl()
        )
    );
}

您可以在 template/ 中找到对此的调用checkout/cart/item/default.phtml:

__('删除项目')?>

有了这些信息,您就可以应该能够为购物车创建一个新的控制器操作,以简单地删除购物车索引中产品的特定 ID。

希望这有帮助。

If you examine, app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php and find the method: getDeleteUrl() will offer some insight on how its generated:

/**
 * Get item delete url
 *
 * @return string
 */
public function getDeleteUrl()
{
    return $this->getUrl(
        'checkout/cart/delete',
        array(
            'id'=>$this->getItem()->getId(),
            Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl()
        )
    );
}

You can find the call to this in template/checkout/cart/item/default.phtml:

<td class="a-center"><a href="<?php echo $this->getDeleteUrl()?>" title="<?php echo $this->__('Remove item')?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove item')?></a></td>

With this info you should be able to create a new controller action for the cart to simply remove a specific ID to a product in the cart's index.

Hope this helps.

等风来 2024-11-06 19:09:37

其中 $_item 是一个 Mage_Sales_Model_Quote_Item_Abstract 对象:

$renderer = new Mage_Checkout_Block_Cart_Item_Renderer();
$renderer->setItem($_item);
$renderer->getDeleteUrl();

Where $_item is a Mage_Sales_Model_Quote_Item_Abstract object:

$renderer = new Mage_Checkout_Block_Cart_Item_Renderer();
$renderer->setItem($_item);
$renderer->getDeleteUrl();
卷耳 2024-11-06 19:09:37

组合不同答案后最简单的计算

将其添加到文件的顶部lists.phtml(template/catlog/product)

<?php 
//getting cart count
$currentDelete = array();
$quote = Mage::getSingleton('checkout/session')->getQuote();
    foreach($quote->getAllItems() as $item){
        if($item->getProductId()){
            $currentDelete[$item->getProductId()] =  Mage::getUrl( 'checkout/cart/delete', array( 'id' => $item->getId() ) );
        }
    }
?>

之后

<?php if($_product->isSaleable()): ?>

添加此

       <?php 
            if (isset($currentDelete) and array_key_exists($_product->getId(), $currentDelete)) { ?>
            <div class="curCart">
            <a href=" <?php echo $currentDelete[$_product->getId()]; ?>">Remove</a> 
            </div>
            <?php }?>

The Simplest work out after combining different answers

Add this to the top of file lists.phtml(template/catlog/product)

<?php 
//getting cart count
$currentDelete = array();
$quote = Mage::getSingleton('checkout/session')->getQuote();
    foreach($quote->getAllItems() as $item){
        if($item->getProductId()){
            $currentDelete[$item->getProductId()] =  Mage::getUrl( 'checkout/cart/delete', array( 'id' => $item->getId() ) );
        }
    }
?>

After

<?php if($_product->isSaleable()): ?>

Add this

       <?php 
            if (isset($currentDelete) and array_key_exists($_product->getId(), $currentDelete)) { ?>
            <div class="curCart">
            <a href=" <?php echo $currentDelete[$_product->getId()]; ?>">Remove</a> 
            </div>
            <?php }?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文