0

I use drupal commerce. I have several entityform type. Each product has entity reference to one of these forms. How to page redirect to referenced form url when a product added to cart.

Thanks

1 Answer 1

1

You want to use Rules for this. It should already be installed since Drupal Commerce requires it.

Create a new rule by going to Admin > Config > Workflow > Rules, and click Add rule.

A rule consists of 3 parts.

The event, the action that triggers the rule.

The event that initiates the rule would be After adding a product to the cart.

The conditions, the checks to make sure the rule applies.

Use this to find your reference field;

Add a rule entity had field and check if the commerce_line_item (I suppose you get that by default) has a field commerce_product. Then add a second check to see if commerce_line_item:commerce_product has a field entity_reference.

Depending on where you created the field you might require several layers.

The actions, what to do if the rule is valid.

You want to use the Page redirect action in the system group. Make sure to click the data selector button, then you can search the redirect path. It suppose should look something like commerce_line_item:commerce_product:field_reference:url.

9
  • Hi. [commerce-product:field_reference] gets the form name as url but [commerce-product:field_reference:url] doesn't get the form url. Page redirected to front page
    – mtin -nong
    Commented Dec 23, 2015 at 19:23
  • The names are different as per you installation. Use the data selection widget (the auto fill input) to find the exact names. If the first provides a url, use it to do the redirect. Commented Dec 23, 2015 at 20:05
  • data selector does not provide :url. I can enter only with direct input. May :url token unsupperted for entity form via entity reference? Forms url data looks like this: "weight" : "0", "paths" : { "submit" : { "source" : "eform\/submit\/form-3", "alias" : "the_url_i_need", "language" : "und" } }
    – mtin -nong
    Commented Dec 23, 2015 at 20:32
  • can you get the id of the entity form? You might need to use an action to load the entity by id first. Perhaps the url will become available then. Order does matter, so make sure this action is performed first. If the data selector does not have it, it does not exist. Commented Dec 23, 2015 at 20:37
  • [commerce-product:field_reference:id] works without load the entity by id but [commerce-product:field_reference:url] doesnt work with or without load the entity by id and still url token not provided by data selector.
    – mtin -nong
    Commented Dec 23, 2015 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.