function onInvoiceStarted(Am_Event_InvoiceStarted $event)
 {
     $invoice = $event->getInvoice();
     foreach ($invoice->getItems() as $item) {
         if ($item->item_type != 'product') {
             continue;
         }
         $product = $this->getDi()->productTable->load($item->item_id);
         if ($limit = $product->data()->get('subscription_limit')) {
             $limit -= $item->qty;
             $product->data()->set('subscription_limit', $limit);
             if (!$limit) {
                 $product->is_disabled = 1;
             }
             $product->save();
         }
     }
 }
 static function onInvoiceStarted(Am_Event_InvoiceStarted $event)
 {
     $event->getDi()->emailTemplateTable->sendZeroAutoresponders($event->getInvoice()->getUser());
 }
 static function onInvoiceStarted(Am_Event_InvoiceStarted $event)
 {
     $invoice = $event->getInvoice();
     $event->getDi()->emailTemplateTable->sendZeroAutoresponders($invoice->getUser(), $invoice);
     if ($invoice->first_total > 0 || $invoice->second_total > 0) {
         return;
     }
     if ($event->getDi()->config->get('send_free_payment_admin')) {
         $et = Am_Mail_Template::load('send_free_payment_admin');
         if ($et) {
             $et->setUser($event->getUser())->setInvoice($invoice)->setPayment($event->getPayment())->setInvoice_text($invoice->render());
             $et->send(Am_Mail_Template::TO_ADMIN);
         }
     }
 }
Exemple #4
0
 /**
  * Handle free signups
  */
 function onInvoiceStarted(Am_Event_InvoiceStarted $event)
 {
     $invoice = $event->getInvoice();
     $isFirst = !$this->getDi()->db->selectCell("SELECT COUNT(*)\n            FROM ?_invoice\n            WHERE user_id=?\n            AND invoice_id<>?\n            AND tm_started IS NOT NULL", $invoice->user_id, $invoice->pk());
     if ($invoice->first_total == 0 && $invoice->second_total == 0 && $isFirst) {
         $this->getDi()->affCommissionRuleTable->processPayment($invoice);
     }
 }