uc_stock_skus does not use option weights

Project:Ubercart Contributions
Component:Code
Category:
Priority:normal
Assigned:Unassigned
Status:active
Description
Project: 
Ubercart

uc_stock_skus does not return SKU's in the order of option weights if SKU's are added to the options of a product.
I use this for theming, the order is now different from the dropdown list of options.

Thanks!

Kees

Version: 
Ubercart 1.6
qrios's picture
Offline
Cool profile pic award.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 554
Still applies on 1.6. The

Still applies on 1.6.

The SKU's are loaded from uc_product_adjustments table.
The weights are stored in uc_product_options table.

So, I want this...:

function uc_stock_skus($nid) {
  $node = node_load($nid);

  if (is_null($node->model)) {
    return FALSE;
  }

  $skus = array($node->model);

  if (module_exists('uc_attribute')) {
    $models = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
    while ($model = db_fetch_object($models)) {
      if (!in_array($model->model, $skus)) {
        $skus[] = $model->model;
      }
    }
  }

  return $skus;
}

...to return the array sorted by the "weight" column of the uc_product_options table.

It's very strange to have the options displayed in the order of inserting, not in the order of option weights.

qrios's picture
Offline
Cool profile pic award.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 554
Cant sort options stock levels properly

I tried to workaround this by joining tables.
There is no way to link the order of the options to the stock levels or vice versa. This is a pity at least.

The uc_product_options table contains the ordering column.
The uc_product_stock table contains the stock column.

I can join data on NID, but NID is not unique per option. The uc_product_options table identifier is OID, The uc_product_stock table identifier is SKU. There is no way to link them together afaik.
I think the OID should be saved in the uc_product_stock table.

Please help!

cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 422
Re: Cant sort options stock levels properly
Assigned to:qrios» cha0s

In principle, it sounds like a pretty nice idea, but in practice it can easily become too complex; in the case of having like 3 attributes whos' options combine to form many many permutations of models, how can we sort based on option weight in this case?

BTW, as of 2.x, a new function has been added: uc_product_get_models() it is used in this spot and others, and its result array is sorted alphabetically.

Try FreeBASIC!
My game Lynn's Legacy

qrios's picture
Offline
Cool profile pic award.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 554
Re: Re: Cant sort options stock levels properly
Assigned to:cha0s» qrios

You are absolutely right, didn't think of it. This is not the case in the project I'm working on though.
I found myself an ugly workaround by using the OID in the serialized "combination" data in the "uc_product_adjustments" table to join the SKU/option weight together. Executing sql queries in a loop Sad.

Thanks for pointing out the new 2.# function.