コード例 #1
0
ファイル: class.index.php プロジェクト: hungnv0789/vhtm
	/**
	 * Load and return a listing of the recent orders placed on this store.
	 * Orders are loaded for a specific status if one is passed in via the GET
	 * or via a cookie.
	 *
	 * @return string The recent list of orders HTML.
	 */
	public function LoadRecentOrders()
	{
		// Do we have permission to view this widget?
		if(!$this->auth->HasPermission(AUTH_Manage_Orders)) {
			return false;
		}

		// If we don't have a status coming in via the URL, use the default
		if(!isset($_GET['status'])) {
			// Maybe it's set in a cookie? Use that
			if(isset($_COOKIE['DashboardRecentOrdersStatus'])) {
				$status = $_COOKIE['DashboardRecentOrdersStatus'];
			}
			else {
				$status = 'recent';
			}
		}
		else {
			$status = $_GET['status'];
		}

		$orderWhere = '1=1';
		$statusIn = array();
		// Determine which statuses we'll be showing orders for. Will be used in the query.
		switch($status)
		{
			case 'pending':
				$statusIn = array(
					ORDER_STATUS_PENDING,
					ORDER_STATUS_PARTIALLY_SHIPPED,
					ORDER_STATUS_AWAITING_PAYMENT,
					ORDER_STATUS_AWAITING_SHIPMENT,
					ORDER_STATUS_AWAITING_FULFILLMENT,
					ORDER_STATUS_AWAITING_PICKUP,
				);
				break;
			case 'completed':
				$statusIn = array(
					ORDER_STATUS_SHIPPED,
					ORDER_STATUS_COMPLETED
				);
				break;
			case 'refunded':
				$statusIn = array(
					ORDER_STATUS_REFUNDED,
					ORDER_STATUS_CANCELLED
				);
				break;
			default:
				$status = 'recent';
		}

		// If they've just changed statuses, store it in a cookie
		if(isset($_GET['status'])) {
			isc_setcookie('DashboardRecentOrdersStatus', $status);
		}

		if(!empty($statusIn)) {
			$orderWhere .= " AND ordstatus IN (".implode(',', $statusIn).")";
		}

		// Only get orders for this vendor
		if($this->auth->GetVendorId()) {
			$orderWhere .= " AND ordvendorid='".$this->auth->GetVendorId()."'";
		}

		// Fetch orders
		$query = "
			SELECT orderid, ordbillfirstname, ordbilllastname, ordstatus, orddate, total_inc_tax
			FROM [|PREFIX|]orders
			WHERE ".$orderWhere." AND ordstatus != 0 AND deleted = 0
			ORDER BY orddate DESC
		";
		$query .= $this->db->AddLimit(0, 10);
		$result = $this->db->Query($query);
		$orderList = '';
		while($order = $this->db->Fetch($result)) {
			$this->template->Assign('OrderId', $order['orderid']);
			$this->template->Assign('OrderStatusId', $order['ordstatus']);
			$this->template->Assign('OrderStatus', GetOrderStatusById($order['ordstatus']));
			$customerName = $order['ordbillfirstname'].' '.$order['ordbilllastname'];
			if(!trim($customerName)) {
				$customerName = GetLang('Guest');
			}
			$this->template->Assign('CustomerName', isc_html_escape($customerName));
			$orderSummary = sprintf(GetLang('RecentOrdersDateAndTotal'), Store_DateTime::niceDate($order['orddate'], true), FormatPrice($order['total_inc_tax']));
			$this->template->Assign('OrderSummary', $orderSummary);
			$orderList .= $this->template->render('Snippets/DashboardRecentOrdersItem.html');
		}

		if(!$orderList) {
			$orderList = $this->template->render('Snippets/DashboardRecentOrdersNone.html');
		}

		return $orderList;
	}