【发布时间】:2015-10-06 12:10:00
【问题描述】:
我正在尝试创建一个新模块来绕过免费下载产品的结帐流程。由于我不是开发人员,我需要一些关于模块 xml 文件的帮助。
我有这个文件夹结构:
app/etc/modules/Fe_Freecheckout.xml
app/code/local/Fe/Freecheckout/controllers/CheckoutController.php app/code/local/Fe/Freecheckout/etc/config.xml
这些是文件的内容:
CheckoutController.php
<?php
public function purchaseAction() {
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
$this->_redirectUrl(Mage::getBaseUrl().'customer/account');
return;
}
$request = $this->getRequest();
$id = $request->getParam('id');
$product = Mage::getModel('catalog/product')
->load($id)
->setStoreId(Mage::app()->getStore()->getId());
if(!($product->getIsVirtual() && $product->getFinalPrice() == 0)){
Mage::getSingleton('checkout/session')->addError($this->__('Method only available for Free Downloadable Items'));
return $this;
}
$onepage = Mage::getSingleton('checkout/type_onepage');
/* @var $onepage Mage_Checkout_Model_Type_Onepage */
try{
$quote = $onepage->getQuote();
/* @var $quote Mage_Sales_Model_Quote */
$quote->addProduct($product);
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$onepage->initCheckout();
$payment=array('method'=>'free');
$onepage->savePayment($payment);
$onepage->saveOrder();
$this->getResponse()->setRedirect('/downloadable/customer/products');
}
catch(Exception $e){
$result = $e->getMessage();
Mage::getSingleton('checkout/session')->addError($result);
}
}
?>
app/etc/modules/Fe_Freecheckout.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Fe_Freecheckout>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>local</codePool>
</Fe_Freecheckout>
</modules>
</config>
这是 app/code/local/Fe/Freecheckout/etc/config.xml 我不知道如何注册我的结帐控制器:
<?xml version="1.0" encoding="UTF-8"?>
<!-- The root node for Magento module configuration -->
<config>
<!--
The module's node contains basic
information about each Magento module
-->
<modules>
<!--
This must exactly match the namespace and module's folder
names, with directory separators replaced by underscores
-->
<Fe_Freecheckout>
<!-- The version of our module, starting at 0.0.1 -->
<version>0.0.1</version>
</Fe_Freecheckout>
</modules>
</config>
然后在 product/view.phtml 中我使用以下代码进行结帐:
<?php if($_product->isVirtual() && $_product->getFinalPrice()==0) { ?>
<a href="/Freecheckout/checkout/purchase/id/<?php echo $_product->getId()?>"><?php echo $this->__('Download and Install') ?></a>
<?php } ?>
我总是收到找不到页面...请问有什么路线吗?
谢谢。
【问题讨论】: