【问题标题】:How to Display Update Shopping Cart on Magento Checkout Page?如何在 Magento 结帐页面上显示更新购物车?
【发布时间】:2015-05-01 16:02:05
【问题描述】:
我正在尝试在结帐页面上显示更新购物车,有什么方法可以显示吗?
<?php echo $this->getChildHtml('form_before') ?>
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<?php echo $this->getBlockHtml('formkey'); ?>
<button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update Shopping Cart'); ?>" class="button btn-update"><?php echo $this->__('Update Shopping Cart'); ?></button>
</form>
【问题讨论】:
标签:
php
magento
checkout
cart
【解决方案1】:
首先,您需要在模板中添加购物车更新操作的表单。请注意,您必须将其添加到任何其他表单之外。然后,您需要添加自己的模块和自己的前端控制器和等待表单提交并将用户重定向回结帐的操作。
表单的动作应该是:
<form action="<?php echo $this->getUrl('frontNameOfYourController'); ?>" method="post">
//Don't forget to add a session key to this form.
<div><input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /></div>
在你的 etc/config.xml 添加这个:
<frontend>
<routers>
<modulename>
<use>standard</use>
<args>
<module>Package_Modulename</module>
<frontName>frontNameOfYourController</frontName>
</args>
</modulename>
</routers>
</frontend>
然后在您的控制器/文件夹中添加 IndexController.php:
class Package_Modulename_IndexController extends Mage_Core_Controller_Front_Action {
//Method for submitting the action
public function indexAction()
{
//This action should receive the posted data from the form, please refer to the methods: public function updatePostAction(), protected function _updateShoppingCart() for updating the cart and protected function _emptyShoppingCart() for emptying the cart in code/core/Mage/Checkout/controllers/CheckoutController.php
//The difference in your method should be that it should redirect to your checkout page once the form is submitted.
}
}
我认为这将为您完成工作。如果您想了解有关如何编写方法的更多说明,请发表评论。
【解决方案2】:
在local.xml文件中添加如下代码
app/design/frontend/YOURPACKAGE/YOURTHEME/layout/local.xml
<checkout_onepage_index translate="label">
<reference name="right">
<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
<action method="addItemRender">
<type>simple</type>
<block>checkout/cart_item_renderer</block>
<template>checkout/cart/sidebar/default.phtml</template>
</action>
<action method="addItemRender">
<type>grouped</type>
<block>checkout/cart_item_renderer_grouped</block>
<template>checkout/cart/sidebar/default.phtml</template>
</action>
<action method="addItemRender">
<type>configurable</type>
<block>checkout/cart_item_renderer_configurable</block>
<template>checkout/cart/sidebar/default.phtml</template>
</action>
<block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
<label>Shopping Cart Sidebar Extra Actions</label>
</block>
</block>
</reference>
</checkout_onepage_index>