public function handle() { require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php'; $ms = new \Components\Storefront\Models\Memberships(); /* NEW $subscription = StorefrontModelMemberships::getSubscriptionObject($this->type, $this->pId, $this->uId); // Get the expiration for the current subscription (if any) $currentExpiration = $subscription->getExpiration(); */ // Get current registration $membership = $ms->getMembershipInfo($this->crtId, $this->item['info']->pId); $expiration = $membership['crtmExpires']; /* Add the user to the corresponding user access group (pull access group ID from the meta) */ try { // Get user ID for the cart require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php'; $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId); // Get the user group ID to set the user to (from meta) require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Product.php'; $userGId = \Components\Storefront\Models\Product::getMeta($this->item['info']->pId, 'userGroupId'); $add = \JUserHelper::addUserToGroup($userId, $userGId); if ($add instanceof \Exception) { mail(Config::get('mailfrom'), 'Error adding to the group', $add->getMessage() . ' Cart #' . $this->crtId); } $table = \JTable::getInstance('User', 'JTable', array()); $table->load($userId); // Trigger the onAftereStoreUser event Event::trigger('onUserAfterSave', array($table->getProperties(), false, true, null)); } catch (Exception $e) { // Error return false; } }
public function handle() { require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php'; $ms = new \Components\Storefront\Models\Memberships(); // Get current registration $membership = $ms->getMembershipInfo($this->crtId, $this->item['info']->pId); $expiration = $membership['crtmExpires']; // Get course ID $courseId = $this->item['meta']['courseId']; // Get user ID for the cart require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php'; $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId); // Load courses model and register // registerForCourse($userId, $courseId, $expiration); require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'course.php'; $course = \Components\Courses\Models\Course::getInstance($this->item['meta']['courseId']); if (!$course->offerings()->count()) { // error enrolling } else { // Get to the first and probably the only offering //$offering = $course->offerings()->current(); $offering = $course->offering($this->item['meta']['offeringId']); $offering->add($userId); //$offering->remove($userId); } }
public function handle() { // Get user ID for the cart require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php'; $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId); // Get number of points to add if (!empty($this->item['meta']['addPoints']) && is_numeric($this->item['meta']['addPoints'])) { // Update points account $BTL = new \Hubzero\Bank\Teller($userId); $BTL->deposit($this->item['meta']['addPoints'], 'PRO Membership Bonus', 'PRO', $this->item['info']->sId); } }
public function __construct($type, $pId = NULL, $crtId = NULL) { $this->type = $type; $this->pId = $pId; $this->crtId = $crtId; // Get user, if any $this->uId = \Components\Cart\Models\Cart::getCartUser($crtId); // Set up the default empty ok response $this->response = new \stdClass(); $this->response->status = 'ok'; $this->response->messages = array(); $this->response->notices = array(); $this->response->errors = array(); }
public function handle() { $itemInfo = $this->item['info']; // Get user require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php'; $uId = \Components\Cart\Models\Cart::getCartUser($this->crtId); // Get product type require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php'; $warehouse = new \Components\Storefront\Models\Warehouse(); $pType = $warehouse->getProductTypeInfo($itemInfo->ptId); $type = $pType['ptName']; require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php'; $subscription = \Components\Storefront\Models\Memberships::getSubscriptionObject($type, $itemInfo->pId, $uId); // Get the expiration for the current subscription (if any) $currentExpiration = $subscription->getExpiration(); // Calculate new expiration $newExpires = Components\Storefront\Models\Memberships::calculateNewExpiration($currentExpiration, $this->item); // Update/Create membership expiration date with new value $subscription->setExpiration($newExpires); }
public function emailOrderComplete($transactionInfo) { $params = Component::params(Request::getVar('option')); $items = unserialize($transactionInfo->tiItems); //print_r($items); die; // Build emails // Build order summary $summary = 'Order number: ' . $transactionInfo->tId . "\n\n"; $summary .= "\n====================\n\n"; $summary .= 'Subtotal: ' . '$' . number_format($transactionInfo->tiSubtotal, 2) . "\n"; if (!$transactionInfo->tiShipping) { $transactionInfo->tiShipping = 0; } if ($transactionInfo->tiShipping > 0) { $summary .= 'Shipping and handling: ' . '$' . number_format($transactionInfo->tiShipping, 2) . "\n"; } if (!$transactionInfo->tiTax) { $transactionInfo->tiTax = 0; } if ($transactionInfo->tiDiscounts > 0 || $transactionInfo->tiShippingDiscount > 0) { $summary .= 'Discounts: ' . '$' . number_format($transactionInfo->tiDiscounts + $transactionInfo->tiShippingDiscount, 2) . "\n"; } if ($transactionInfo->tiTax > 0) { $summary .= 'Tax: ' . '$' . number_format($transactionInfo->tiTax, 2) . "\n"; } $summary .= 'Total: ' . '$' . number_format($transactionInfo->tiTotal, 2) . "\n"; if (!empty($transactionInfo->tiShippingToFirst)) { $summary .= "\n\nShipping address:"; $summary .= "\n--------------------\n"; $summary .= $transactionInfo->tiShippingToFirst . ' ' . $transactionInfo->tiShippingToLast . "\n"; $summary .= $transactionInfo->tiShippingAddress . "\n"; $summary .= $transactionInfo->tiShippingCity . ', ' . $transactionInfo->tiShippingState . ' ' . $transactionInfo->tiShippingZip . "\n"; } $summary .= "\n\nItems ordered:"; $summary .= "\n--------------------\n"; require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php'; $warehouse = new \Components\Storefront\Models\Warehouse(); foreach ($items as $k => $item) { $itemInfo = $item['info']; $cartInfo = $item['cartInfo']; $itemMeta = $item['meta']; //print_r($item); die; $productType = $warehouse->getProductTypeInfo($itemInfo->ptId)['ptName']; // If course, generate a link to the course $action = false; if ($productType == 'Course') { $action = ' Go to the course page at: ' . ($action .= Route::url('index.php?option=com_courses', true, -1) . $itemMeta['courseId'] . '/' . $itemMeta['offeringId']); } elseif ($productType == 'Software Download') { $action = ' Download at: ' . ($action .= Route::url('index.php?option=com_cart', true, -1) . 'download/' . $transactionInfo->tId . '/' . $itemInfo->sId); if (isset($itemMeta['serial']) && !empty($itemMeta['serial'])) { $action .= "\n\t"; $action .= " Serial number: " . $itemMeta['serial']; } } $summary .= "{$cartInfo->qty} x "; $summary .= "{$itemInfo->pName}"; if (!empty($item['options'])) { $summary .= '('; $optionCount = 0; foreach ($item['options'] as $option) { if ($optionCount) { $summary .= ', '; } $summary .= $option; $optionCount++; } $summary .= ')'; } $summary .= ' @ ' . '$' . number_format($itemInfo->sPrice, 2); if ($action) { $summary .= "\n\t"; $summary .= $action; } $summary .= "\n"; } //print_r($summary); die; // Get message plugin JPluginHelper::importPlugin('xmessage'); // "from" info $from = array(); $from['name'] = Config::get('sitename'); $from['email'] = Config::get('mailfrom'); // Email to admin $adminEmail = "There is a new online store order: \n\n"; $adminEmail .= $summary; // Admin email $to = array($params->get('storeAdminId')); Event::trigger('onSendMessage', array('store_notifications', 'New order at ' . $from['name'], $adminEmail, $from, $to, '', null, '', 0, true)); // Email to client $clientEmail = 'Thank you for your order at ' . Config::get('sitename') . "!\n\n"; $clientEmail .= $summary; require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'Cart.php'; $to = array(\Components\Cart\Models\Cart::getCartUser($transactionInfo->crtId)); Event::trigger('onSendMessage', array('store_notifications', 'Your order at ' . $from['name'], $clientEmail, $from, $to, '', null, '', 0, true)); // Email notification extra $notifyTo = $params->get('sendNotificationTo'); if (!empty($notifyTo)) { $notifyTo = explode(',', str_replace(' ', '', $notifyTo)); $notifyEmail = 'There is a new online store order at ' . Config::get('sitename') . "\n\n"; $notifyEmail .= $summary; // Plain text email $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'order_notify')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->message = $notifyEmail; $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); $message = new \Hubzero\Mail\Message(); $message->setSubject('ORDER NOTIFICATION: New order at ' . $from['name']); $message->addFrom(Config::get('mailfrom'), Config::get('sitename')); $message->addPart($plain, 'text/plain'); foreach ($notifyTo as $email) { if (\Hubzero\Utility\Validate::email($email)) { $message->addTo($email); } } $message->setBody($plain); $message->send(); } }
/** * View the order * * @return void */ public function viewTask() { // Incoming $id = Request::getVar('id', array(0)); // Get transaction info $tInfo = Cart::getTransactionInfo($id); $tItems = unserialize($tInfo->tiItems); foreach ($tItems as $item) { // Check if the product is still available $warehouse = new Warehouse(); $skuInfo = $warehouse->getSkuInfo($item['info']->sId); if (!$skuInfo) { // product no longer available $item['info']->available = false; } else { $item['info']->available = true; } } $tInfo->tiItems = $tItems; // Get user info $userId = Cart::getCartUser($tInfo->crtId); $user = Profile::getInstance($userId); //print_r($user); die; $this->view->user = $user; $this->view->tInfo = $tInfo; $this->view->tId = $id; $this->view->setLayout('view')->display(); }
/** * Serve the file * * @param $pId * @return void */ public function displayTask() { // Get the transaction ID $tId = Request::getInt('task', ''); // Get the SKU ID $sId = Request::getVar('p0'); // Get the landing page flag $direct = Request::getVar('p1'); // Check if the transaction is complete and belongs to the user and is active and the SKU requested is valid $transaction = Cart::getTransactionFacts($tId); $transactionExistingItems = $transaction->items; $transaction = $transaction->info; $transactionItems = unserialize($transaction->tiItems); $tStatus = $transaction->tStatus; $crtId = $transaction->crtId; // get cart user $cartUser = Cart::getCartUser($crtId); $currentUser = $this->juser->id; // Error if needed if ($tStatus !== 'completed') { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_TRANSACTION_NOT_COMPLETED'), 'error')); $this->messageTask($messages); return; } elseif ($cartUser != $currentUser) { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_NOT_AUTHORIZED'), 'error')); $this->messageTask($messages); return; } elseif (!array_key_exists($sId, $transactionItems)) { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_NOT_AUTHORIZED'), 'error')); $this->messageTask($messages); return; } // Check if the product is valid and downloadable; find the file $warehouse = new Warehouse(); $sku = $warehouse->getSkuInfo($sId); $productType = $warehouse->getProductTypeInfo($sku['info']->ptId); $downloadFile = $sku['meta']['downloadFile']; // Error if needed if ($productType['ptName'] != 'Software Download' || empty($downloadFile)) { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_DOWNLOADABLE'), 'error')); $this->messageTask($messages); return; } $db = \App::get('db'); // Check if there is a limit on how many times the product can be downloaded // Get the number of downloads allowed if (isset($sku['meta']['downloadLimit']) && $sku['meta']['downloadLimit'] && is_numeric($sku['meta']['downloadLimit'])) { $sql = "SELECT COUNT(`dId`) FROM `#__cart_downloads` WHERE `uId` = {$currentUser} AND `sId` = {$sId} AND `dStatus` > 0"; $db->setQuery($sql); $downloadsCount = $db->loadResult(); if ($downloadsCount >= $sku['meta']['downloadLimit']) { $messages = array(array('Download limit exceeded', 'error')); $this->messageTask($messages); return; } } // Path and file name $storefrontConfig = Component::params('com_storefront'); $dir = $storefrontConfig->get('downloadFolder', '/site/protected/storefront/software'); $file = PATH_APP . $dir . DS . $downloadFile; if (!file_exists($file)) { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_FOUND'), 'error')); $this->messageTask($messages); return; } if (!$direct) { $this->landingTask($tId, $sId); return; } // Log the download $sql = "INSERT INTO `#__cart_downloads` SET\n\t\t\t\t`uId` = " . $currentUser . ",\n\t\t\t\t`sId` = " . $sId . ",\n\t\t\t\t`dIp` = INET_ATON(" . $db->quote(Request::ip()) . "),\n\t\t\t\t`dDownloaded` = NOW()"; $db->setQuery($sql); $db->query(); $dId = $db->insertid(); // Save the meta data $userGroups = User::getAuthorisedGroups(); $meta = array(); $ignoreGroups = array('public', 'registered'); foreach ($userGroups as $groupId) { $group = Accessgroup::one($groupId); if (!in_array(strtolower($group->get('title')), $ignoreGroups)) { $meta[$groupId] = $group->get('title'); } } if ($mta = User::getState('metadata')) { $meta = array_merge($meta, $mta); } $sql = "INSERT INTO `#__cart_meta` SET\n\t\t\t\t`scope_id` = " . $dId . ",\n\t\t\t\t`scope` = 'download',\n\t\t\t\t`mtKey` = 'userInfo',\n\t\t\t\t`mtValue` = '" . serialize($meta) . "'"; $db->setQuery($sql); $db->query(); // Figure out if the EULA was accepted $itemTransactionInfoMeta = $transactionExistingItems[$sId]['transactionInfo']->tiMeta; $eulaAccepted = $itemTransactionInfoMeta && property_exists($itemTransactionInfoMeta, 'eulaAccepted') && $itemTransactionInfoMeta->eulaAccepted ? true : false; if ($eulaAccepted) { $sql = "INSERT INTO `#__cart_meta` SET\n\t\t\t\t\t`scope_id` = " . $dId . ",\n\t\t\t\t\t`scope` = 'download',\n\t\t\t\t\t`mtKey` = 'eulaAccepted',\n\t\t\t\t\t`mtValue` = '" . $eulaAccepted . "'"; $db->setQuery($sql); $db->query(); } // Serve up the file $xserver = new \Hubzero\Content\Server(); $xserver->filename($file); $xserver->serve_attachment($file); // Firefox and Chrome fail if served inline exit; }
/** * Serve the file * * @param $pId * @return void */ public function displayTask() { // Get the transaction ID $tId = Request::getInt('task', ''); // Get the SKU ID $sId = Request::getVar('p0'); // Get the landing page flag $direct = Request::getVar('p1'); // Check if the transaction is complete and belongs to the user and is active $transaction = Cart::getTransactionFacts($tId); $transaction = $transaction->info; $tStatus = $transaction->tStatus; $crtId = $transaction->crtId; // get cart user $cartUser = Cart::getCartUser($crtId); $currentUser = $this->juser->id; // Error if needed if ($tStatus !== 'completed') { $messages = array(array('COM_CART_DOWNLOAD_TRANSACTION_NOT_COMPLETED', 'error')); $this->messageTask($messages); return; } elseif ($cartUser != $currentUser) { $messages = array(array('COM_CART_DOWNLOAD_NOT_AUTHORIZED', 'error')); $this->messageTask($messages); return; } // Check if the product is valid and downloadable; find the file $warehouse = new Warehouse(); $sku = $warehouse->getSkuInfo($sId); $productType = $sku['info']->ptId; $downloadFile = $sku['meta']['downloadFile']; // Error if needed if ($productType != 30 || empty($downloadFile)) { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_DOWNLOABLE'), 'error')); $this->messageTask($messages); return; } $db = \App::get('db'); // Check if there is a limit on how many times the product can be downloaded // Get the number of downloads allowed $allowedDownloads = $sku; if (isset($sku['meta']['downloadLimit']) && $sku['meta']['downloadLimit'] && is_numeric($sku['meta']['downloadLimit'])) { $sql = "SELECT COUNT(`dId`) FROM `#__cart_downloads` WHERE `uId` = {$currentUser} AND `sId` = {$sId}"; $db->setQuery($sql); $downloadsCount = $db->loadResult(); if ($downloadsCount >= $sku['meta']['downloadLimit']) { $messages = array(array('Download limit exceeded', 'error')); $this->messageTask($messages); return; } } // Path and file name $storefrontConfig = Component::params('com_storefront'); $dir = $storefrontConfig->get('downloadFolder'); $file = PATH_ROOT . $dir . DS . $downloadFile; if (!file_exists($file)) { $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_FOUND'), 'error')); $this->messageTask($messages); return; } if (!$direct) { $this->landingTask($tId, $sId); return; } // Log the download $sql = "INSERT INTO `#__cart_downloads` SET\n\t\t\t\t`uId` = " . $currentUser . ",\n\t\t\t\t`sId` = " . $sId . ",\n\t\t\t\t`dIp` = INET_ATON(" . $db->quote(Request::getClientIp()) . "),\n\t\t\t\t`dDownloaded` = NOW()"; $db->setQuery($sql); $db->query(); // Serve up the file $xserver = new \Hubzero\Content\Server(); $xserver->filename($file); $xserver->serve_attachment($file); // Firefox and Chrome fail if served inline exit; }