在 Magento 的侧边栏中添加购物车链接(包含商品数量)
我面临着来自一位独特客户的独特问题。在 Magento 的帐户屏幕中,“我的购物车”通常出现在两个位置:顶部栏,并在侧栏中作为一个块。但是,我的任务是删除这些内容并在侧边栏的“我的帐户”部分中放置一个链接(包含购物车中的商品数量)。
看来作为一个新用户,我无法发布任何图像。这会带来一个问题。
我的帐户
仪表板
地址簿
我的购物车 (2 件) <---- 此链接在此。在此区域内,并显示物品数量
我的订单
我的产品评论
五月标签 时事通讯订阅
现在,添加链接本身就是个问题。事实上,它非常简单,可以在
<action method="addLink" translate="label" module="checkout"><name>cart</name><path>checkout/cart/</path><label>My Cart</label></action>
customer.xml 文件中完成。
问题源于在该区域内列出购物车中的商品。如果这个网站只有英文,code\core\Mage\Customer\Block\Account\Navigation.php 中的一些“if”语句就可以解决这个问题。但是,所有翻译似乎都是在调用 addItem 函数以将这些链接添加到菜单之前完成的。
我认为如果在调用 addItem 之前可以显示购物车中的商品数量,这个问题就可以解决,但是标签内部的所有 php 都会被忽略。
如果有人有解决方案或任何线索,将不胜感激!感谢您花时间阅读本文。
I'm faced with a unique problem from a unique customer. In Magento's account screen, there are typically two places where "My Cart" makes an appearance; the top bar, and in the sidebar as a block. However, I've been tasked with removing those and placing a link (with the number of items in the cart) in the "My Account" section of the sidebar.
It appears that as a new user, I cannot post any images. This is going to pose a problem.
MY ACCOUNT
Dashboard
Address Book
My Cart (2 items) <---- This link here. Within this area, and showing the number of items
My Orders
My Product Reviews
May Tags
Newsletter Subscriptions
Now, adding the link itself is problem. In fact, it's quite simple and accomplished by
<action method="addLink" translate="label" module="checkout"><name>cart</name><path>checkout/cart/</path><label>My Cart</label></action>
within the customer.xml file.
The problem stems from listing the items in the cart within that area. If this site were only in English, a few "if" statements inside of code\core\Mage\Customer\Block\Account\Navigation.php would resolve it. However, all translation seems to be done before the addItem function is called to add those links to the menu.
I figure that if the number of items in the cart could be displayed before addItem is called, this problem would be solved, but all php from inside of the tags gets ignored.
If anyone has a solution or any clues to this, it would be greatly appreciated! Thanks for taking the time to read this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相当确定我们无法从
addLink
块操作(尤其是从布局文件)完成“我的购物车(%d 件)”功能,因为我们需要调用Mage::helper('checkout/cart')->getCart()->getItemsCount()
获取购物车中的商品数量。我建议按照您的建议使用 if 语句,然后使用
__($str) ?>
进入本地化系统来翻译您的字符串模板文件,如有必要,将翻译添加到区域设置 csv 文件中。I'm fairly sure we won't be able to accomplish the "My Cart (%d items)" functionality from the
addLink
block action (especially from the layout file) as we need to callMage::helper('checkout/cart')->getCart()->getItemsCount()
to get the number of items in our cart.I recommend using the if statements, as you suggest, then tapping into the localisation system by using
<?php echo $this->__($str) ?>
to translate your strings in the template file, adding the translation to the locale csv files if necessary.通常,与物品数量的链接是在
Mage_Checkout_Block_Links
中通过其addCartLink()
方法实现的。用户帐户侧边栏是一个Mage_Customer_Block_Account_Navigation
,它没有该方法。您需要通过覆盖该类来自己添加它。您的/Module/etc/config.xml
您的/Module/Block/Account/Navigation.php
(主要从 Mage_Checkout_Block_Links 复制)
layout/customer.xml
Normally the link with number of items is achieved in
Mage_Checkout_Block_Links
with it'saddCartLink()
method. The user account sidebar is aMage_Customer_Block_Account_Navigation
which does not have that method. You need to add it yourself by overriding the class.Your/Module/etc/config.xml
Your/Module/Block/Account/Navigation.php
(copied mostly from Mage_Checkout_Block_Links)
layout/customer.xml