且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Drupal Commerce订单对象额外数据

更新时间:2023-11-30 13:20:40

好的,所以这是我根据您在问题中提供的新信息给出的新答案

OK, so here's my new answer based on the new info you provided in your question

================================

=================================

因此,这可能比您预期的要复杂一些,但并非不可能!有两点很重要:

So this is probably a little more complicated than you expected, but not impossible! Two things are important:

  • 您订单上所附的订单项将包含您的产品和
  • 您将需要使用一个规则组件,以便能够在规则操作中包含一个附加的条件操作"组合

这是操作方法:

  1. 在完成结帐过程"时触发的规则中,在"操作"部分中添加循环.您应该在添加操作"旁边看到添加循环".我们将使用此循环遍历您订单中的所有商务行项目:这就是产品隐藏的地方
  2. 在配置循环时,告诉它通过"commerce-order:commerce-line-items"进行迭代,然后重命名,或者记住在调用每个订单项时要调用的内容.

  1. In your rule that is triggered upon 'Completing the checkout process', add a loop in your 'Actions' section. You should see 'Add loop' right next to 'Add action'. We'll use this loop to iterate through all the commerce-line-items in your order: that's where the products are hiding
  2. When configuring the loop, tell it to iterate through 'commerce-order:commerce-line-items' and either rename, or remember what it's going to call each line item as it goes through it.

现在-当它遍历您订单的每个订单项时,我们将要使用其自己的条件"和操作"集调用一条完整的新规则.我们需要的条件是检查订单项是否包含您期望的产品,并且该操作可以是您想要的任何操作-根据特定字段或任何内容发布节点.就我而言,该操作只是发送电子邮件以证明我找到了产品.当我们需要规则中的条件操作集时,我们需要创建一个规则组件

Now - as it's going through each of your order's line items, we'll want to call an entire new rule with its own set of 'condition' and 'action'. The condition we need is to check that the line item contains the product you expect, and the action can be whatever you want - publish a node based on a certain field or whatever. In my case, the action will just be sending an email to prove I found a product. When we need condition-action sets within a rule, we need to create a rule component!!

转到/admin/config/workflow/rules/components创建一个新的规则组件,以针对上述每个项目运行.点击页面顶部的添加新组件"链接

Go to /admin/config/workflow/rules/components to create a new rule component to run for each of the above items. Click the 'Add new component' link at the top of the page

从下拉选项中选择"规则",因为这将是既包含条件又包含操作的组件

Select 'Rule' from the drop-down options, since this will be a component that contains both a condition and an action

命名规则,在变量"部分中,我们必须让它知道我们将为其传递一个要使用的参数.在我们的例子中,将是当前正在迭代的商务订单项.

Name the rule, and in the 'Variables' section, we have to let it know we're going to pass it a parameter to work with. In our case, it will be the commerce line item that is currently being iterated through.

  1. 在组件中添加两个条件(或您认为必要的任何检查).我添加了实体类型" => Commerce Line item和实体有字段" => commerce_product.因此,此刻适用于我所有的产品.
  2. 我在组件上设置的条件是发送电子邮件,然后在电子邮件正文中填写以下内容:[line-item:commerce_product],并且每次都会在电子邮件中漂亮地打印出产品名称我已经测试过结帐了!

但是首先-保存后,如何为每种订单项类型调用此组件?继续阅读:

But first - how do I call this component for each of my line item types after I save it?? Read on:

  1. 保存组件后,添加操作到您的循环中:
  2. 从现在开始,在操作的最底部,您将看到一个全新的组件"部分,对于您而言,现在应该只有一个.选择它可以为每个项目调用它:
  3. 最后一步是填写要传递给该组件的参数,该参数显然是您当前正在使用的list_item,或者如果更改了当前项目的计算机名称,则为该名称.
  4. 保存并测试!
  1. After the component is saved, Add an action to your loop:
  2. From now on, at the very bottom of your actions, you'll see a brand new 'Components' section, and in your case, you should only have one now. Select it to call it for each item:
  3. Last step will be to fill in the parameter to pass to this component, which is obviously the list_item you're currently on, or whatever the computer name of the current item was if you changed it.
  4. Save and test!

哇!有点复杂,但我希望它能使您朝正确的方向前进!

Whew! It's a little complicated, but I hope it puts you in the right direction!