将“添加到购物车" Magento主页上的按钮 [英] Placing "Add to cart" button on homepage in Magento

查看:109
本文介绍了将“添加到购物车" Magento主页上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Magento中开发一个购物门户.在首页上,我想在此处显示的每个产品旁边显示添加到购物车"按钮.主页是一个简单的静态CMS页面. 当我尝试此代码时,

I'm trying to develop a shopping portal in Magento. At homepage, I want to show "add to cart" button next to every product shown there. Home Page is a simple static CMS page. When i tried this code,

<button class="button btn-cart" title="Add to Cart" onclick="setLocation('/n/magento/checkout/cart/add/product/644/qty/1')" type="button"><span><span>Add to Cart</span></span></button>

其中644是产品ID,页面已重定向到购物车页面,但未将产品添加到购物车中.我也尝试了在Firefox,Chrome和IE中,但一无所获.我在许多网站上搜索了此内容,但找不到任何有用的信息. 如果有人可以为此提供帮助,那将是极大的帮助.预先感谢.

where 644 is product id, page was redirected to cart page, but product is not being added in the cart. I tried it in firefox, chrome and IE as well but with nothing. I searched through many sites for this, but couldn't find anything useful. If anyone could help regarding this, it will be of great help. Thanks in advance.

推荐答案

自从我发布此问题已有很长时间了,我最终找到了答案,但忘了在此处添加答案.

It's been a long time since I posted this question, and I eventually found the answer but forgot to add that here.

我无法从admin wysiwyg编辑器内部使用添加到购物车"按钮,因为它需要通过PHP调用Magento类,而在admin编辑器中是不可能的(不适用于PHP代码).

There is no way I can have "Add to cart" button from within inside admin wysiwyg editor as it requires calling Magento classes via PHP which is not possible from the admin editor(It is not for PHP code).

我所做的,在管理员中被称为这样的模板:

What I did, was called a template in admin like this :

<block type="core/template" name="home_products" template="home/product.phtml">

然后,在该文件中,我使用了PHP函数,使Magento具备了正确添加到购物车按钮所需的格式.我只是通过目录/产品模型加载了产品,然后像catalog/product/view/addtocart.phtml文件中的内容一样创建了表单.另外,在最新版本的Magento中,还应在表单中包含formkey,以使其正常工作.

And then, Inside that file, I used PHP functions to have the form that Magento requires for a proper Add to cart button. I simply loaded the product via catalog/product model and then created the form similarly like what is inside catalog/product/view/addtocart.phtml file. Also, with latest versions of Magento, formkey should also be present inside the form to get it working properly.

这篇关于将“添加到购物车" Magento主页上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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