How about an observer class like this:
PHP Code:
<?php
/**
* observer class to set customer subscription status after purchase
*
* @package classes
* @copyright Copyright 2003-2016 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: Should work on zc v1.5 and 1.6 $
*/
class updateCustomerSubscriptionStatusAfterPurchase extends base {
/**
* Attach observer class to the global $zco_notifier and watch for a single notifier event.
*/
function __construct() {
// Using NOTIFY_CHECKOUT_PROCESS_HANDLE_AFFILIATES because the $_SESSION['order_summary']['products_ordered_ids'] is set just before that.
$this->attach($this, array('NOTIFY_CHECKOUT_PROCESS_HANDLE_AFFILIATES'));
$this->subscription_product_id = 77; // set the product_id of your subscription product here
$this->subscribed_privilege_level = 1; // set the permission level to be granted by this product here
}
/**
* Actual Method that does the desired activity
* Called by observed class when any of the notifiable events occur
*
* @param object $class
* @param string $eventID
* @param array $paramsArray
*/
function update(&$class, $eventID, $paramsArray = array())
{
global $db;
$customer_id = $_SESSION['customer_id'];
$purchased_products_array = explode('|', $_SESSION['order_summary']['products_ordered_ids']);
if (in_array($this->subscription_product_id, $purchased_products_array)) {
$sql = "update " . TABLE_CUSTOMERS . "
set customers_privileges = " . $this->subscribed_privilege_level . "
where customers_id = " . (int)$customer_id;
$db->Execute($sql);
$_SESSION['customers_privileges'] = (int)$this->subscribed_privilege_level;
}
}
}