如何获取网址以从Magento中的购物车中删除产品? [英] How to get url to remove product from cart in Magento?

查看:58
本文介绍了如何获取网址以从Magento中的购物车中删除产品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了default/template/checkout/cart.html并找到了以下代码:

I looked at default/template/checkout/cart.html and found this code:

        <?php foreach($this->getItems() as $_item): ?>
            <?php echo $this->getItemHtml($_item) ?>
        <?php endforeach ?>

但是它返回的不仅仅是我所需要的.有什么方法可以只调用url从购物车中删除产品?还是要在购物车上获取产品的ID? (因为在商店不一样)

But it returns more than all I need. Is some way to just call the url to remove the product from the cart? Or to get the product's id at cart? (since it is not the same at the store)

推荐答案

似乎这些问题是我再次提出的&再次(大约14个月后).现在需要清除一些基本知识.

It seems that these are the questions, which I asked again & again (some 14 months back). Some basics need to be cleared now.

在Checkout购物车中,主要实体是"报价"(其类别为"Mage_Sales_Model_Quote"),并且与"目录产品"实体(其类别为"Mage_Catalog_Model_Product").因此,产品具有自己的唯一(数字)ID,但是将它们添加到购物车后,它们的ID在购物车"页面中不再相关(产品URL除外,因为用户可能要查看产品详细信息)再次翻页).

In Checkout Cart, the main entity is the "Quote" (whose class is "Mage_Sales_Model_Quote") and it is not at all related to the "Catalog Product" entity (whose class is "Mage_Catalog_Model_Product"). So, products have their own unique (numeric) IDs, but when they get added to the Shopping Cart, their IDs are no more relevant in the Shopping Cart page (except for the Product URL, since the user may want to view the Product details page again).

在结帐购物车"页面中,可用的ID特别是其中添加的每个项目的报价项目ID,并且结帐购物车本身具有报价ID,这是在此期间添加到购物车的所有项目的父项特定的结帐会话.

In the Checkout Cart page, the IDs available are specifically the Quote Item IDs for each of the items added there, and the Checkout Cart itself has a Quote ID, which is the parent of all the items added to the Cart during that particular Checkout Session.

此报价详细信息可以在数据库表"sales_flat_quote"中找到,其项目可以在"sales_flat_quote_items"中找到.

This Quote details can be found in the database table "sales_flat_quote", and its items can be found in "sales_flat_quote_items".

现在回到问题所在,您正在查看的视图页面是"default/template/checkout/cart.phtml"(没有扩展名为"html"的页面,它应该是"phtml").这是整个购物车的查看页面.由于您对这些项目感兴趣,因此您应该查看"default/template/checkout/cart/item/default.phtml".它所引用的Block类为"Mage_Checkout_Block_Cart_Item_Renderer".该PHTML页面可用于每个项目,因此您可以在此页面中完成每个项目所需的操作.

Now coming back to the question, the view page which you are seeing is "default/template/checkout/cart.phtml" (There is no page with extension "html", it should be "phtml"). This is the view page of the whole Cart. Since you are interested in the items, so you should be looking at "default/template/checkout/cart/item/default.phtml". The Block class, which it refers to, is "Mage_Checkout_Block_Cart_Item_Renderer". This PHTML page serves for each item, so whatever you need to do for each item can be done in this page.

要从购物车中删除产品,您需要知道该产品的报价项目ID,并写以下语句:-

To remove the Product from the Cart, you need to know that product's Quote Item ID, and write the following statement:-

$this->getUrl('checkout/cart/delete', array('id' => 'xxxx'));

其中xxxx是指要删除的产品的报价项目ID.

where xxxx refers to the to-be-deleted product's Quote Item ID.

要从购物车中删除产品,请在结帐购物车"页面中,在"default/template/checkout/cart/item/default.phtml"中调用以下语句:-

To remove the Product from the Cart, in the Checkout Cart page, you need to call the following statement in "default/template/checkout/cart/item/default.phtml":-

$this->getDeleteUrl();

执行此语句后,它将自动从内部获取该产品的报价项目ID(这是Magento的优点).

When this statement will get executed, it will take in that product's Quote Item ID from internal automatically (that's the beauty of Magento).

要从购物车中获取产品ID ,请在结帐购物车"页面中,在"default/template/checkout/cart/item/default.phtml"中调用以下语句:-

To get the Product ID from the Cart, in the Checkout Cart page, you need to call the following statement in "default/template/checkout/cart/item/default.phtml":-

$this->getProduct()->getId();

方法"getProduct()"将返回&加载该产品的Model对象(包含所有详细信息),下一个方法"getId()"将使用该对象来获取该产品的ID.

The method "getProduct()" will return & load that Product's Model object (with all the details), which the next method "getId()" will use it for fetching that Product's ID.

希望有帮助.

这篇关于如何获取网址以从Magento中的购物车中删除产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆