Using Display Manager there is the possibility to order the product.
I've try to move the product inside the list but doesn't work.
If I show the row weights every single product have 0 and also if I try to modify it when I save remain 0.
How I can modify the row weight?

CommentFileSizeAuthor
#3 1363542-admin-sorting-fix.patch3.29 KBfonant

Comments

andrea.brogi’s picture

Assigned: andrea.brogi » Unassigned
fonant’s picture

I have this too. If you re-order the products in the Display Manager list, the order is saved with suitable deltas. And the list is generated with the products in the correct order according to delta.

But the row weight widgets all have zero as their default, so when you save again, all the deltas get set to zero.

OK, here's the fix. Change this:

            'delta' => array(
              '#type' => 'weight',
              '#title' => t('Delta'),
              '#title_display' => 'invisible',

to this:

            'delta' => array(
              '#type' => 'weight',
              '#title' => t('Delta'),
              '#title_display' => 'invisible',
              '#delta' => $products_result_count,
              '#default_value' => $key

The #delta setting means the field will always have enough numbers in the select to show as many product deltas as there are products.

The #default_value setting simply uses the $key, as the sorting is done as deltas counting up from zero, and the products are already sorted by delta value.

Arghhh... while that fixes the problem on loading the page, when you sort using JavaScript all the weights/deltas get set wrongly, as the sorting is assuming one single table...

fonant’s picture

StatusFileSize
new3.29 KB

OK, fixed that, it just needed grouping, and one drupal_add_tabledrag() per group. I simply incremented the group number for each product display node, you could use the display node's ID instead.

Patch for this attached.

So now the drag-sorting works properly.

Final problem is that the products are NOT, in fact, sorted correctly in the admin table. While the list of products from _commerce_pdm_get_products_referenced() is in the correct order, this order is lost when the next query to get the product titles is performed.

The code needs to be re-factored quite a bit to fix this.

fonant’s picture

Priority: Normal » Major

Raising priority, as with lots of products this failure to remember the sort order on the admin page is quite a problem.

tugis’s picture

Fonant, I applied your patch successfully, but it's not working :/
Sorting is still wrong.

fonant’s picture

Yes, as I said, the code needs a bit of a re-write so that the sort order from the database can be used in the Display Manager list. My patch fixes the JavaScript sorting behaviour, but doesn't enable the sort values to get into the list when the page is first constructed.

netsensei’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not quite sure what this patch is trying to fix here. Do you mean that the product display manager delta's don't map to the delta's of the product reference field on the product display nodes? I've played a bit with reordering the products with 7.x-1.x-dev but I don't see any problems there when saving and re-saving the form.

Some more input needed!

sanchezduran’s picture

Status: Postponed (maintainer needs more info) » Active

Within the administration panel of product display manager, when you order different products within a node display it work, but when I reloaded the page is not displayed in the order saved but it was in before saving.

Sorry for my english

netsensei’s picture

Priority: Major » Normal

Okay. So when saving the product display from the manager, the order gets ignored. I don't think this is a major blocker, but I'll investigate nonetheless.

netsensei’s picture

Status: Active » Postponed (maintainer needs more info)

Hm. I can't seem to reproduce this problem. I've been toying with this and checking delta's in the database tables of the referencing fields, but I don't see any problems there. Changes are saved correctly.

I'm now explicitly retrieving the delta from the database and passing it to the delta form element as a default_value, as per #2. I'm not sure changing the tabledrag would add more value.

Commit ref:
http://drupalcode.org/project/commerce_product_display_manager.git/commi...