Magento - 步骤结帐和附加模块

时间:2017-10-27 11:30:27

标签: magento

感谢这个论坛。我经常读它,这是我的第一个问题。 问题涉及Magento(1.9.1.0)。我想添加一个额外的模块,允许客户在订单上写评论。我已经能够在网上找到一个适合我需要的模块。它运作完美,但存在一个大问题:它在结账的最后一步(特别是在付款阶段之后)加入。因此,如果客户通过银行转帐,标记或类似付款付款,则不会出现问题:Magento会转到下一步(订单评论),然后完成订单。 在Paypal支付的情况下出现问题,因为Magento将客户重定向到Paypal.com,并且在付款后,在订单结束时返回商店(不进入评论的下一步)。评论表单由19个文件组成,一旦安装在Magento中,就不会修改任何现有文件。 我想在shipping_method步骤之后(而不是在付款步骤之后)包含此表单,因此,我认为我必须修改名为Abstract.php的文件(模块)(app / code / community / Brainvire / Ordercomment) /Controller/Onepage/Abstract.php)。 如果你能帮我编辑那个文件,我将非常感激。

<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Brainvire_Ordercomment_Controller_Onepage_Abstract extends 
Mage_Checkout_OnepageController {

/*
* Saving the Payment at Checkout
*/
public function savePaymentAction()
{
    $this->_expireAjax();
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('payment', array());


        try {
            $result = $this->getOnepage()->savePayment($data);
        }
        catch (Mage_Payment_Exception $e) {
            if ($e->getFields()) {
                $result['fields'] = $e->getFields();
            }
            $result['error'] = $e->getMessage();
        }
        catch (Exception $e) {
            $result['error'] = $e->getMessage();
        }
        $redirectUrl = $this->getOnePage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
        if (empty($result['error']) && !$redirectUrl) {
            $this->loadLayout('checkout_onepage_ordercomment');

            $result['goto_section'] = 'ordercomment';
        }

        if ($redirectUrl) {
            $result['redirect'] = $redirectUrl;
        }

        $this->getResponse()->setBody(Zend_Json::encode($result));
    }
}

/*
* Saving the order comment 
*/
public function saveOrdercommentAction()
{
    $this->_expireAjax();
    if ($this->getRequest()->isPost()) {


        $_brainvire_Ordercomment = $this->getRequest()->getPost('ordercomment');

        Mage::getSingleton('core/session')->setBrainvireOrdercomment($_brainvire_Ordercomment);

        $result = array();

        $redirectUrl = $this->getOnePage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
        if (!$redirectUrl) {
            $this->loadLayout('checkout_onepage_review');

            $result['goto_section'] = 'review';
            $result['update_section'] = array(
                'name' => 'review',
                'html' => $this->_getReviewHtml()
            );

        }

        if ($redirectUrl) {
            $result['redirect'] = $redirectUrl;
        }

        $this->getResponse()->setBody(Zend_Json::encode($result));
    }
}    
}

如何在shipping_method步骤之后和付款步骤之前编辑此php代码以插入Ordercomment? 谢谢 GS

1 个答案:

答案 0 :(得分:0)

我能够通过编辑两个文件来移动订单评论部分:

首先:Brainvire\Ordercomment\Block\Onepage.php

class Brainvire_Ordercomment_Block_Onepage extends Mage_Checkout_Block_Onepage
{
    /**
     * getting the steps of Checkout page
     */
    public function getSteps()
    {
        ...

        $stepCodes = array('billing', 'shipping', 'shipping_method', 'ordercomment', 'payment', 'review'); // moved 'ordercomment' before 'payment'

        ...
    }
}

然后是你提到的文件:Brainvire\Ordercomment\Controller\Onepage\Abstract.php

删除savePaymentAction()方法并替换为:

class Brainvire_Ordercomment_Controller_Onepage_Abstract extends Mage_Checkout_OnepageController {


     /**
     * Shipping method save action
     */
    public function saveShippingMethodAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('shipping_method', '');
            $result = $this->getOnepage()->saveShippingMethod($data);
            /*
            $result will have erro data if shipping method is empty
            */
            if(!$result) {
                Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method',
                        array('request'=>$this->getRequest(),
                            'quote'=>$this->getOnepage()->getQuote()));
                $this->getOnepage()->getQuote()->collectTotals();
                $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

                if (empty($result['error']) && !$redirectUrl) {
                    $this->loadLayout('checkout_onepage_ordercomment');
                    $result['goto_section'] = 'ordercomment';
                }
            }
            $this->getOnepage()->getQuote()->collectTotals()->save();
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }

    /*
    * Saving the order comment 
    */
    public function saveOrdercommentAction()
    {
        $this->_expireAjax();
        if ($this->getRequest()->isPost()) {
            $_brainvire_Ordercomment = $this->getRequest()->getPost('ordercomment');

            Mage::getSingleton('core/session')->setBrainvireOrdercomment($_brainvire_Ordercomment);

            $result = array();
            $result['goto_section'] = 'payment';
            $result['update_section'] = array(
                'name' => 'payment-method',
                'html' => $this->_getPaymentMethodsHtml()
            );
            $this->getResponse()->setBody(Zend_Json::encode($result));
        }
    }
}

一旦你开始工作,你应该将这些自定义移动到覆盖模块,或者至少将修改后的文件复制到app / code / local,这样原始代码就会保持不变。