Would it be possible to expose the 'Commerce node checkout' field created on nodes to the Conditional Fields module?

Case:
We have a node A for which an author can choose from the listing options 1. basic listing or 2. featured listing. If a featured listing is chosen, additional fields are exposed to the author (eg. homepage/slideshow image).

Comments

mstef’s picture

Status: Active » Postponed (maintainer needs more info)

Why does anything have to be done inside this module for that to work?

It also sounds like your conditional fields have nothing to do with the fields that this module adds to nodes..

semei’s picture

In fact, I would also be interested in this feature. It would be very cool if one could have the field that lets you select the product you want to buy in order to publish the node ("basic" or "featured") recognized as a dependee by Conditional Fields Module. But I am also not sure if this would have to go into the code of Conditional Fields Module.

kopeboy’s picture

Status: Postponed (maintainer needs more info) » Needs review

I am very interested in this too.
My usecase is this:

A customer wants to list his business on my website.
Because there are many business categories, but the fields for each are similar, a different content type for each is not feasible. I then use a taxonomy term and place a Term reference field called "Category" in my content type "Business".
Each "Category" of "Business" must have a different price.
How to do this?

I tried placing the same term reference field in my product of type "Pay to publish", but then nothing new shows up on my "Business" content type fields, thus I cannot set any dependency with Conditional Fields (that would have meant something like checking for the "Commerce node checkout term reference" field having a value, and setting the Term reference field "Category" to the same value).

I haven't much experience yet with Commerce (was using Ubercart in past projects) so I don't know if something similar can be achieved involving the Line item.
Any help would be greatly appreciated.

EDIT: I also tried using Rules but the provided "Order has nodes" condition won't let me select any Data related to the node afterwards, only order and line items.
Basically I am trying to set the field "Category" value of my "Business" content type based on the product selected (with the select list provided by this module) during the creation. Is this possible currently?

kopeboy’s picture

Category: Feature request » Support request

If this isn't possible currently, neither with rules nor with reference fields and Conditional fields, we can change back to Feature request.

mstef’s picture

Status: Needs review » Active
gateway69’s picture

I was also looking for this type of option where you have various conditional fields that populate based upon price. Btw has anyone tried it to see if this works.. I would assume the following should work.

Payment Type = x

Display group fields a,b,c

Payment Type = y

Display groups fields x,y,z

This allows the user to fill out these fields based upon what conditions are met in the conditional fields.

Im assuming then when the node is saved you would need to make sure that when they go edit the field again (if they are allowed) that you need to lock the select list for the payment so the conditional fields continue to work.

Otherwise I would suggest this work flow as well.

create x content types .. (clones of each other but with the various options you need per type).. On Node / Create use some sort of multi page wizard that first asks you for the payment type, then when they hit next they are displayed with the form based upon their payment type.

thoughts, suggestions ?

Infoloko’s picture

I too need this sort of functionality and it seems somewhat absurd that you can use an add form to select a node to purchase but then not be able to control (on the same add form) what is on that node.

my use case is similar to those above - I have a node that can have variable contents (quantity of text, number of image(s) and varying expiration), basically the more they want on the node the more they pay. The first action of the purchaser is to select what they want ("Listing Option") and then fill in the relevant fields BUT how to make the "Listing Option" control which data fields are available? Use of Conditional Fields would seem to be a reasonable method.

The multi-page approach might work although would that mean the node being in the checkout without any content (assuming the 1st page actions the 'Commerce node checkout' field before displaying the relevant add node page)? What happens if the user cancels from the add page? Food for thought!

Infoloko’s picture

I've managed to figure out a work-around (not elegant but at least it works) that allows conditional fields to work with 'Commerce node checkout' (CNC)

The problem seems to be that CNC does not expose a field (which Conditional Fields needs) but instead uses the Fields API to create elements.

The work-around adds a non-displayed field to the content type containing CNC then uses jQuery to copy the CNC value.

In the following steps XXXXXXX is your module name...So..

1. on the content type add a new text field "commerce-node-checkout-val" and set css for this to "display:none"

2. in your module folder create a XXXXXXX.js file containing the following

(function ($) {
    
Drupal.behaviors.XXXXXXX = {
    attach: function(context, settings){
        $("#edit-commerce-node-checkout-product").change(function() {
            var selected_text = $("#edit-commerce-node-checkout-product option:selected").text();
            $("#edit-field-commerce-node-checkout-val-und-0-value").val(selected_text).change();
            }).change();
        }};
})(jQuery);

3. in your module use hook_form_alter, add the following for the zzz_node_form that you're using:

$module_path = drupal_get_path("module","XXXXXXX");
$form['#attached']['js'] = array($module_path . '/XXXXXXX.js');

Done .. you can now use conditional fields with the newly added but not displayed "commerce-node-checkout-val" field -- the only pain is getting the correct contents but turn the display back on and you can cut/paste these values across). Hope that helps anyone desperate for a way to get this functionality!

pancho2jr’s picture

Aparato thanks this code work for me

tuthanh’s picture

Thanks Aparato, it works for me #8.

hoff331’s picture

I also need this functionality but am hoping we can implement a 'cleaner' solution, similar to MoneyScripts.net's premium "Pay to Publish" module (see https://www.moneyscripts.net/tutorials/pay-publish/pay-publish-fields-in...).

On the Commerce Node Checkout module's project page, it reads "visit our site if you're interested in sponsoring paid enhancements". Perhaps we could pool some funds and make a donation to Lee?!?

Thoughts?

thecramp’s picture

Hi ,
Aparato i’d like to try your solution but, i have some problems,

- Do we have to make a new module ? or we use the commerce node checkout module ?
- For Step 2 ok, i create a new file
- Step 3 , don’t understand where we put this code ?

Can you give me more information please ?
thanks kid regards

tuthanh’s picture

#8 works well. Thank you Aparto.

I have another problem. This piece of code works well for new submission. But for re-listing (when the node is expired and we renew it), the value is set and it can't be changed via the javascript.

Can you adapt the code to handle this case as well?

vaccinemedia’s picture

Here's a no code required solution. Say that you have a content type called "event" and you have 2 pay to publish options: FREE and Paid. The free option has title, body and date as available fields, but you want the paid event to also include an entity reference to a venue, an image, a video etc....

In dependencies, select the field you want to hide e.g. the video field as the dependant and any field e.g. the title field (if using the title module) as the dependee and click "Add dependency".

On the config screen select Values input mode = All these values (AND) and in the set of values enter the number of the product you want to trigger the field being shown. You can find this out by inspecting the select on the node add page - each product option has a numeric key and as the paid option is the second option in this case simply enter 2 into the "Set of values" field.

In Advanced edit context settings, enter the jQuery selector for the select field:
[name="commerce_node_checkout_product"]

Save and that should be it. The field will be hidden until the second product (the paid one) is selected.

morybel’s picture

Thank you so much vaccinemedia, this is a life saver! It's a perfect solution, I just needed to add the Title module in order to make everything word.