php商城首页跳转到购物车页,magento产品添加到购物车后跳转到不同页面

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

true

local

5)编辑文件Magento/app/design/frontend/[myinterface]/[mytheme]/layout/checkout.xml

6) 在模版文件中添加 “Add to cart”按钮 view/addtocart.phtml

<?php  $_product = $this->getProduct() ?>

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

<?php  if(!$_product->isGrouped()): ?>

<?php  echo $this->__('Qty:') ?>

getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />

__('Add to Cart') ?>" class="button btn-cart" οnclick="productAddToCartForm.submit()"><?php  echo $this->__('Add to Cart') ?>

Add to cart 2

<?php  echo $this->getChildHtml('', true, true) ?>

7)清下缓存,然后后台设置下跳转或不跳转,或者根据本文的第二方法,添加下代码,让默认的不跳转,我们重新添加的add to cart 按钮不跳转

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值