Is it possible to add a product to an account via the API? E.g. $user = Am_Di::getInstance()->userTable->findFirstBy(array('login' => $username)); $active_subs = $user->getActiveProductIds(); if(!in_array(ProductID,$active_subs)){ // Something here to add product $user->insertActiveProduct(ProductID); // Sample
Hello, Yes, it is possible: PHP: Am_Di::getInstance()->accessTable->insert([ 'user_id' => $user->pk(), 'product_id' => $ProductID, 'qty' => 1, 'begin_date' => sqlDate('now'), 'expire_date' => sqlDate('+1year'),]);
Also, is there any other API calls required after this? As it seems to add the product, and shows as active, yet when searching for that same user it shows not active even though the sub is active in the user account.
Please change code to this one: PHP: $access = Am_Di::getInstance()->accessRecord;$access->setForInsert([ 'user_id' => $user->pk(), 'product_id' => $ProductID, 'qty' => 1, 'begin_date' => sqlDate('now'), 'expire_date' => sqlDate('+1year'),]);$access->save(); or below insert via table add this code: PHP: $user->checkSubscriptions(true);