Ejemplo n.º 1
0
 /**
  * Creates a customer record (and WordPress user) and attaches the order to it
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @return void
  **/
 public function accounts($Event)
 {
     $Purchase = $Event->order();
     if (!$Purchase) {
         shopp_debug('No purchase available for account registration processing.');
         return;
     }
     if (!$this->Customer->exists()) {
         $registration = $Purchase->registration();
         if (empty($registration)) {
             shopp_debug('No purchase registration data available for account registration processing.');
             return;
         }
         $this->Customer->copydata($registration['Customer']);
         $this->Billing->copydata($registration['Billing']);
         $this->Shipping->copydata($registration['Shipping']);
         // Validation already conducted during the checkout process
         add_filter('shopp_validate_registration', '__return_true');
         // Prevent redirection to account page after registration
         add_filter('shopp_registration_redirect', '__return_false');
     }
     ShoppRegistration::process();
     // Update Purchase with link to created customer record
     if (!empty($this->Customer->id)) {
         $Purchase = ShoppPurchase();
         if ($Purchase->id != $Event->order) {
             $Purchase = new ShoppPurchase($Event->order);
         }
         $Purchase->customer = $this->Customer->id;
         $Purchase->billing = $this->Billing->id;
         $Purchase->shipping = $this->Shipping->id;
         $Purchase->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * Handles orders list loading
  *
  * @author Jonathan Davis
  * @since 1.2.1
  *
  * @return void
  **/
 public function loader()
 {
     if (!current_user_can('shopp_orders')) {
         return;
     }
     $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, $_GET);
     extract($args, EXTR_SKIP);
     $url = add_query_arg(array_merge($_GET, array('page' => $this->Admin->pagename('orders'))), admin_url('admin.php'));
     if ($page == "shopp-orders" && !empty($deleting) && !empty($selected) && is_array($selected) && current_user_can('shopp_delete_orders')) {
         foreach ($selected as $selection) {
             $Purchase = new ShoppPurchase($selection);
             $Purchase->load_purchased();
             foreach ($Purchase->purchased as $purchased) {
                 $Purchased = new ShoppPurchased($purchased->id);
                 $Purchased->delete();
             }
             $Purchase->delete();
         }
         if (count($selected) == 1) {
             $this->notice(__('Order deleted.', 'Shopp'));
         } else {
             $this->notice(sprintf(__('%d orders deleted.', 'Shopp'), count($selected)));
         }
     }
     $statusLabels = shopp_setting('order_status');
     if (empty($statusLabels)) {
         $statusLabels = array('');
     }
     $txnstatus_labels = Lookup::txnstatus_labels();
     if ($update == "order" && !empty($selected) && is_array($selected)) {
         foreach ($selected as $selection) {
             $Purchase = new ShoppPurchase($selection);
             $Purchase->status = $newstatus;
             $Purchase->save();
         }
         if (count($selected) == 1) {
             $this->notice(__('Order status updated.', 'Shopp'));
         } else {
             $this->notice(sprintf(__('%d orders updated.', 'Shopp'), count($selected)));
         }
     }
     $Purchase = new ShoppPurchase();
     $offset = get_option('gmt_offset') * 3600;
     if (!empty($start)) {
         $startdate = $start;
         list($month, $day, $year) = explode("/", $startdate);
         $starts = mktime(0, 0, 0, $month, $day, $year);
     }
     if (!empty($end)) {
         $enddate = $end;
         list($month, $day, $year) = explode("/", $enddate);
         $ends = mktime(23, 59, 59, $month, $day, $year);
     }
     $pagenum = absint($paged);
     $start = $per_page * ($pagenum - 1);
     $where = array();
     $joins = array();
     if (!empty($status) || $status === '0') {
         $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->orders = 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));
     }
 }
Ejemplo n.º 3
0
 public function save_totals()
 {
     if (!$this->form('save-totals')) {
         return;
     }
     $Purchase = new ShoppPurchase($this->form('id'));
     if (!$Purchase->exists()) {
         return;
     }
     $totals = array();
     if ($this->form('totals')) {
         $totals = $this->form('totals');
     }
     $objects = array('tax' => 'OrderAmountTax', 'shipping' => 'OrderAmountShipping', 'discount' => 'OrderAmountDiscount');
     $methods = array('fee' => 'fees', 'tax' => 'taxes', 'shipping' => 'shipfees', 'discount' => 'discounts');
     $total = 0;
     foreach ($totals as $property => $fields) {
         if (empty($fields)) {
             continue;
         }
         if (count($fields) > 1) {
             if (isset($fields['labels'])) {
                 $labels = $fields['labels'];
                 unset($fields['labels']);
                 if (count($fields) > count($labels)) {
                     $totalfield = array_pop($fields);
                 }
                 $fields = array_combine($labels, $fields);
             }
             $fields = array_map(array('Shopp', 'floatval'), $fields);
             $entries = array();
             $OrderAmountObject = isset($objects[$property]) ? $objects[$property] : 'OrderAmountFee';
             foreach ($fields as $label => $amount) {
                 $entries[] = new $OrderAmountObject(array('id' => count($entries) + 1, 'label' => $label, 'amount' => $amount));
             }
             $savetotal = isset($methods[$property]) ? $methods[$property] : $fees;
             $Purchase->{$savetotal}($entries);
             $sum = array_sum($fields);
             if ($sum > 0) {
                 $Purchase->{$property} = $sum;
             }
         } else {
             $Purchase->{$property} = Shopp::floatval($fields[0]);
         }
         $total += 'discount' == $property ? $Purchase->{$property} * -1 : $Purchase->{$property};
     }
     $Purchase->total = $Purchase->subtotal + $total;
     $Purchase->save();
 }