Last active
August 29, 2015 14:00
-
-
Save yanniboi/11370169 to your computer and use it in GitHub Desktop.
Generate commerce file license
This file contains hidden or 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
| <?php | |
| $fid = ''; // ID of the file you want to license. | |
| $uid = ''; // ID of the user receiving the license. | |
| $line_item_id = ''; // Optional - Id of line item in an order owned by the user. | |
| // Get the entities. | |
| $user = user_load($uid); | |
| $file = file_load($fid); | |
| $values = array( | |
| 'uid' => $user->uid, | |
| 'status' => 'active', | |
| ); | |
| $license_new = commerce_file_license_create($values); | |
| // Attach the file to the license. | |
| $license_new->commerce_file_license_file[LANGUAGE_NONE][] = array( | |
| 'fid' => $file->fid, | |
| 'data' => array( | |
| 'duration' => 0, | |
| 'download_limit' => 0, | |
| 'access_limit' => 0, | |
| ), | |
| ); | |
| // Optional if line item exists. | |
| $license_new->commerce_file_license_line_items[LANGUAGE_NONE][] = array( | |
| 'line_item_id' => $line_item_id, | |
| ); | |
| // Save. | |
| commerce_file_license_save($license_new); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment