Advertisement
wizonesolutions

Unfinished patch to uc_attribute_clone

Jun 8th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <?php
  2. // $Id: uc_attribute_clone.module,v 1.2 2009/07/13 17:54:39 longwave Exp $
  3.  
  4. /**
  5.  * Implementation of hook_help().
  6.  */
  7. function uc_attribute_clone_help($path, $arg) {
  8.   switch ($path) {
  9.     case 'admin/help#uc_attribute_clone':
  10.       $output = '<p>'. t('Attribute clone works with the node clone and Ubercart attribute modules to copy product attributes and options when a node is cloned.') .'</p>';
  11.       return $output;
  12.   }
  13. }
  14.  
  15. /**
  16. * Implementation of hook_clone_node_alter().
  17. */
  18. function uc_attribute_clone_clone_node_alter(&$node, $original_node, $method) {
  19.   if (in_array($node->type, module_invoke_all('product_types'))) {
  20.     if ($method == 'prepopulate') {
  21.       $node->uc_attribute_clone = $original_node->nid;
  22.       if (empty($_POST['op'])) {
  23.         drupal_set_message(t('Product attributes, options, and configured features will be copied when you submit.'));
  24.       }
  25.     }
  26.   }
  27. }
  28.  
  29. /**
  30. * Implementation of hook_form_alter().
  31. */
  32. function uc_attribute_clone_form_alter(&$form, $form_state, $form_id) {
  33.   if (isset($form['type']['#value']) && $form['type']['#value'] .'_node_form' == $form_id) {
  34.     if (isset($form['#node']->uc_attribute_clone)) {
  35.       $form['uc_attribute_clone'] = array(
  36.         '#type' => 'hidden',
  37.         '#value' => $form['#node']->uc_attribute_clone,
  38.       );
  39.     }
  40.   }
  41. }
  42.  
  43. /**
  44.  * Implementation of hook_nodeapi().
  45.  */
  46. function uc_attribute_clone_nodeapi(&$node, $op) {
  47.   if ($op == 'insert' && isset($node->uc_attribute_clone)) {
  48.     db_query("DELETE FROM {uc_product_attributes} WHERE nid = %d", $node->nid);
  49.     db_query("DELETE FROM {uc_product_options} WHERE nid = %d", $node->nid);
  50.     $features = uc_product_feature_load_multiple($node->nid);
  51.     // Delete any associated with the clonee first - unlikely
  52.     foreach ($features as $pfid => $feature) {
  53.       uc_product_feature_delete($pfid);
  54.       // This is tricky because product features are often modules in their own
  55.       // right. Thus, we have to call the associated functions manually.
  56.       // This is known to work with uc_roles.module but hasn't been tested with
  57.       // all product feature modules and may need refinement.
  58.      
  59.       $form_state = array();
  60.       $this_form = drupal_get_form($feature['callback'], $form_state, $feature);
  61.       // Stick everything into $form_state in preparation for drupal_execute();
  62.       foreach ($form
  63.     }
  64.     db_query("INSERT INTO {uc_product_attributes} (nid, aid, ordering, required, display, default_option) SELECT %d, aid, ordering, required, display, default_option FROM {uc_product_attributes} WHERE nid = %d", $node->nid, $node->uc_attribute_clone);
  65.     db_query("INSERT INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) SELECT %d, oid, cost, price, weight, ordering FROM {uc_product_options} WHERE nid = %d", $node->nid, $node->uc_attribute_clone);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement