2

How might it be possible to get Commerce-Product-Display information in a Commerce-Order object?

The issue is I need to publish a Commerce-Product-Display node when a user has made a payment to publish the node. I am using Rules to detect the payment and attempt to publish the node.

My problem is, because the Completing the checkout process Rules event only has data for a Commerce-Order, and the Commerce-Order does not have information for the Product nor the Product display, I am unable to publish the node.

halfer
  • 19,824
  • 17
  • 99
  • 186
sisko
  • 9,604
  • 20
  • 67
  • 139

2 Answers2

3

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:

  • the line-items that are attached to your order will contain your products and
  • you will need to use a rule component, in order to be able to have an additional 'condition-action' combo inside your rule action

Here is how to do it:

  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.

    enter image description here

  3. 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!!

  4. 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

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

  6. 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.

enter image description here

  1. Add two conditions to your component (or whatever checks you think are necessary). I added 'Entity is of type' => Commerce Line item and 'Entity has field' => commerce_product. So this runs for all my products at the moment.
  2. The condition I set on my component is to send an email, and I filled in the following for the body of the email: [line-item:commerce_product], and it prints out the product's name beautifully in the email each time I've tested checking out!

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

  1. After the component is saved, Add an action to your loop: enter image description here
  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: enter image description here
  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!

Community
  • 1
  • 1
Boriana Ditcheva
  • 1,995
  • 15
  • 26
  • Saying thank-you will be inadequate but thank-you anyway. I am very grateful for your detailed response and helping me solve my problem :-) – sisko Jul 25 '13 at 20:40
  • No problem - it's kind of confusing getting into Drupal Commerce, so I'm glad you're figuring things out. ;-) – Boriana Ditcheva Jul 25 '13 at 20:55
1

The way rules work in Drupal is that not all fields are shown for your entity by default in the actions. What you need to do is prompt Rules to recognize your object as a certain type of node in order for the Rule to add all of its appropriate fields.

You can do this either by

  • using the 'Content is of type' under the Node section check (and select your Commerce Display node type or
  • directly using the 'Entity has field' check under the Entities section to check for a specific field you want to use.

Either of those should prompt Rules to recognize the type of entity you're working with and populate the Actions with the necessary fields.

Let us know if this works!

Boriana Ditcheva
  • 1,995
  • 15
  • 26
  • Thank you for your detailed response. However, my Rule executes on the "Completing the checkout process" event. As The event is not based on a content type I can't include appropriate fields as you described. "Entity has field" is also not very clear forward in solving this problem as I am trying to find the product date related to the Order. As it's not there, entity has field is not likely to work - unless I am missing something – sisko Jul 23 '13 at 20:16
  • Hmm, I think I got confused by this part of your question: "I found it has no data relating to the Commerce-Product nor the Commerce-Display entities". Because of that I assumed that you were working with the product or product display already, but just couldn't see their fields. If your rule is triggered on 'adding a product to the cart' or some other such rule, you should be able to get the product. In any case, so is your question actually that you don't know how to get TO THE PRODUCTS in your cart or how would you re-phrase it? – Boriana Ditcheva Jul 23 '13 at 20:49
  • Thank you again Boriana. I have rephrased my question. I hope it is clearer – sisko Jul 23 '13 at 21:54
  • OK, I have a new answer below, but this answer still contains important information about GETTING to the fields in your products if you can't see then once you have your hands on the product. :-) Good luck! – Boriana Ditcheva Jul 24 '13 at 19:51