Conditional actions not allowing Adjustment SKU selection

thill_ - June 23, 2009 - 19:36
Project:Ubercart
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Island Usurper
Status:closed
Issue tags:CA, Release blocker, ubercamp sprint
Description

In this wonderful code below we are not returning adjusted skus.
Perhaps this is a feature request vs a bug, but allowing actions on all skus seems important.

function uc_order_condition_has_products_form($form_state, $settings = array('required' => 0, 'forbidden' => 0)) {
  $form['required'] = array('#type' => 'radios',
    '#title' => t('Require selected products'),
    '#options' => array(
      0 => t('Order has any of these products.'),
      1 => t('Order has all of these products.'),
    ),
    '#default_value' => $settings['required'],
  );
  $form['forbidden'] = array('#type' => 'radios',
    '#title' => t('Forbid other products'),
    '#options' => array(
      0 => t('Order may have other products.'),
      1 => t('Order has only these products.'),
    ),
    '#default_value' => $settings['forbidden'],
  );
  $options = array();
  $result = db_query("SELECT nid, model FROM {uc_products}");
  while ($product = db_fetch_object($result)) {
    $options[$product->nid] = $product->model;
  }
  $form['products'] = array('#type' => 'select',
    '#title' => t('Products'),
    '#options' => $options,
    '#default_value' => $settings['products'],
    '#multiple' => TRUE,
  );
  return $form;
}

#1

rszrama - June 29, 2009 - 16:31
Issue tags:+ubercamp sprint

#2

cYu - June 29, 2009 - 16:54
Assigned to:Anonymous» cYu

#3

cYu - June 29, 2009 - 18:39
Status:active» needs review

This patch allows for the SKU to be specified instead of the nid when using the "Check an order's products" condition. The only downside to this is that someone who previously had a product with 100 different skus for one product would have previously been able to select just the nid but will now need to select all 100 skus in their condition.

AttachmentSize
has_model.patch 1.6 KB

#4

Island Usurper - July 2, 2009 - 21:16

Hmm. There is a function for us to use to find all of the possible SKUs that a product has. This can kind of future-proof this condition a little bit. But it looks not nearly as efficient as just reading the adjustments table directly.

What do you guys think?

AttachmentSize
condition_has_product_model.patch 1.15 KB

#5

cYu - July 7, 2009 - 15:52

Lyle, I think your method is worth the overhead. I didn't like doing a module_exists for uc_attribute and querying directly since any other contrib module could work the same way in adjusting and creating new SKUs, but was unaware of uc_product_get_models().

#6

cha0s - July 7, 2009 - 17:10
Status:needs review» needs work

The drupal_map_assoc() isn't necessary, because product_get_models() does it for you. Also, the 'Any' model should be masked out.

#7

Island Usurper - July 7, 2009 - 17:40
Status:needs work» needs review

Ah, yeah. Good call.

AttachmentSize
condition_has_product_model.patch 1.2 KB

#8

sammys - July 11, 2009 - 21:17

Updated the patch to use += instead of array_merge(). Also changed uc_product_get_models() to a more suitable form by adding the $add_blank parameter.

AttachmentSize
500134_200907111714-0400.patch 2.67 KB

#9

Island Usurper - July 13, 2009 - 18:50

I don't know that we need to allow the "Any" option to be any string that is passed in. Either way, t() isn't supposed to be used on variables, just string literals. Patch reflects this change.

This condition that we're working on is really similar to the one that checks the number of a particular product in an order. Are they similar enough that we ought to combine them? I could write an update function to change people's predicates that use one to the use the other.

AttachmentSize
500134_model_condition.patch 2.76 KB

#10

sammys - July 21, 2009 - 17:48

The ability for any caller to select the string placed at the top of the list is important for reusability. Other modules (outside of core) may want to put something different there. Core really should allow the default string to be modified with all lists affected. This is a small step towards a solid API.

No argument regarding the t() call.

#11

sammys - July 21, 2009 - 18:17
Status:needs review» needs work

Forgot to change to needs work.

#12

Island Usurper - July 21, 2009 - 19:59
Status:needs work» needs review

Allows for the blank value to be passed in, but uses t() only on literal strings.

AttachmentSize
500134_model_condition.patch 2.43 KB

#13

rszrama - September 9, 2009 - 20:40
Issue tags:+Release blocker

#14

Island Usurper - September 15, 2009 - 21:40
Assigned to:cYu» Island Usurper

I was looking over this and was just about ready to commit it when I realized it needed an upgrade path. Everybody's predicates that use this condition would suddenly stop working, or be pointing at the wrong products, when their settings have nids, but the callback expects model numbers.

This update was a bear to write because conditions are stored in a tree structure, and that inevitably requires some kind of recursive walk through the array. The helper function that is added will probably be abstracted out whenever we need to fix another condition's settings, but that will certainly wait until later. In other words, let's not do anything else like this for a while. ;)

AttachmentSize
500134_model_condition.patch 3.22 KB

#15

Island Usurper - September 16, 2009 - 18:16

Somehow, I left out the changes to uc_product.module in that last patch. Here it is again, along with a fix so that the form field will actually display all of the SKUs.

AttachmentSize
500134_model_condition.patch 5.47 KB

#16

Island Usurper - September 16, 2009 - 18:26
Status:needs review» fixed

And it tests out OK. This isn't something that will scale very well, but it'll do well enough for now. Committed.

#17

System Message - September 30, 2009 - 18:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.