function save($src = '', $orderingFilter = '', $ignore = '') { $prev = clone $this; if (!empty($this->id)) { $prev->load($this->id); } if ($save = parent::save($src, $orderingFilter, $ignore)) { if ($prev->subscription_enabled && empty($this->subscription_enabled)) { // if it was previously enabled and now is disabled Citruscart::load('CitruscartHelperJuga', 'helpers.juga'); $helper = new CitruscartHelperJuga(); $helper->doExpiredSubscription($this); } } return $save; }
/** * Marks a subscription as expired * and sends the expired email to the user * * @param $subscription_id * @param object $item Single item from the Subscriptions model * @param $issues If this is subscription by issues * @return unknown_type */ function setExpired($subscription_id, $item = '', $issues = false) { // change status = '0' JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $subscription = JTable::getInstance('Subscriptions', 'CitruscartTable'); $subscription->subscription_id = $subscription_id; $subscription->subscription_enabled = 0; if ($issues) { $subscription->expires_datetime = JFactory::getDate()->toSql(); } if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // fire plugin event onAfterExpiredSubscription JPluginHelper::importPlugin('citruscart'); JFactory::getApplication()->triggerEvent('onAfterExpiredSubscription', array($subscription)); if (empty($item)) { JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('Subscriptions', 'CitruscartModel'); $model->setId($subscription_id); $item = $model->getItem(); } //remove user in juga group if integration exist Citruscart::load('CitruscartHelperJuga', 'helpers.juga'); $helperJuga = new CitruscartHelperJuga(); if ($helperJuga->isInstalled()) { if ($helperJuga->doExpiredSubscription($item)) { //do something //either send email or raised message } } // Email user that their subs expired if (!empty($item)) { Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $helper->sendEmailNotices($item, 'subscription_expired'); } return true; }