【问题标题】:Magento Checkout, Trying to create a new module for free productsMagento Checkout,尝试为免费产品创建新模块
【发布时间】: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 } ?>

我总是收到找不到页面...请问有什么路线吗?

谢谢。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    我认为你需要覆盖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>
    

    这可能会对你有所帮助。

    【讨论】:

    • 我的模块中没有任何 helper.php 文件...只有结帐 controller.php
    • 谢谢。我会尝试将此代码添加到 config.xml。
    • 有没有把Packag_modulename换成Fe_Freecheckout
    • 是的,这是我的应用程序/code/local/Fe/Freecheckout/etc/congif.xml /Freecheckout/checkout_onepage/
    猜你喜欢
    • 2013-08-28
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多