Esempio n. 1
0
 /**
  * Displays a list of groups
  *
  * @return  void
  */
 public function displayTask()
 {
     // Instantiate a new view
     $this->view->store_enabled = $this->config->get('store_enabled');
     // Get paging variables
     $this->view->filters = array('limit' => Request::getState($this->_option . '.items.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.items.limitstart', 'limitstart', 0, 'int'), 'filterby' => Request::getState($this->_option . '.items.filterby', 'filterby', 'all'), 'sortby' => Request::getState($this->_option . '.items.sortby', 'sortby', 'date'));
     $obj = new Store($this->database);
     $this->view->total = $obj->getItems('count', $this->view->filters, $this->config);
     $this->view->rows = $obj->getItems('retrieve', $this->view->filters, $this->config);
     // how many times ordered?
     if ($this->view->rows) {
         $oi = new OrderItem($this->database);
         foreach ($this->view->rows as $o) {
             // Active orders
             $o->activeorders = $oi->countActiveItemOrders($o->id);
             // All orders
             $o->allorders = $oi->countAllItemOrders($o->id);
         }
     }
     // Output the HTML
     $this->view->display();
 }
Esempio n. 2
0
 /**
  * Display an order
  *
  * @return     void
  */
 public function orderTask()
 {
     $this->view->store_enabled = $this->config->get('store_enabled');
     // Incoming
     $id = Request::getInt('id', 0);
     // Load data
     $this->view->row = new Order($this->database);
     $this->view->row->load($id);
     $oi = new OrderItem($this->database);
     $this->view->orderitems = array();
     $this->view->customer = null;
     $this->view->funds = 0;
     if ($id) {
         // Get order items
         $this->view->orderitems = $oi->getOrderItems($id);
         if (count($this->view->orderitems) > 0) {
             foreach ($this->view->orderitems as $r) {
                 $params = new Registry($r->params);
                 $selections = new Registry($r->selections);
                 // Get size selection
                 $r->sizes = $params->get('size', '');
                 $r->sizes = str_replace(' ', '', $r->sizes);
                 $r->sizes = preg_split('#,#', $r->sizes);
                 $r->selectedsize = trim($selections->get('size', ''));
                 $r->sizeavail = in_array($r->selectedsize, $r->sizes) ? 1 : 0;
                 // Get color selection
                 $r->colors = $params->get('color', '');
                 $r->colors = str_replace(' ', '', $r->colors);
                 $r->colors = preg_split('#,#', $r->colors);
                 $r->selectedcolor = trim($selections->get('color', ''));
             }
         }
         $this->view->customer = User::getInstance($this->view->row->uid);
         // Check available user funds
         $BTL = new Teller($this->database, $this->view->row->uid);
         $balance = $BTL->summary();
         $credit = $BTL->credit_summary();
         $this->view->funds = $balance;
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
Esempio n. 3
0
 /**
  * Finalize the purchase process
  *
  * @return     void
  */
 public function finalizeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Set page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Check authorization
     if (User::isGuest()) {
         $this->loginTask();
         return;
     }
     $now = \Date::toSql();
     // Get cart object
     $item = new Cart($this->database);
     // Calculate total
     $cost = $item->getCartItems(User::get('id'), 'cost');
     // Check available user funds
     $BTL = new Teller(User::get('id'));
     $balance = $BTL->summary();
     $credit = $BTL->credit_summary();
     $funds = $balance - $credit;
     $funds = $funds > 0 ? $funds : '0';
     // Get cart items
     $items = $item->getCartItems(User::get('id'));
     if (!$items or $cost > $funds) {
         $this->cartTask();
         return;
     }
     // Get shipping info
     $shipping = array_map('trim', $_POST);
     // make sure email address is valid
     $email = \Hubzero\Utility\Validate::email($shipping['email']) ? $shipping['email'] : User::get('email');
     // Format posted info
     $details = Lang::txt('COM_STORE_SHIP_TO') . ':' . "\r\n";
     $details .= $shipping['name'] . "\r\n";
     $details .= Sanitize::stripAll($shipping['address']) . "\r\n";
     $details .= Lang::txt('COM_STORE_COUNTRY') . ': ' . $shipping['country'] . "\r\n";
     $details .= '----------------------------------------------------------' . "\r\n";
     $details .= Lang::txt('COM_STORE_CONTACT') . ': ' . "\r\n";
     if ($shipping['phone']) {
         $details .= $shipping['phone'] . "\r\n";
     }
     $details .= $email . "\r\n";
     $details .= '----------------------------------------------------------' . "\r\n";
     $details .= Lang::txt('COM_STORE_DETAILS') . ': ';
     $details .= $shipping['comments'] ? "\r\n" . Sanitize::stripAll($shipping['comments']) : 'N/A';
     // Register a new order
     $order = new Order($this->database);
     $order->uid = User::get('id');
     $order->total = $cost;
     $order->status = '0';
     // order placed
     $order->ordered = $now;
     $order->email = $email;
     $order->details = $details;
     // Store new content
     if (!$order->store()) {
         throw new Exception($order->getError(), 500);
     }
     // Get order ID
     $objO = new Order($this->database);
     $orderid = $objO->getOrderID(User::get('id'), $now);
     if ($orderid) {
         // Transfer cart items to order
         foreach ($items as $itm) {
             $orderitem = new OrderItem($this->database);
             $orderitem->uid = User::get('id');
             $orderitem->oid = $orderid;
             $orderitem->itemid = $itm->itemid;
             $orderitem->price = $itm->price;
             $orderitem->quantity = $itm->quantity;
             $orderitem->selections = $itm->selections;
             // Save order item
             if (!$orderitem->store()) {
                 throw new Exception($orderitem->getError(), 500);
             }
         }
         // Put the purchase amount on hold
         $BTL = new Teller(User::get('id'));
         $BTL->hold($order->total, Lang::txt('COM_STORE_BANKING_HOLD'), 'store', $orderid);
         $message = new \Hubzero\Mail\Message();
         $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_STORE_EMAIL_SUBJECT_NEW_ORDER', $orderid));
         $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)));
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'confirmation_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->orderid = $orderid;
         $eview->cost = $cost;
         $eview->shipping = $shipping;
         $eview->details = $details;
         $eview->items = $items;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         $message->addPart($plain, 'text/plain');
         // HTML email
         $eview->setLayout('confirmation_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         $message->addPart($html, 'text/html');
         // Send e-mail
         $message->setTo(array(User::get('email')));
         $message->send();
     }
     // Empty cart
     $item->deleteCartItem('', User::get('id'), 'all');
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error');
     } else {
         \Notify::message(Lang::txt('COM_STORE_SUCCESS_MESSAGE', $orderid), 'success');
     }
     App::redirect(Route::url('index.php?option=' . $this->_option));
     return;
 }