Created
August 8, 2016 14:40
-
-
Save BBGuy/d5460d0ffa451c3d7c8ca6ee41a62ded to your computer and use it in GitHub Desktop.
Create a default producr if one was not set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_form_alter(). | |
*/ | |
function dwwcommerce_form_alter(&$form, &$form_state, $form_id) { | |
// The style edit form. | |
if ($form_id == 'product_style_node_form') { | |
// Add a custom submit. | |
$form['actions']['submit']['#submit'][] = 'mymodule_node_prod_display_form_submit'; | |
} | |
} | |
/** | |
* A custom submit for the product style form. | |
* | |
* Used to set the default product if not allready set. | |
*/ | |
function mymodule_node_prod_display_form_submit($form, &$form_state) { | |
$nid = $form_state['values']['nid']; | |
$node = node_load($nid); | |
if ($node->type = 'product_style') { | |
if (empty($node->field_product)) { | |
// Add Awaiting Product. | |
$node->field_product[LANGUAGE_NONE][]['product_id'] = AWAITING_PRODUCT_ID; | |
} | |
node_save($node); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment