When using this module in combination with the Commerce module the sorting doesn't work with more than 50 product variants in a product display. Currently the weight delta is hardcoded to 50 in the inline_entity_form.module.

Perhaps we can increase the value or don't make it hardcoded?

Comments

bojanz’s picture

#delta is just the maximum delta, and if you don't provide it, it defaults to 10, so there's no "don't hardcode it".
Since we say it's 50, that means you can have weights between -50 and 50, which is 100 in total.

We can add code that allows more, of course (by counting the total number of items or something)

combicart’s picture

That would be great. I know that in theory there should be 100 positions (-50 to 50), but when adding more than 50 variants, the ordering is completely random. Even if you manually rearrange the variants they are only saved once correctly, but when editing the product for the second time the ordering isn't saved and is completely random.

Kiendeleo’s picture

I would recommend that you make this a variable that is configurable from the site admin pages. That way it can be configured as needed. I have a couple of products with 2000+ variations and I have to manually edit this every time there is an update to drupal commerce kickstart.

Kiendeleo’s picture

Version: 7.x-1.0 » 7.x-1.4
Issue summary: View changes
criz’s picture

Title: Increase weight delta » Weight delta only supports ordering of 50 items
Version: 7.x-1.4 » 7.x-1.x-dev
Category: Feature request » Bug report
Priority: Normal » Major
StatusFileSize
new54.07 KB

This is a major issue imho.

Now only the ordering of 50 items is supported (starts at 0 and not -50). When combining some product attributes 50 is just nothing.

What is the consequence of having more than 50 referenced product variations?
The order gets disarranged every time the node is saved. This leads to random default values in the add-to-cart form.

A workaround for now is using hook_form_alter():

<?php
    // Increase delta for product reference field as there can be more than 50 items.
    if (isset($form['field_product'][LANGUAGE_NONE]['entities'][0])) {
      foreach ($form['field_product'][LANGUAGE_NONE]['entities'] as $key => $value) {
        if (is_int($key)) {
          $form['field_product'][LANGUAGE_NONE]['entities'][$key]['delta']['#delta'] = 2000;
        }
      }
    }
?>
dman’s picture

This killed a site managers week here also.
All ordering above 50 was scrambled, and this was being used in a bunch of different places, with lists of several hundred items.
While I appreciate that this particular UI maybe wasn't designed to scale like that (and is awkward with that many items to say the least), the total lossage of the ordering data was ruinous.

Setting it to 50 doesn't really mean 100 - it just means 50 by the time you revisit the editor.
If it can't be unlimited, ( can't it do count($entities) + 10? ) then yeah make it configurable - or at least a lot bigger.

I too did a form alter that's almost the same as @criz above:


/**
 * Update the number of draggable items - we need more than 50.
 *
 * hook_field_widget_form_alter()
 * To modify inline_entity_form_field_widget_form()
 */
function niwa_ui_settings_field_widget_form_alter(&$element, &$form_state, $context) {
  // Based on historical similar issues noted like
  // https://drupal.org/node/1007746
  // it seems we have to change the #delta number in order to allow
  // more items to be dragged and dropped.
  // Oddly it is set on each element, not the tabledrag wrapper.
  if ($context['instance']['widget']['type'] != 'inline_entity_form') {
    return;
  }
  foreach (element_children($element['entities']) as $delta => $entity_entry) {
    $element['entities'][$delta]['delta']['#delta'] = 500;
  }
}

fearlsgroove’s picture

Status: Active » Needs review
StatusFileSize
new1.04 KB
joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Tested out #7 it worked like a charm! Thanks @fearlsgroove!

For testing just created this script:
https://gist.github.com/joelpittet/8adcbcf3626110a2d06c

// test.php
$node_wrapper = entity_metadata_wrapper('node', 17966);
foreach (range(1, 50) as $value) {
  $section_title = entity_create('section', ['type' => 'section_title']);
  $section_title_wrapper = entity_metadata_wrapper('section', $section_title);
  $section_title_wrapper->field_section_title = $value;
  $section_title_wrapper->save();
  $node_wrapper->field_library_sections[] = $section_title_wrapper->getIdentifier();
};
 
$node_wrapper->save();

Change your nid, entity types, field and bundles in the above. I was using an existing eck type with a section title field so I can see the order.

Then I went and added titles like A, B, C, D before and after the patch to see what happened to the order.

Totally fixed my problem:)

garphy’s picture

I just deployed #7 to production. Works great.

pq’s picture

#7 also working fine for me.

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thank you.

  • bojanz committed 566f641 on 7.x-1.x authored by fearlsgroove
    Issue #1876652 by fearlsgroove, criz: Weight delta only supports...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

webflo’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new1.2 KB

We don´t have this issue in 8.x-1.x because if fixed it in 56744aa5 before. But this patch is more in line with 7.x-1.x

  • slashrsm committed 07b2133 on 8.x-1.x authored by webflo
    Issues #1876652 and #2472769 by webflo: Weight delta only supports...
slashrsm’s picture

Status: Needs review » Fixed

Committed to D8. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.