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); }
/** * 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; }