Beispiel #1
0
 /**
  * After a checkout has been completed
  * and a payment has been received (instant)
  * run this method to enable
  * any non-recurring subscriptions that were created when the order was saved
  *
  * @param $order_id
  * @return unknown_type
  */
 public static function enableNonRecurringSubscriptions($order_id)
 {
     $error = false;
     $errorMsg = "";
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $model = JModelLegacy::getInstance('Orders', 'CitruscartModel');
     $model->setId($order_id);
     $model_issues = null;
     $order = $model->getItem();
     if ($order->orderitems) {
         foreach ($order->orderitems as $orderitem) {
             // if this orderItem created a subscription, enable it
             if (!empty($orderitem->orderitem_subscription)) {
                 // these are only for one-time payments that create subscriptions
                 // recurring payment subscriptions are handled differently - by the payment plugins
                 $subscription = JTable::getInstance('Subscriptions', 'CitruscartTable');
                 $subscription->load(array('orderitem_id' => $orderitem->orderitem_id));
                 if (!empty($subscription->subscription_id)) {
                     $subscription->subscription_enabled = '1';
                     Citruscart::load('CitruscartHelperProduct', 'helpers.product');
                     $product = CitruscartHelperProduct::load($subscription->product_id, true, false);
                     if ($product->subscription_period_unit == 'I') {
                         $model_issues = JModelLegacy::getInstance('ProductIssues', 'CitruscartModel');
                         $subscription->subscription_issue_end_id = $model_issues->getEndIssueId($subscription->product_id, $product->subscription_period_interval);
                     }
                     if (!$subscription->save()) {
                         // track error
                         $error = true;
                         $errorMsg .= $subscription->getError();
                         // TODO What to do with this error
                     } else {
                         JFactory::getApplication()->triggerEvent('onAfterEnableSubscription', array($subscription));
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Returns the full path to the product's image gallery files
  *
  * @param int $id
  * @return string
  */
 public static function getGalleryPath($row)
 {
     static $paths;
     if (is_object($row)) {
         $id = $row->product_id;
         $paths[$id] = $row->getImagePath(true);
     } else {
         $id = (int) $row;
         if (!is_array($paths)) {
             $paths = array();
         }
         if (empty($paths[$id])) {
             $paths[$id] = '';
             if (isset($this) && is_a($this, 'CitruscartHelperProduct')) {
                 $helper = $this;
             } else {
                 $helper = new CitruscartHelperProduct();
             }
             $row = $helper->load((int) $id, true, false);
             if (empty($row->product_id)) {
                 // TODO figure out what to do if the id is invalid
                 return null;
             }
             $paths[$id] = $row->getImagePath(true);
         }
     }
     return $paths[$id];
 }