Followup to #2716417: Allow rendering of variation fields on the product entity..

We need to implement a derivative DsField plugin that provides a plugin definition for each renderable field.
Since DsField plugins can have settings, we can ask for the formatter and settings here, and pass them along to the field renderer.

CommentFileSizeAuthor
#3 2723689-3-add-ds-integration.patch7.18 KBbojanz

Comments

bojanz created an issue. See original summary.

bojanz’s picture

Assigned: Unassigned » bojanz

I'm in the mood to tackle this.

bojanz’s picture

Status: Active » Needs work
StatusFileSize
new7.18 KB

Blocked on Ds: #2725077: Rethink DsField settings.

Attaching current code.

zenimagine’s picture

I tested the patch and it works, but:

- when I change the varation of product, the price disappears.

- the labels are displayed twice.

The fields will be displayed for the next update ?

bojanz’s picture

Display Suite never completed the refactoring needed for our patch to work, so don't expect this functionality any time soon.

I generally recommend using pure Twig for your product pages.

zenimagine’s picture

Thank you but I do not know the twig

zenimagine’s picture

Can we bypass the problem by creating a view with the product variation to integrate it to the product page ?

bojanz’s picture

You won't get far without knowing Twig.
Commerce is built to be customized that way.

zenimagine’s picture

Thank you but in my view, the change of variation does not change the price

lonalore’s picture

@zenimagine If you check your browser's inspector, you can see that it tries to update the fields with the following selectors:

{command: "insert", method: "replaceWith", selector: ".product--variation-field--variation_sku__12",…}
{command: "insert", method: "replaceWith", selector: ".product--variation-field--variation_title__12",…}
{command: "insert", method: "replaceWith", selector: ".product--variation-field--variation_price__12",…}

So you should set the proper class on your field elements:

product--variation-field--variation_FIELDNAME__PRODUCTID

zenimagine’s picture

I do not know how to do that. What do I change in my view ?

olegnaumov’s picture

Bojanz, it might be built that way, but trying to find the right variable in dump() of product Twig template has been a very frustrating experience so far.

Is there any documentation or examples?

zenimagine’s picture

it's very complicated. Will there be a fix on the next version display suite ?

olegnaumov’s picture

Regarding Commerce Twig variables: https://www.drupal.org/node/2888382#comment-12150972

It would be nice if there was more Commerce documentation available though...

bojanz’s picture

Documentation doesn't write itself :)

When you figure out the Twig variables, contribute a documentation page to github.com/drupalcommerce/commerce-docs, which is used to build docs.drupalcommerce.org

I'd love to write some myself, but for now it's a bigger priority to solve bugs & missing features on the road to 2.0

adrian83’s picture

I didn't try this module, but maybe this new module or its concept could be useful for using Display Suite to lay out Commerce Product fields. https://www.drupal.org/project/ds_chains. Here is the introduction: https://www.previousnext.com.au/blog/introducing-display-suite-chained-f....

fotograafinge’s picture

Display Suite Chained Fields (see #16) does the trick. Works perfectly for variation fields.

Edit: Display Suite Chained Fields is NOT the answer for variations. When 5 variations, it renders all 5 (for example all 5 prices when you use Variations: Price)

adrian83’s picture

@fotograafinge Thank you for verifying that hunch!

fotograafinge’s picture

@Adrian83: I was too quick in responding. Sadly it doesn't do the trick. I edited my comment.

adrian83’s picture

Too bad :(. Do you mind elaborating on "doesn't do the trick"? Does the Display Suite Chained Fields module only work with nodes, not product entities?

fotograafinge’s picture

@Adrian83: Because you have multiple variations added to a product, the module renders all variations and not only the values for one you select in your add to cart form. So for this issues the ds_chains module is not the solution. But the module works - as designed - with taxonomy terms on nodes which are also entity reference fields (f.e. "Brand: Logo" if you want to show only the logo field of the 'Brand' taxonomy term added to the product type node, not to the variation node).
When you choose an other product in your add to cart for, f.e. a blue shirt, you want to change to image to a blue shirt. In D7 commerce 1.x you could use "Product: Image" in DS, and the image would change if you choose a certain color in the add to cart for on the product display node. Trying to do the same with ds_chains does not work. Hope this explanation is clearer?

zenimagine’s picture

Will the problem be solved with the use of "Layout Builder" ?

bojanz’s picture

Status: Needs work » Closed (won't fix)

It's obvious that Display Suite won't ever be refactored to support our use case, because the community's entire focus is on Layout Builder.

Thus, #2952529: Support for Layout Builder module is our path forward.

osab’s picture

Hi! Maybe this information can be useful if you use the patch 3 :
There is a problem when you have a different product type and variation machine names.
I figured out that in the patch we get variation_id equal as product_id.
So, I needed to make changes in this way ( function getDerivativeDefinitions() )
$variation_type_id = $product_type->getVariationTypeId();

Moreover, DS gets the bundle from the form and it is also is an equal product type:
$bundle = $form['#bundle']
But in your hook__form_entity_view_display_edit_form_alter() you can fix it and set
$form['#bundle'] = $variation_type_id;

tbenice’s picture

To my knowledge layout builder does not allow injection of other data as fields in the display. I think it's a mistake to assume that ds is being abandoned.

For my use I need to be able to inject ds fields into a commerce entity view display full stop. Layout builder doesnt give me this.

adrian83’s picture

@tbenice, Do you mean that you want some content to be displayed on all displays of a product type, and you are wanting to use a DS field to add that content to only the display? If so, Layout Builder allows you to add one-off blocks that display the content on all products of the same product type. If you want to be able to use tokens, use the Token Filter module to create a new text filter. I may not be understanding what you're trying to accomplish.

BigEd’s picture

To me this does not look like an issue you can use Display suite with variations currently, the data won't save for classes in the view mode unless you select at the bottom of the display.

Select a layout : Reset Layout

Then it will work and save values and you can add any custom fields from display suite with any classes you want. You won't be able to use the display columns from the other templates but you can use field groups to make your own or alter the twig template to add your own.

It's an easy workaround to consider.

maxmendez’s picture

@BigEd, if any layout of DS is selected the variation fields are lost.

rolle’s picture

No solution for this yet? Im having the same problem with DS and variations. Same issue when using layout builder.