public static function skuIntegrityCheck($sku) { $return = new \stdClass(); $return->status = 'ok'; $return->errors = array(); //print_r($sku); $options = $sku->getOptions(); // Check if there are other SKUs that have the same set of options $warehouse = new \Components\Storefront\Models\Warehouse(); $skuMatch = $warehouse->mapSku($sku->getProductId(), $options, false); if ($skuMatch && $skuMatch != $sku->getId()) { $return->status = 'error'; // If there are no options, no multiple SKUs can be published if (empty($options)) { $return->errors[] = 'There is already another SKU published for this product. A product without product options can only have one SKU.'; } else { $return->errors[] = 'There is already a SKU with the identical set of options. Each SKU must have a unique set of options.'; } } // If allowing multiple check if the parent product allows it. If not -- parent must be set to allow it first. if ($sku->getAllowMultiple()) { $pInfo = $warehouse->getProductInfo($sku->getProductId()); if (!$pInfo->pAllowMultiple) { $return->status = 'error'; $return->errors[] = 'Cannot allow multiple, the parent product is not set to allow multiple.'; } } return $return; }
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 static function skuIntegrityCheck($sku) { $return = new \stdClass(); $return->status = 'ok'; $return->errors = array(); $options = $sku->getOptions(); // Check if there are other SKUs that have the same set of options $warehouse = new \Components\Storefront\Models\Warehouse(); $skuMatch = $warehouse->mapSku($sku->getProductId(), $options, false); if ($skuMatch && $skuMatch != $sku->getId()) { $return->status = 'error'; // If there are no options, no multiple SKUs can be published if (empty($options)) { $return->errors[] = 'There is already another SKU published for this product. A product without product options can only have one SKU.'; } else { $return->errors[] = 'There is already a SKU with the identical set of options. Each SKU must have a unique set of options.'; } } return $return; }
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(); } }
<p>Thank you for your order.</p> <p>You will receive an email confirmation shortly at the email address associated with your account. Your transaction is now complete.</p> <section class="section"> <?php //print_r($this->transactionInfo); die; if (!empty($this->transactionInfo)) { $transactionItems = unserialize($this->transactionInfo->tiItems); $meta = unserialize($this->transactionInfo->tiMeta); $membershipInfo = $meta['membershipInfo']; //print_r($transactionItems); die; echo '<h2>Order summary</h2>'; echo '<table id="cartContents">'; echo '<tr><th>Item</th><th>Status</th><th>Notes</th></tr>'; require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php'; $warehouse = new \Components\Storefront\Models\Warehouse(); foreach ($transactionItems as $sId => $item) { $info = $item['info']; $action = ''; $productType = $warehouse->getProductTypeInfo($item['info']->ptId)['ptName']; //print_r($item); die; // If course if ($productType == 'Course') { $status = 'Registered'; $action = '<a href="' . Route::url('index.php?option=com_courses/' . $item['meta']['courseId']); $action .= '">Go to the course page</a>'; } elseif ($productType == 'Software Download') { $status = 'Ready'; $action = '<a href="' . Route::url('index.php?option=com_cart') . 'download/' . $this->transactionInfo->tId . '/' . $info->sId; $action .= '" target="_blank">Download</a>'; if (isset($item['meta']['serial']) && !empty($item['meta']['serial'])) {
/** * Actions to perform after deleting an offering * * @param object $model \Components\Courses\Models\Section * @param boolean $isNew Is this a newly created entry? * @return void */ public function onAfterDeleteCoupon($model) { if (!$model->exists()) { return; } $warehouse = new \Components\Storefront\Models\Warehouse(); try { $warehouse->deleteCoupon($model->get('code')); } catch (Exception $e) { echo 'ERROR: ' . $e->getMessage(); } return; }