我应该如何在 Magento 中捕获与订单一起存储的自定义表单?
我正在开发一个模块,将名为 Rental 的新步骤添加到 magento 的 Onepage Checkout 模块中。问题不在于添加步骤,而在于数据捕获。
我希望能够采用我创建的自定义表单并将其与其余订单信息一起存储,因此当我单击后端中的“查看订单”时,它将表单中的信息显示为单独的框。
最好我想通过创建一个独立的模块来分离关注点。
你会怎样做呢?您实施此计划的个人策略是什么?
I am working on a module to add a new step called Rental into the Onepage Checkout module in magento. The problem is not adding a step it is the data capture.
I want to be able to take the custom form I have created and store it with the rest of the order information so when I click view order in the backend, it shows the information in the form as a seperate box.
Preferably I want to seperate the concerns by creating a standalone module.
How would you go about doing this? What would be your personal strategy for implementing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,这完全取决于“租赁”数据是什么。它可以适合/适当地放置在产品的自定义选项中吗?或者您是否需要创建自定义销售属性来存储数据?
如果您想要后者,您应该使用 Magento Module Creator by SilkSoftware 创建一个模块来实现销售属性。
另外:使用销售属性的一个很好的线程/场景:Magento:在 sales/order_shipment 模型上设置自定义属性
其次,捕获表单数据 - 假设您已经创建了一个块/表单并显示在结帐页面上。我强烈建议您按照以下语义命名字段:
其中
text_data
和text_data2
是您所需的变量名称。订单最终通过
Mage_Checkout_OnepageController
中名为saveOrderAction
的控制器操作或您当前用于结帐页面的任何控制器类提交/保存。不要编辑在app/code/core/Mage/Checkout/controllers/OnepageController.php
中找到的相应 PHP 类文件!由于您想将其分离到另一个模块中,因此您应该尝试重写此控制器,以便 Magento 在其扩展上述基类 (Mage_Checkout_OnepageController
) 的模块内使用您的自定义控制器类相反。关于重写控制器的好教程可以在此处找到。
然后,您可以从此处执行以下两个选项之一:
1.) 您可以复制整个 saveOrderAction 函数并创建例程以在此处保存租赁数据。如果您遵循我建议的命名语义,您应该能够检索表单数据,这样做:
2.)其次,您可以用自定义事件调度替换上面的代码
,然后创建一个适当的观察者将自定义数据保存在某处。
我知道这并不多,但这是一个开始。我将在不久的将来考虑对其进行编辑以详细说明。
Firstly, it should all depend on what data 'Rental' would be. Could it fit/be appropriately placed inside a product's custom option? Or do you need to create a custom sales attribute to store the data in?
If you want the latter, you should use Magento Module Creator by SilkSoftware to create a module to implement sales attributes.
Also: a good thread / scenario in using sales attributes: Magento: Setting a custom attribute on the sales/order_shipment model
Secondly, is capturing the form data -- this is assuming you already have a block/form created and showing on the checkout page. I highly encourage you name the fields in the following semantic:
Where
text_data
andtext_data2
are your desired variable names.An order is submitted / saved finally via a Controller action called
saveOrderAction
inMage_Checkout_OnepageController
or whatever Controller class you are using currently for your checkout page. Don't edit the corresponding PHP Class file for this found atapp/code/core/Mage/Checkout/controllers/OnepageController.php
! Since you want to separate this into another module, you should try and rewrite this controller then so that your custom Controller class inside your module that extends the aforementioned base class (Mage_Checkout_OnepageController
) should be used by Magento in its stead.A good tutorial on rewriting controllers can be found here.
You can then do either of the two options from here:
1.) you could copy the entire saveOrderAction function and create routines to save Rental data there. if you followed the naming semantic I suggested, you should be able to retrieve the form data doing so:
2.) secondly, you could replace the above code with a custom event dispatch
then make an appropriate observer to save your custom data somewhere.
I know this isn't much, but it's a start. I will look into editing this to elaborate more in the near future.