magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮
1 添加产品到购物车成功后是跳转到购物车页面或不跳转。这个在后台可以设置
system -》 configuration -》 After Adding a Product Redirect to
Shopping Cart – Yes/No”
这个是设置成功添加产品后是跳转到购物车页面,还是不跳转
2 修改默认的跳转页面
可以在app\design\frontend\default\theme173\template\catalog\product\view.phtml
<input type="hidden" name="return_url"
value="yoururl" />
将url替换成要跳转的页面的url就可以了。
3 添加一个add to cart的按钮
两个按钮可以一个自动跳转到购物车页面,一个不跳转,中文网站中,一般有一个立即购买(跳转到购物车页面),一个添加到购物车(不跳转停留在原来页面)。
解决这个的办法就是重写控制器Checkout-CartController
1)创建模块目录和文件
- Magento/app/code/local/MyNameSpace/MyCheckout/etc/config.xml
- Magento/app/code/local/MyNameSpace/MyCheckout/controllers/CartController.php
- Magento/app/etc/modules/MyNameSpace_MyCheckout.xml
2)编辑Magento/app/code/local/MyNameSpace/MyCheckout/etc/config.xml
<?
xml
version
=
"1.0"
?>
<
config
>
<
modules
>
<
MyNameSpace_Mycheckout
>
<
version
>0.1.0</
version
>
</
MyNameSpace_Mycheckout
>
</
modules
>
<
frontend
>
<
routers
>
<
MyNameSpace_Mycheckout
>
<
use
>standard</
use
>
<
args
>
<
module
>MyNameSpace_Mycheckout</
module
>
<
frontName
>mycheckout</
frontName
>
</
args
>
</
MyNameSpace_Mycheckout
>
</
routers
>
</
frontend
>
<
global
>
<
routers
>
<
checkout
>
<
rewrite
>
<
cart
>
<
to
>mycheckout/cart</
to
>
<
override_actions
>true</
override_actions
>
<
actions
>
<
add
>
<
to
>mycheckout/cart/add</
to
>
</
add
>
</
actions
>
</
cart
>
</
rewrite
>
</
checkout
>
</
routers
>
</
global
>
</
config
>
3)编辑
/controllers/CartController.phpMagento/app/code/local/MyNameSpace/MyCheckout/controllers/CartController.php
<?php
require_once
'Mage/Checkout/controllers/CartController.php'
;
class
MyNameSpace_Mycheckout_CartController
extends
Mage_Checkout_CartController
{
public
function
addAction()
{
$cart
=
$this
->_getCart();
$params
=
$this
->getRequest()->getParams();
try
{
if
(isset(
$params
[
'qty'
])) {
$filter
=
new
Zend_Filter_LocalizedToNormalized(
array
(
'locale'
=>
Mage::app()->getLocale()->getLocaleCode())
);
$params
[
'qty'
]
=
$filter
->filter(
$params
[
'qty'
]);
}
$product
=
$this
->_initProduct();
$related
=
$this
->getRequest()->getParam(
'related_product'
);
if
(!
$product
)
{
$this
->_goBack();
return
;
}
$cart
->addProduct(
$product
,
$params
);
if
(!
empty
(
$related
))
{
$cart
->addProductsByIds(
explode
(
','
,
$related
));
}
$cart
->save();
$this
->_getSession()->setCartWasUpdated(true);
Mage::dispatchEvent(
'checkout_cart_add_product_complete'
,
array
(
'product'
=>
$product
,
'request'
=>
$this
->getRequest(),
'response'
=>
$this
->getResponse())
);
if
(!
$this
->_getSession()->getNoCartRedirect(true))
{
if
(!
$cart
->getQuote()->getHasError()){
$message
=
$this
->__(
'%s
was added to your shopping cart.'
,
Mage::helper(
'core'
)->htmlEscape(
$product
->getName()));
$this
->_getSession()->addSuccess(
$message
);
}
if
(
$returnUrl
=
$this
->getRequest()->getParam(
'return_url'
))
{
//
clear layout messages in case of external url redirect
if
(
$this
->_isUrlInternal(
$returnUrl
))
{
$this
->_getSession()->getMessages(true);
}
$this
->getResponse()->setRedirect(
$returnUrl
);
}
elseif
(!Mage::getStoreConfig(
'checkout/cart/redirect_to_cart'
)
&&
!
$this
->getRequest()->getParam(
'in_cart'
)
&&
$backUrl
=
$this
->_getRefererUrl()) {
$this
->getResponse()->setRedirect(
$backUrl
);
}
else
{
if
((
$this
->getRequest()->getActionName()
==
'add'
) &&
!
$this
->getRequest()->getParam(
'in_cart'
))
{
$this
->_getSession()->setContinueShoppingUrl(
$this
->_getRefererUrl());
}
if
(
$this
->getRequest()->getParam(
'noCheckoutYet'
)==
"yes"
)
$this
->getResponse()->setRedirect(
$this
->_getRefererUrl());
else
$this
->_redirect(
'checkout/cart'
);
}
}
}
catch
(Mage_Core_Exception
$e
) {
if
(
$this
->_getSession()->getUseNotice(true))
{
$this
->_getSession()->addNotice(
$e
->getMessage());
}
else
{
$messages
=
array_unique
(
explode
(
"\n"
,
$e
->getMessage()));
foreach
(
$messages
as
$message
)
{
$this
->_getSession()->addError(
$message
);
}
}
$url
=
$this
->_getSession()->getRedirectUrl(true);
if
(
$url
) {
$this
->getResponse()->setRedirect(
$url
);
}
else
{
$this
->_redirectReferer(Mage::helper(
'checkout/cart'
)->getCartUrl());
}
}
catch
(Exception
$e
) {
$this
->_getSession()->addException(
$e
,
$this
->__(
'Cannot add the item to shopping
cart.'
));
$this
->_goBack();
}
}
}
4)编辑文件
Magento/app/etc/modules/MyNameSpace_MyCheckout.xml
<?xml version=
"1.0"
?>
<config>
<modules>
<MyNameSpace_Mycheckout>
<active>true</active>
<codePool>local</codePool>
</MyNameSpace_Mycheckout>
</modules>
</config>
5)编辑文件
Magento/app/design/frontend/[myinterface]/[mytheme]/layout/checkout.xml
<
camelweb_mycheckout_cart_index
>
<
update
handle
=
"checkout_cart_index"
/>
</
camelweb_mycheckout_cart_index
>
6)
在模版文件中添加 “Add to cart”按钮view/addtocart.phtml
<?php
$_product
=
$this
->getProduct()
?>
<?php
if
(
$_product
->isSaleable()):
?>
<div
class
=
"add-to-cart"
>
<?php
if
(!
$_product
->isGrouped()):
?>
<label
for
=
"qty"
><?php
echo
$this
->__(
'Qty:'
)
?></label>
<input
type=
"text"
name=
"qty"
id=
"qty"
maxlength=
"12"
value=
"<?php echo
$this->getMinimalQty($_product)
?>"
title=
"<?php echo
$this->__('Qty') ?>"
class
=
"input-text
qty"
/>
<?php
endif
;
?>
<button
type=
"button"
title=
"<?php echo
$this->__('Add to Cart') ?>"
class
=
"button
btn-cart"
onclick=
"productAddToCartForm.submit()"
><span><span><?php
echo
$this
->__(
'Add to Cart'
)
?></span></span></button>
<br
/>
<!--自定义添加的add
to cart的按钮-->
<a
href=
"<?php echo
Mage::getUrl('checkout/cart/add', array('product' =>
$_product->getId(),
'noCheckoutYet'=>'yes'))
?>"
>Add to cart
2</a>
<?php
echo
$this
->getChildHtml(
''
, true, true)
?>
</div>
<?php
endif
;
?>
7)清下缓存,然后后台设置下跳转或不跳转,或者根据本文的第二方法,添加下代码,让默认的不跳转,我们重新添加的add to cart
按钮不跳转
magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮的更多相关文章
- 关于WordPress登录后跳转到指定页面
前面在写模版的时候,有朋友要求网站登录后要跳转的到指定的页面.这个从前还真没遇到过.于是就用万能的搜索(很少百度)找了下,方法基本上就是一个,代码如下: <?php // Fields f ...
- shiro控制登陆成功后跳回之前的页面
登陆之后跳回之前的页面是在做登陆注册模块时遇到的一个需求,也是很有必要的.若用户直接访问登陆页面,那可以控制它直接到首页,但是要用户没有登陆直接访问自己的购物车等需要经过身份认证的页面,或者因为ses ...
- web.config中配置页面出错后跳转指定错误页面
每当用户访问错误页面时,会出现不友好的404错误,所以为了防止这种不友好,我们在web.config中的<system.web>节点下配置 <customErrors>,在出现 ...
- layui弹窗里面 session过期 后跳转到登录页面
1.在登录页面添加 <script> $(function () { if (top != window) { layer.msg("登录失效", {icon: 5}) ...
- MVC 访问IFrame页面Session过期后跳转到登录页面
Web端开发时,用户登录后往往会通过Session来保存用户信息,Session存放在服务器,当用户长时间不操作的时候,我们会希望服务器保存的Session过期,这个时候,因为Session中的用户信 ...
- php弹窗后跳入另一个页面
之前写项目时,在跳转页面前加入一个弹窗,发现弹窗没有弹出来就直接跳转了,之前使用的header跳转发现不行,换成location.href也不行,后来再location.href前加入一个parent ...
- 编写Servlet,验证用户登录,如果用户名与密码都为“admin”则验证通过,跳转欢迎页面,否则弹出提示信息“用户名或密码错误,请重新输入!”,点击“确定”后跳转至登录页面
java代码:(Test1) package com.test; import java.io.IOException; import java.io.PrintWriter; import java ...
- C#-WebForm-点击网页中的按钮后跳转到其他页面是怎么实现的?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- session失效后跳转到登陆页面
一.编写Filter拦截器类 package com.pv.utils; import java.io.IOException; import java.io.PrintWriter; import ...
随机推荐
- SAP smartforms之Zebra print control language
因为在做个小标签的时候需要将部分字符旋转180度,在scn上找了很久也发布了自己的提问,不过最终的结果却不尽人意.Rotated text in smartforms need use the PCL ...
- 聚类算法:K-means 算法(k均值算法)
k-means算法: 第一步:选$K$个初始聚类中心,$z_1(1),z_2(1),\cdots,z_k(1)$,其中括号内的序号为寻找聚类中心的迭代运算的次序号. 聚类中心的向量值可任意设 ...
- PHP函数——parse_ini_file() 函数
资料网址:http://www.w3school.com.cn/php/func_filesystem_parse_ini_file.asp 1.parse_ini_file() 函数解析一个配置文件 ...
- display:inline-block;如何取消标签之间的距离
<div style="font-size:0px"> <div style=" display:inline-block; zoom:1;*displ ...
- ANGULARJS 动态编译添加到dom中
在使用angularjs 时,希望通过动态构建angular模版,再通过angular进行展示. 使用 方法如下: <html ng-app="app"> <he ...
- 让DIV实现抖动效果!
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- eclipse关联tomcat并且部署java web应用程序
http://www.ibm.com/developerworks/cn/opensource/os-eclipse-tomcat/
- UVa 11021 - Tribles
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 凸多边形的三角剖分(dp好题)
[题目描述]给定一具有N个顶点(从1到N编号)的凸多边形,每个顶点的权均已知.问如何把这个凸多边形划分成N-2个互不相交的三角形,使得这些三角形顶点的权的乘积之和最小?[输入格式]第一行 顶点数N(N ...
- zabbix邮件报警
#!/usr/bin/python #coding:utf-8 import smtplib from email.mime.text import MIMEText import sys mail_ ...