【问题标题】:How to execute a script at the end of and Magento Order process?如何在 Magento Order 流程​​结束时执行脚本?
【发布时间】:2013-06-03 13:09:55
【问题描述】:

我正在 Magento atm 中构建自己的结帐方法。我创建了一个 PHP 脚本,该脚本具有在将订单详细信息填写到我的自定义付款页面后重定向用户的功能。该脚本本身正在运行,但它在订购过程的早期被触发。启用后,当用户单击“去结帐按钮”而不填写订单详细信息时,他或她会立即被重定向。所以我的 PHP 脚本被 Magento 看到了,并且该方法被立即触发(我正在使用 _contruct 方法)。

所以现在是以下程序: 用户选择产品 -> 用户进入购物篮 -> 用户点击结帐 -> 用户被重定向。

我希望它如下所示: 用户选择产品 -> 用户进入购物篮 -> 用户点击结帐 -> 用户填写订单详细信息并根据需要选择我的送货方式 -> 用户点击“完成订单并付款” -> 用户现在被重定向脚本被执行。

我的 PHP 脚本使用以下语法:

 public function __construct()
{ my PHP code here with the redirect };

当用户选择发货地址、账单地址并选择我的付款方式后,我如何让 PHP 脚本执行?

【问题讨论】:

  • 也许在真正尝试编写任何代码之前尝试阅读有关 magento 的书/基础知识?提示:使用事件
  • @Bixi thx 给小费。我正在与一群编码学生一起工作。我们有编程经验,但没有 Magento 框架。我们将调查 Magento 事件,再次感谢。

标签: magento zend-framework mage


【解决方案1】:

下单后可以使用magento的事件/观察者方法做某事。

你可以使用这个活动sales_order_place_after

只需创建一个模块来监听 magento 观察者/事件。

在您的 /app/code/local/{namespace}/{yourmodule}/etc/config.xml 中:

<config>
        ...
        <frontend>
            ...
            <events>
                <sales_order_place_after>
                    <observers>
                        <unique_event_name>
                            <class>{{modulename}}/observer</class>
                            <method>your function name</method>
                        </unique_event_name>
                    </observers>
                </sales_order_place_after>
            </events>
            ...
        </frontend>
        ...
    </config>

然后在 /app/code/local/{namespace}/{yourmodule}/Model/Observer.php 创建一个 Observer 类

    class <namespace>_<modulename>_Model_Observer
   {
      public function your function name(Varien_Event_Observer $obs)
      {
          whatever your logic put here
      }

   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多