public function screen() { $Shopp = Shopp::object(); if (!current_user_can('shopp_settings_checkout')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $purchasetable = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $next = sDB::query("SELECT IF ((MAX(id)) > 0,(MAX(id)+1),1) AS id FROM {$purchasetable} LIMIT 1"); $next_setting = shopp_setting('next_order_id'); if ($next->id > $next_setting) { $next_setting = $next->id; } $term_recount = false; if (!empty($_POST['save'])) { check_admin_referer('shopp-setup-management'); $next_order_id = $_POST['settings']['next_order_id'] = intval($_POST['settings']['next_order_id']); if ($next_order_id >= $next->id) { if (sDB::query("ALTER TABLE {$purchasetable} AUTO_INCREMENT=" . sDB::escape($next_order_id))) { $next_setting = $next_order_id; } } $_POST['settings']['order_shipfee'] = Shopp::floatval($_POST['settings']['order_shipfee']); // Recount terms when this setting changes if (isset($_POST['settings']['inventory']) && $_POST['settings']['inventory'] != shopp_setting('inventory')) { $term_recount = true; } shopp_set_formsettings(); $this->notice(Shopp::__('Management settings saved.'), 'notice', 20); } if ($term_recount) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } $states = array(__('Map the label to an order state:', 'Shopp') => array_merge(array('' => ''), Lookup::txnstatus_labels())); $statusLabels = shopp_setting('order_status'); $statesLabels = shopp_setting('order_states'); $reasonLabels = shopp_setting('cancel_reasons'); if (empty($reasonLabels)) { $reasonLabels = array(__('Not as described or expected', 'Shopp'), __('Wrong size', 'Shopp'), __('Found better prices elsewhere', 'Shopp'), __('Product is missing parts', 'Shopp'), __('Product is defective or damaaged', 'Shopp'), __('Took too long to deliver', 'Shopp'), __('Item out of stock', 'Shopp'), __('Customer request to cancel', 'Shopp'), __('Item discontinued', 'Shopp'), __('Other reason', 'Shopp')); } $promolimit = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '15', '20', '25'); $lowstock = shopp_setting('lowstock_level'); if (empty($lowstock)) { $lowstock = 0; } include $this->ui('management.php'); }
/** * Interface processor for the orders list interface * * @author Jonathan Davis * * @return void **/ public function orders() { if (!current_user_can('shopp_orders')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } global $Shopp, $Orders; $defaults = array('page' => false, 'update' => false, 'newstatus' => false, 'paged' => 1, 'per_page' => 20, 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); $s = stripslashes($s); $statusLabels = shopp_setting('order_status'); if (empty($statusLabels)) { $statusLabels = array(''); } $txnstatus_labels = Lookup::txnstatus_labels(); $Purchase = new ShoppPurchase(); $Orders = $this->orders; $ordercount = $this->ordercount; $num_pages = ceil($ordercount->total / $per_page); $ListTable = ShoppUI::table_set_pagination($this->screen, $ordercount->total, $num_pages, $per_page); $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp'), 'iif' => __('Intuit® QuickBooks.iif', 'Shopp')); $formatPref = shopp_setting('purchaselog_format'); if (!$formatPref) { $formatPref = 'tab'; } $exportcolumns = array_merge(ShoppPurchase::exportcolumns(), ShoppPurchased::exportcolumns()); $selected = shopp_setting('purchaselog_columns'); if (empty($selected)) { $selected = array_keys($exportcolumns); } $Gateways = $Shopp->Gateways; include $this->ui('orders.php'); }
/** * Renders the recent orders dashboard widget * * @author Jonathan Davis * @since 1.0 * * @return void **/ public static function orders_widget($args = false) { $defaults = array('before_widget' => '', 'before_title' => '', 'widget_name' => '', 'after_title' => '', 'after_widget' => ''); $args = array_merge($defaults, (array) $args); extract($args, EXTR_SKIP); $statusLabels = shopp_setting('order_status'); echo $before_widget; echo $before_title; echo $widget_name; echo $after_title; $purchasetable = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $purchasedtable = ShoppDatabaseObject::tablename(Purchased::$table); $txnlabels = Lookup::txnstatus_labels(); if (!($Orders = get_transient('shopp_dashboard_orders'))) { $Orders = sDB::query("SELECT p.*,count(*) as items FROM (SELECT * FROM {$purchasetable} WHERE txnstatus != 'purchased' AND txnstatus != 'invoiced' ORDER BY created DESC LIMIT 6) AS p LEFT JOIN {$purchasedtable} AS i ON i.purchase=p.id GROUP BY p.id ORDER BY p.id DESC", 'array'); set_transient('shopp_dashboard_orders', $Orders, 90); // Keep for the next 1 minute } if (!empty($Orders)) { echo '<table class="widefat">' . '<thead>' . ' <tr>' . ' <th scope="col">' . __('Name', 'Shopp') . '</th>' . ' <th scope="col">' . __('Date', 'Shopp') . '</th>' . ' <th scope="col" class="num">' . Shopp::__('Items') . '</th>' . ' <th scope="col" class="num">' . Shopp::__('Total') . '</th>' . ' <th scope="col" class="num">' . Shopp::__('Status') . '</th>' . ' </tr>' . '</thead>' . ' <tbody id="orders" class="list orders">'; $even = false; foreach ($Orders as $Order) { $classes = array(); if ($even = !$even) { $classes[] = 'alternate'; } $txnstatus = isset($txnlabels[$Order->txnstatus]) ? $txnlabels[$Order->txnstatus] : $Order->txnstatus; $status = isset($statusLabels[$Order->status]) ? $statusLabels[$Order->status] : $Order->status; $contact = '' == $Order->firstname . $Order->lastname ? '(no contact name)' : $Order->firstname . ' ' . $Order->lastname; $url = add_query_arg(array('page' => ShoppAdmin()->pagename('orders'), 'id' => $Order->id), admin_url('admin.php')); $classes[] = strtolower(preg_replace('/[^\\w]/', '_', $Order->txnstatus)); echo '<tr class="' . join(' ', $classes) . '">' . ' <td><a class="row-title" href="' . $url . '" title="View "Order ' . $Order->id . '"">' . (empty($Order->firstname) && empty($Order->lastname) ? '(no contact name)' : $Order->firstname . ' ' . $Order->lastname) . '</a></td>' . ' <td>' . date("Y/m/d", mktimestamp($Order->created)) . '</td>' . ' <td class="num items">' . $Order->items . '</td>' . ' <td class="num total">' . money($Order->total) . '</td>' . ' <td class="num status">' . $statusLabels[$Order->status] . '</td>' . '</tr>'; } echo '</tbody></table>'; } else { echo '<p>' . Shopp::__('No orders, yet.') . '</p>'; } echo $after_widget; }
public function management() { $Shopp = Shopp::object(); if (!current_user_can('shopp_settings_checkout')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $purchasetable = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $next = sDB::query("SELECT IF ((MAX(id)) > 0,(MAX(id)+1),1) AS id FROM {$purchasetable} LIMIT 1"); $next_setting = shopp_setting('next_order_id'); if ($next->id > $next_setting) { $next_setting = $next->id; } if (!empty($_POST['save'])) { check_admin_referer('shopp-setup-management'); $next_order_id = $_POST['settings']['next_order_id'] = intval($_POST['settings']['next_order_id']); if ($next_order_id >= $next->id) { if (sDB::query("ALTER TABLE {$purchasetable} AUTO_INCREMENT=" . sDB::escape($next_order_id))) { $next_setting = $next_order_id; } } shopp_set_formsettings(); $this->notice(Shopp::__('Management settings saved.'), 'notice', 20); } $states = array(__('Map the label to an order state:', 'Shopp') => array_merge(array('' => ''), Lookup::txnstatus_labels())); $statusLabels = shopp_setting('order_status'); $statesLabels = shopp_setting('order_states'); $reasonLabels = shopp_setting('cancel_reasons'); if (empty($reasonLabels)) { $reasonLabels = array(__('Not as described or expected', 'Shopp'), __('Wrong size', 'Shopp'), __('Found better prices elsewhere', 'Shopp'), __('Product is missing parts', 'Shopp'), __('Product is defective or damaaged', 'Shopp'), __('Took too long to deliver', 'Shopp'), __('Item out of stock', 'Shopp'), __('Customer request to cancel', 'Shopp'), __('Item discontinued', 'Shopp'), __('Other reason', 'Shopp')); } include $this->ui('management.php'); }
public function prepare_items() { $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'paged' => 1, 'per_page' => 20, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $this->request()); extract($args, EXTR_SKIP); // $url = $this->url($_GET); $statusLabels = shopp_setting('order_status'); if (empty($statusLabels)) { $statusLabels = array(''); } $txnstatus_labels = Lookup::txnstatus_labels(); $Purchase = new ShoppPurchase(); $offset = get_option('gmt_offset') * 3600; if ($this->request('start')) { list($month, $day, $year) = explode("/", $this->request('start')); $starts = mktime(0, 0, 0, $month, $day, $year); } if ($this->request('end')) { list($month, $day, $year) = explode("/", $this->request('end')); $ends = mktime(23, 59, 59, $month, $day, $year); } $pagenum = absint($paged); $start = $per_page * ($pagenum - 1); $where = array(); $joins = array(); if (!empty($status) || '0' === $status) { $where[] = "status='" . sDB::escape($status) . "'"; } if (!empty($s)) { $s = stripslashes($s); $search = array(); if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER) > 0) { foreach ($props as $query) { $keyword = sDB::escape(!empty($query[2]) ? $query[2] : $query[3]); switch (strtolower($query[1])) { case "txn": $search[] = "txnid='{$keyword}'"; break; case "company": $search[] = "company LIKE '%{$keyword}%'"; break; case "gateway": $search[] = "gateway LIKE '%{$keyword}%'"; break; case "cardtype": $search[] = "cardtype LIKE '%{$keyword}%'"; break; case "address": $search[] = "(address LIKE '%{$keyword}%' OR xaddress='%{$keyword}%')"; break; case "city": $search[] = "city LIKE '%{$keyword}%'"; break; case "province": case "state": $search[] = "state='{$keyword}'"; break; case "zip": case "zipcode": case "postcode": $search[] = "postcode='{$keyword}'"; break; case "country": $search[] = "country='{$keyword}'"; break; case "promo": case "discount": $meta_table = ShoppDatabaseObject::tablename(ShoppMetaObject::$table); $joins[$meta_table] = "INNER JOIN {$meta_table} AS m ON m.parent = o.id AND context='purchase'"; $search[] = "m.value LIKE '%{$keyword}%'"; break; case "product": $purchased = ShoppDatabaseObject::tablename(Purchased::$table); $joins[$purchased] = "INNER JOIN {$purchased} AS p ON p.purchase = o.id"; $search[] = "p.name LIKE '%{$keyword}%' OR p.optionlabel LIKE '%{$keyword}%' OR p.sku LIKE '%{$keyword}%'"; break; } } if (empty($search)) { $search[] = "(id='{$s}' OR CONCAT(firstname,' ',lastname) LIKE '%{$s}%')"; } $where[] = "(" . join(' OR ', $search) . ")"; } elseif (strpos($s, '@') !== false) { $where[] = "email='" . sDB::escape($s) . "'"; } else { $where[] = "(id='{$s}' OR CONCAT(firstname,' ',lastname) LIKE '%" . sDB::escape($s) . "%')"; } } if (!empty($starts) && !empty($ends)) { $where[] = "created BETWEEN '" . sDB::mkdatetime($starts) . "' AND '" . sDB::mkdatetime($ends) . "'"; } if (!empty($customer)) { $where[] = "customer=" . intval($customer); } $where = !empty($where) ? "WHERE " . join(' AND ', $where) : ''; $joins = join(' ', $joins); $countquery = "SELECT count(*) as total,SUM(IF(txnstatus IN ('authed','captured'),total,NULL)) AS sales,AVG(IF(txnstatus IN ('authed','captured'),total,NULL)) AS avgsale FROM {$Purchase->_table} AS o {$joins} {$where} ORDER BY o.created DESC LIMIT 1"; $this->ordercount = sDB::query($countquery, 'object'); $query = "SELECT o.* FROM {$Purchase->_table} AS o {$joins} {$where} ORDER BY created DESC LIMIT {$start},{$per_page}"; $this->items = sDB::query($query, 'array', 'index', 'id'); $num_pages = ceil($this->ordercount->total / $per_page); if ($paged > 1 && $paged > $num_pages) { Shopp::redirect(add_query_arg('paged', null, $url)); } $Gateways = Shopp::object()->Gateways; $this->gateways = array_merge($Gateways->modules, array('ShoppFreeOrder' => $Gateways->freeorder)); $this->statuses = (array) shopp_setting('order_status'); $this->txnstatuses = ShoppLookup::txnstatus_labels(); // Convert other date formats to numeric but preserve the order of the month/day/year or day/month/year $date_format = get_option('date_format'); $date_format = preg_replace("/[^A-Za-z0-9]/", '', $date_format); // Force month display to numeric with leading zeros $date_format = str_replace(array('n', 'F', 'M'), 'm/', $date_format); // Force day display to numeric with leading zeros $date_format = str_replace(array('j'), 'd/', $date_format); // Force year display to 4-digits $date_format = str_replace('y', 'Y/', $date_format); $this->dates = trim($date_format, '/'); $this->set_pagination_args(array('total_items' => $this->ordercount->total, 'total_pages' => $this->ordercount->total / $per_page, 'per_page' => $per_page)); }
/** * Provides the current payment status (the transaction status) * * @api `shopp('purchase.payment')` * @since 1.3 * * @param string $result The output * @param array $options The options * @param ShoppPurchase $O The working object * @return string The pay **/ public static function payment($result, $options, $O) { $labels = Lookup::txnstatus_labels(); return isset($labels[$O->txnstatus]) ? $labels[$O->txnstatus] : $O->txnstatus; }
/** * Returns a human readable and translated order status label. * * We may wish to expand this to take account of mapped status labels in Shopp (where merchants * can map their own label like "Completed" to an actual status of "Captured", etc). * * @param $status * @return string */ protected function order_status_label($status) { $labels = Lookup::txnstatus_labels(); return isset($labels[$status]) ? $labels[$status] : ''; }