0

I am trying to create a product programmatically and set it features for role assignment, that a user gets a specific role after he purchases, i tried all the ways i can but couldnt get it working. below is the code i used for adding it, but when i edit the feature for role assignment it doesnt hold the values i set in the edit feature form.

function add_product_feature($nid, $sku){
     // Insert new product into the uc_product_features tables
     $desc = "<strong>SKU:</strong> ".$sku."<br /><strong>Role:
     </strong>purchaser<br /><strong>Expiration:</strong> <a 
      href=\"/admin/store/settings/products\">Global expiration</a> 
      (not overridden)<br /><strong>Shippable:</strong> No<br />
      <strong>Multiply by quantity:</strong> No";
      $nid1 = db_insert('uc_product_features')
      ->fields(array('nid' => $nid,'fid' => 'role','description' => 
      $desc, 
      ))
      ->execute();
}
0

Don't do that. Inserting into the DB directly can cause you problems down the road; there's already been code written to do what you're trying to do.

Look at the uc_roles functions/documentation and follow how it adds product features via uc_roles_feature_form_submit submission handler and its uc_product_feature_save() call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.