Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $Id: uc_attribute_clone.module,v 1.2 2009/07/13 17:54:39 longwave Exp $
- /**
- * Implementation of hook_help().
- */
- function uc_attribute_clone_help($path, $arg) {
- switch ($path) {
- case 'admin/help#uc_attribute_clone':
- $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>';
- return $output;
- }
- }
- /**
- * Implementation of hook_clone_node_alter().
- */
- function uc_attribute_clone_clone_node_alter(&$node, $original_node, $method) {
- if (in_array($node->type, module_invoke_all('product_types'))) {
- if ($method == 'prepopulate') {
- $node->uc_attribute_clone = $original_node->nid;
- if (empty($_POST['op'])) {
- drupal_set_message(t('Product attributes, options, and configured features will be copied when you submit.'));
- }
- }
- }
- }
- /**
- * Implementation of hook_form_alter().
- */
- function uc_attribute_clone_form_alter(&$form, $form_state, $form_id) {
- if (isset($form['type']['#value']) && $form['type']['#value'] .'_node_form' == $form_id) {
- if (isset($form['#node']->uc_attribute_clone)) {
- $form['uc_attribute_clone'] = array(
- '#type' => 'hidden',
- '#value' => $form['#node']->uc_attribute_clone,
- );
- }
- }
- }
- /**
- * Implementation of hook_nodeapi().
- */
- function uc_attribute_clone_nodeapi(&$node, $op) {
- if ($op == 'insert' && isset($node->uc_attribute_clone)) {
- db_query("DELETE FROM {uc_product_attributes} WHERE nid = %d", $node->nid);
- db_query("DELETE FROM {uc_product_options} WHERE nid = %d", $node->nid);
- $features = uc_product_feature_load_multiple($node->nid);
- // Delete any associated with the clonee first - unlikely
- foreach ($features as $pfid => $feature) {
- uc_product_feature_delete($pfid);
- // This is tricky because product features are often modules in their own
- // right. Thus, we have to call the associated functions manually.
- // This is known to work with uc_roles.module but hasn't been tested with
- // all product feature modules and may need refinement.
- $form_state = array();
- $this_form = drupal_get_form($feature['callback'], $form_state, $feature);
- // Stick everything into $form_state in preparation for drupal_execute();
- foreach ($form
- }
- 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);
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement