1
我正在試圖創建一個新模塊來繞過免費下載產品的簽出過程。由於我不是開發人員,我需要一些模塊的xml文件的幫助。Magento簽出,試圖創建一個免費產品的新模塊
我已經此文件夾結構:
應用的/ etc /模塊/ Fe_Freecheckout.xml
應用程序/代碼/本地/鐵/ Freecheckout /控制器/ CheckoutController.php 應用程序/代碼/本地/鐵/ 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);
}
}
?>
應用程序的/ etc /模塊/ 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>
這是應用程序/代碼/本地/鐵/ 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>
然後,在產品/ I 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 } ?>
我總是克找不到頁面...請提供任何方向?
謝謝。
我沒有任何helper.php文件在我的模塊中...只有結帳controller.php –
您可以刪除那種情況.. – urfusion
謝謝你。我會嘗試添加此代碼到config.xml。 –