3 replies [Last post]
yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294

I have the organic group (og) subscribe module working
http://drupal.org/project/uc_og_subscribe

I have also figured out how to use migrate (migrate_og) and tablewizard to import my 100+ groups.

What is a practical way to manage this? I'm interested because it is interesting to figure out the "right" drupal way of doing things, and also because, even after I get my site set up with my (less than 200) groups, I'm going to be sharing the site with other local organization I partner with, and they are going to be setting up their sites, with there own different set of groups! So this site set up will need to be done quite a few times.

I think ideally, on import of a cvs file describing the groups it would [it. what is it here. maybe my own module, I just did http://drupal.org/node/735714#comment-2694462, or is it a rule]:
a* set up the attribute option values for the one product we have: "join". in the join product, there is an attribute (pull down) to select the groupname. each option value is a groupname.

b* for og groups who have a certain category (taxonomy) of active [vs closed] those groupnames would be enabled in the product options (eg. node/19/edit/options)

c* set the sku in the adjustments to something like 1001-groupname

d* add a group subscription feature (node/19/edit/features) for each sku linking 1001-whatevergroupname to the og group groupname

I've used rules a bit lately, so I'm wondering if rules can be used to do any of this.
Even something like:

tigger: create new node type group (that is what my migrate import does)
action: a-d, etc. might be some built in actions that would work, or use the execute php action

I suppose also I would need something for when a group changes from active to closed:
e* disable the product option

And maybe some like when a group is deleted:
f* remove the attribute option
I'm guessing I wont have to disable the option for the product [coresponding to b*, because the option will be removed, so it wont be listed anyway. And same for c*: there wont be an adjustment, hmmm what about d* the feature? I guess if the attribute option value is removed, I wont have to worry about the feature either... Hmm. I just tried it. I manually deleted an option value for groupname: MyCity, which did take care of c* the were no adjustments then for setting the sku of the product with that option, because the option was gone. BUT, the feature was still there which said to look for the sku 1001-MyCity. Also interesting, I did delete the actual og group, and the feature is still there to saying: MyCity is the group to subscribe to. If I edit the feature, then sku pull down menu does not list the old adjustment (because it is deleted) and it does not list the old group (because it is deleted)... but the old feature is still there, "trying" to do stuff based on a sku that does not exist, to a group that does not exist.

Well. There are some thoughts recorded so I dont forget them, and also to see what others have to say. Thanks.

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: practical advice for setting up large amount of organic grou

worked through some of this here:
http://www.ubercart.org/forum/support/15840/api_adding_option_attribute_...

and more here:
http://drupal.org/node/745794

with a patch I suggested (in that same issue)
http://drupal.org/node/745794#comment-2744626

and here is a rules export:

array (
  'rules' =>
  array (
    'rules_6' =>
    array (
      '#type' => 'rule',
      '#set' => 'event_node_insert',
      '#label' => 'create a ubercart option value for a group on group node creation (adding a  group)',
      '#active' => 1,
      '#weight' => '0',
      '#categories' =>
      array (
      ),
      '#status' => 'custom',
      '#conditions' =>
      array (
        0 =>
        array (
          '#type' => 'condition',
          '#settings' =>
          array (
            'type' =>
            array (
              'group' => 'group',
            ),
            '#argument map' =>
            array (
              'node' => 'node',
            ),
          ),
          '#name' => 'rules_condition_content_is_type',
          '#info' =>
          array (
            'label' => 'Created content is Group',
            'arguments' =>
            array (
              'node' =>
              array (
                'type' => 'node',
                'label' => 'Content',
              ),
            ),
            'module' => 'Node',
          ),
          '#weight' => 0,
        ),
      ),
      '#actions' =>
      array (
        0 =>
        array (
          '#weight' => -4,
          '#info' =>
          array (
            'label' => 'Execute custom PHP code to add the option',
            'label callback' => false,
            'module' => 'PHP',
            'eval input' =>
            array (
              0 => 'code',
            ),
          ),
          '#name' => 'rules_action_custom_php',
          '#settings' =>
          array (
            'code' => ' module_load_include(\'inc\', \'uc_attribute\', \'uc_attribute.admin\');
$form_state = array();
$myaid->aid=2;
$form_state[\'values\'][\'name\'] = check_plain($node->field_groupname[0][\'value\']);
drupal_execute(\'uc_attribute_option_form\', $form_state, $myaid);',
            'vars' =>
            array (
              0 => 'node',
            ),
          ),
          '#type' => 'action',
        ),
        1 =>
        array (
          '#weight' => 0,
          '#info' =>
          array (
            'label' => 'Show a configurable message on the site and enable the option on the membership product',
            'label callback' => false,
            'module' => 'System',
            'eval input' =>
            array (
              0 => 'message',
            ),
          ),
          '#name' => 'rules_action_drupal_message',
          '#settings' =>
          array (
            'message' => 'Added the group name <? echo $node->field_groupname[0][\'value\'] ?> for nid <? echo $node->nid ?> to the list of groups in the join product drop down (attribute 2) option list.  <?
$myaid->aid=2;
$myproductid=19; 
$myoptionname = $node->field_groupname[0][\'value\'];
$result = db_query("SELECT myoptions.oid FROM {uc_attribute_options} myoptions WHERE myoptions.name = \'%s\' AND myoptions.aid = %d", $myoptionname, $myaid->aid);
if ($row = db_fetch_object($result))
{
  $myfirstmatchingoid=$row->oid;
  echo "Option id matching that name is: ";
  echo $row->oid;
  echo ". ";
  $productresult = db_query("SELECT myprodoptions.oid FROM {uc_product_options} myprodoptions WHERE myprodoptions.nid = %d AND myprodoptions.oid = %d", $myproductid, $row->oid);
  if (db_fetch_object($productresult)) {
    echo "The option was already enabled. Contact developer. ";
  } else {
    db_query("INSERT INTO {uc_product_options} (nid, oid) VALUES (%d, %d)", $myproductid, $row->oid);
    echo "Enabled option $row->oid on product (node) $myproductid";
    echo ". ";
  }
  if ($row = db_fetch_object($result))
  {
    echo "Oops and there were other options matching that name: ";
    echo $row->oid;
    while ($row = db_fetch_object($result))
    {
      echo " ";
      echo $row->oid;
    }
    echo ". ";
    echo "Having more than one option with the same name is going to cause problems. Contact a developer and delete the group you just made. Create a new group with a slightly different name.";
  }
  $node->field_storeoptionid[0][\'value\']=$row->oid;
  node_save($node);
}
else {
echo "no options found with that name. something is really wrong. contact developer.";
}
//now set the adjustments skus so later the feature of automatically joining can be done
$myadjleveloidarray = array ( 1 => \'1\', 2 => \'2\', 3 => \'3\', 4 => \'4\', 5 => \'5\', 6 => \'6\', 7 => \'7\', 8 => \'8\', 9 => \'9\', 10 => \'10\',);
$myadjoid = $myfirstmatchingoid;
foreach ($myadjleveloidarray as $aleveloid)
{
  $myadjarray = array(
    1 => $aleveloid,
    2 => $myadjoid,
  );
  $mycomb=\'\';
  $mycomb=serialize($myadjarray);
  $mymodel="1001-" . $node->field_groupname_codeunique[0][\'value\'];
  db_query("INSERT INTO {uc_product_adjustments} (nid, combination, model) VALUES (%d, \'%s\', \'%s\')", $myproductid, $mycomb, $mymodel);
}
echo " Made the adjustments to the sku. ";

module_load_include(\'inc\', \'uc_og_subscribe\', \'uc_og_subscribe.ca.inc\');
$form_state = array();
$form_state[\'values\'][\'uc_group_gid\'] = $node->nid;
$form_state[\'values\'][\'uc_group_model\'] = $mymodel;
$form_state[\'values\'][\'nid\']="19";
$myemptyfeature=array();
$productnode=node_load($myproductid);
drupal_execute(\'uc_og_subscribe_feature_form\', $form_state, $productnode, $myemptyfeature);

echo "added the feature to product $productnode->nid";
?>
',
            'error' => 0,
            '#eval input' =>
            array (
              'rules_input_evaluator_php' =>
              array (
                'message' =>
                array (
                  0 => 'node',
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
)

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: Re: practical advice for setting up large amount of organic

I'm trying to pull my thoughts together. Now... do I automate undoing all the stuff I did for deleting a group?!?!

Well, http://drupal.org/node/743678 is a step in that direction, trying to save the option id on the group node, I would probably want to save the feature id too. Then I could delete the pull down in the product for the group name, and the auto subscribing to the group feature when a group is deleted.

I'm not really expecting to delete groups too often, maybe I'll just change them to "inactive" ... but I would still want to remove the names from the pull down on the product ....

well. I'll let my mind rest now for a while!

sandeepkeswani's picture
Offline
Joined: 08/11/2011
Juice: 3
add Group Subscribe feature to ubercart product

Hello YesCT,

I've been following your posts thoroughly here and the links provided for drupal.org posts. I'm facing some problem in automating the steps for adding "Group Subscription" feature to newly created product. Here is what i'm trying to execute as the custom php code:

module_load_include('inc', 'node', 'node.pages');
module_load_include('inc', 'uc_attribute', 'uc_attribute.admin');
module_load_include('inc', 'uc_og_subscribe', 'uc_og_subscribe.ca.inc');
$form_state = array();
$form_state['values']['uc_group_model'] = $node->model;
$form_state['values']['uc_group_gid'] = $node->nid;
$form_state['values']['uc_group_description'] = 'no description';
$form_state['values']['uc_group_active'] = '1';
$form_state['values']['uc_group_admin'] = '1';
$form_state['values']['uc_group_retro_add'] = '1';
$form_state['values']['op'] = t('Save feature');
$myemptyfeature=array();
$productnode=node_load($node->nid);

drupal_execute('uc_og_subscribe_feature_form', $form_state, $node, $myemptyfeature);

I'm not able to understand where am i going wrong. The code part that you contributed for help here: http://drupal.org/node/745794#comment-2744604 included setting up of options and attributes as well, so i left that part and took the part associated with assigning the "Group Subscription" feature. I also applied the patch that you contributed, but still i'm getting the error: "An illegal choice has been detected. Please contact the site administrator."

Can you please help me out on this.

Thanks & Regards
Sandeep Keswani