Esempio n. 1
0
 /**
  * Process item
  *
  * @param 	void
  * @return 	bool
  */
 public function handle()
 {
     // Get product type info
     $ptId = $this->item['info']->ptId;
     include_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     $ptIdTypeInfo = $warehouse->getProductTypeInfo($ptId);
     // Run both product model handler and type handler if needed.
     // Model handlers must go first for type handlers to potentially use their updates
     $handlersPath = PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'lib' . DS . 'handlers';
     // MODEL HANDLER
     $modelHandlerClass = str_replace(' ', '_', ucwords(strtolower($ptIdTypeInfo['ptModel']))) . '_Model_Handler';
     if (file_exists($handlersPath . DS . 'model' . DS . $modelHandlerClass . '.php')) {
         // Include the parent class
         include_once $handlersPath . DS . 'ModelHandler.php';
         // Include the handler file
         include_once $handlersPath . DS . 'model' . DS . $modelHandlerClass . '.php';
         $modelHandler = new $modelHandlerClass($this->item, $this->crtId);
         $modelHandler->handle();
     }
     // TYPE HANDLER
     $typeHandlerClass = str_replace(' ', '_', ucwords(strtolower($ptIdTypeInfo['ptName']))) . '_Type_Handler';
     //print_r($typeHandlerClass); die;
     if (file_exists($handlersPath . DS . 'type' . DS . $typeHandlerClass . '.php')) {
         // Include the parent class
         include_once $handlersPath . DS . 'TypeHandler.php';
         // Include the handler file
         include_once $handlersPath . DS . 'type' . DS . $typeHandlerClass . '.php';
         $typeHandler = new $typeHandlerClass($this->item, $this->crtId);
         $typeHandler->handle();
     }
     // CUSTOM HANDLERS (if any)
     if (!empty($this->item['meta']['customHandler'])) {
         $customHandler = $this->item['meta']['customHandler'];
         $customHandlerClass = str_replace(' ', '_', ucwords(strtolower($customHandler))) . '_Custom_Handler';
         if (file_exists($handlersPath . DS . 'custom' . DS . $customHandlerClass . '.php')) {
             // Include the parent class
             include_once $handlersPath . DS . 'CustomHandler.php';
             // Include the handler file
             include_once $handlersPath . DS . 'custom' . DS . $customHandlerClass . '.php';
             $customHandler = new $customHandlerClass($this->item, $this->crtId);
             $customHandler->handle();
         }
     }
 }
Esempio n. 2
0
 /**
  * Constructor
  * @param 	Object  Product info
  * @param   int     Cart ID
  * @param   int     User ID
  * @return 	Void
  */
 public static function getAuditor($pInfo, $crtId)
 {
     $pId = $pInfo->pId;
     $warehouse = new StorefrontModelWarehouse();
     // Get product type
     $pType = $warehouse->getProductTypeInfo($pInfo->ptId);
     $type = $pType['ptName'];
     $model = $pType['ptModel'];
     // Find if there are auditors for this product's type and model
     $auditorsPath = PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'lib' . DS . 'auditors';
     $auditorClass = str_replace(' ', '_', ucwords(strtolower($model))) . '_Auditor';
     if (file_exists($auditorsPath . DS . $auditorClass . '.php')) {
         // Include the auditor file
         include_once $auditorsPath . DS . $auditorClass . '.php';
         return new $auditorClass($type, $pId, $crtId);
     } else {
         return new BaseAuditor($type);
     }
 }
 public function handle()
 {
     $itemInfo = $this->item['info'];
     // Get user
     require_once JPATH_BASE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'Cart.php';
     $uId = CartModelCart::getCartUser($this->crtId);
     // Get product type
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     $pType = $warehouse->getProductTypeInfo($itemInfo->ptId);
     $type = $pType['ptName'];
     require_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $subscription = StorefrontModelMemberships::getSubscriptionObject($type, $itemInfo->pId, $uId);
     // Get the expiration for the current subscription (if any)
     $currentExpiration = $subscription->getExpiration();
     // Calculate new expiration
     $newExpires = StorefrontModelMemberships::calculateNewExpiration($currentExpiration, $this->item);
     // Update/Create membership expiration date with new value
     $subscription->setExpiration($newExpires);
 }
Esempio n. 4
0
 /**
  * Handle memberships
  *
  * @param 	object 		$cartInfo
  * @param	object		$cartCoupons
  * @return 	object		membership info
  */
 public function getMembershipInfo()
 {
     $cartInfo = $this->getCartInfo();
     $cartItems = $cartInfo->items;
     // init membership info
     $memberships = array();
     include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new StorefrontModelMemberships();
     // Get membership types
     $membershipTypes = $ms->getMembershipTypes();
     // Go through each product and see if the type is membership
     foreach ($cartItems as $sId => $item) {
         if (in_array($item['info']->ptId, $membershipTypes) && !empty($item['meta']['ttl'])) {
             $itemInfo = $item['info'];
             // Get product type
             require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
             $warehouse = new StorefrontModelWarehouse();
             $pType = $warehouse->getProductTypeInfo($itemInfo->ptId);
             $type = $pType['ptName'];
             // Get the correct membership Object
             $subscription = StorefrontModelMemberships::getSubscriptionObject($type, $itemInfo->pId, User::get('id'));
             // Get the expiration for the current subscription (if any)
             $currentExpiration = $subscription->getExpiration();
             // Calculate new expiration
             $newExpires = StorefrontModelMemberships::calculateNewExpiration($currentExpiration, $item);
             $membershipSIdInfo = new stdClass();
             $membershipSIdInfo->newExpires = strtotime($newExpires);
             if ($currentExpiration && $currentExpiration['crtmActive']) {
                 $membershipSIdInfo->existingExpires = strtotime($currentExpiration['crtmExpires']);
             }
             $memberships[$sId] = $membershipSIdInfo;
             unset($membershipSIdInfo);
         }
     }
     return $memberships;
 }