Magento Checkout,试图为免费产品创建一个新模块

时间:2015-10-06 12:10:01

标签: php magento

我正在试图创建一个新模块,以绕过免费下载产品的结帐流程。由于我不是开发人员,我需要一些模块的xml文件的帮助。

我有这个文件夹结构:

应用程序的/ 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>

这是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 } ?>

我总是找不到页面......有任何指示吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

我认为您需要覆盖onepagecontroller

<global>
    <rewrite>        
        <Packag_modulename_checkout_onepagecontroller>
            <from><![CDATA[#^/checkout/onepage/#]]></from> <!-- Mage_Checkout_OnepageController  -->
            <to>/modulename/checkout_onepage/</to> <!-- Package_ModuleName_Checkout_OnepageController  -->
        </Package_modulename_checkout_onepagecontroller>
    </rewrite>
    <helpers>
        <modulename>
            <class>Package_ModuleName_Helper</class>
        </modulename>
    </helpers>
</global>

这可能对你有帮助。