示例#1
0
 /**
  * Populate extended fields loaded from the ShoppMetaObject
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function expopulate()
 {
     parent::expopulate();
     if (is_string($this->uri)) {
         $this->uri = stripslashes($this->uri);
     }
 }
示例#2
0
 public function add_pending_referral($order_id = 0)
 {
     if ($this->was_referred()) {
         $this->order = apply_filters('affwp_get_shopp_order', shopp_order($order_id->order));
         $customer_email = $this->order->email;
         if ($this->is_affiliate_email($customer_email)) {
             return;
             // Customers cannot refer themselves
         }
         $description = '';
         foreach ($this->order->purchased as $key => $item) {
             $description .= $item->name;
             if ($key + 1 < count($this->order->purchased)) {
                 $description .= ', ';
             }
         }
         $amount = $this->order->total;
         if (affiliate_wp()->settings->get('exclude_tax')) {
             $amount -= $this->order->tax;
         }
         if (affiliate_wp()->settings->get('exclude_shipping')) {
             $amount -= $this->order->shipping;
         }
         $referral_total = $this->calculate_referral_amount($amount, $order_id->order);
         $this->insert_pending_referral($referral_total, $order_id->order, $description);
         $referral = affiliate_wp()->referrals->get_by('reference', $order_id->order, 'shopp');
         $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
         $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
         $user = wp_get_current_user();
         $Note = new ShoppMetaObject();
         $Note->parent = $order_id->order;
         $Note->context = 'purchase';
         $Note->type = 'order_note';
         $Note->value = new stdClass();
         $Note->value->author = $user->ID;
         $Note->value->message = sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name);
         $Note->save();
     }
 }
示例#3
0
 public function info(ShoppCustomer $Customer)
 {
     if (false === $this->form('info')) {
         return $Customer;
     }
     $info = $this->form('info');
     foreach ((array) $field as $id => $value) {
         $Meta = new ShoppMetaObject($id);
         $Meta->value = $value;
         $Meta->save();
     }
     return $Customer;
 }
示例#4
0
 public function addnote($order, $message, $sent = false)
 {
     $user = wp_get_current_user();
     $Note = new ShoppMetaObject();
     $Note->parent = $order;
     $Note->context = 'purchase';
     $Note->type = 'order_note';
     $Note->name = 'note';
     $Note->value = new stdClass();
     $Note->value->author = $user->ID;
     $Note->value->message = $message;
     $Note->value->sent = $sent;
     $Note->save();
 }
示例#5
0
 function load()
 {
     $args = func_get_args();
     if (empty($args[0])) {
         return false;
     }
     if (!is_array($args[0])) {
         return false;
     }
     $where = "";
     foreach ($args[0] as $key => $id) {
         $where .= ($where == "" ? "" : " AND ") . "{$key}='" . sDB::escape($id) . "'";
     }
     $r = sDB::query("SELECT * FROM {$this->_table} WHERE {$where}", 'array');
     foreach ($r as $row) {
         $meta = new ShoppMetaObject();
         $meta->populate($row, '', array());
         $this->meta[$meta->id] = $meta;
         $this->named[$meta->name] =& $this->meta[$meta->id];
     }
     if (isset($row) && count($row) == 0) {
         $this->_loaded = false;
     }
     $this->_loaded = true;
     return $this->_loaded;
 }
示例#6
0
 /**
  * Handles saving updates from the product editor
  *
  * Saves all product related information which includes core product data
  * and supporting elements such as images, digital downloads, tags,
  * assigned categories, specs and pricing variations.
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @param Product $Product
  * @return void
  **/
 public function save(ShoppProduct $Product)
 {
     check_admin_referer('shopp-save-product');
     if (!current_user_can('shopp_products')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     ShoppSettings()->saveform();
     // Save workflow setting
     $status = $Product->status;
     // Set publish date
     if ('publish' == $_POST['status']) {
         $publishing = isset($_POST['publish']) ? $_POST['publish'] : array();
         $fields = array('month' => '', 'date' => '', 'year' => '', 'hour' => '', 'minute' => '', 'meridiem' => '');
         $publishdate = join('', array_merge($fields, $publishing));
         if (!empty($publishdate)) {
             $publish =& $_POST['publish'];
             if ($publish['meridiem'] == "PM" && $publish['hour'] < 12) {
                 $publish['hour'] += 12;
             }
             $publish = mktime($publish['hour'], $publish['minute'], 0, $publish['month'], $publish['date'], $publish['year']);
             $Product->status = 'future';
             unset($_POST['status']);
         } else {
             unset($_POST['publish']);
             // Auto set the publish date if not set (or more accurately, if set to an irrelevant timestamp)
             if ($Product->publish <= 86400) {
                 $Product->publish = null;
             }
         }
     } else {
         unset($_POST['publish']);
         $Product->publish = 0;
     }
     // Set a unique product slug
     if (empty($Product->slug)) {
         $Product->slug = sanitize_title($_POST['name']);
     }
     $Product->slug = wp_unique_post_slug($Product->slug, $Product->id, $Product->status, ShoppProduct::posttype(), 0);
     $Product->featured = 'off';
     if (isset($_POST['content'])) {
         $_POST['description'] = $_POST['content'];
     }
     $Product->updates($_POST, array('meta', 'categories', 'prices', 'tags'));
     do_action('shopp_pre_product_save');
     $Product->save();
     // Remove deleted images
     if (!empty($_POST['deleteImages'])) {
         $deletes = array();
         if (strpos($_POST['deleteImages'], ",") !== false) {
             $deletes = explode(',', $_POST['deleteImages']);
         } else {
             $deletes = array($_POST['deleteImages']);
         }
         $Product->delete_images($deletes);
     }
     // Update image data
     if (!empty($_POST['images']) && is_array($_POST['images'])) {
         $Product->link_images($_POST['images']);
         $Product->save_imageorder($_POST['images']);
         if (!empty($_POST['imagedetails'])) {
             $Product->update_images($_POST['imagedetails']);
         }
     }
     // Update Prices
     if (!empty($_POST['price']) && is_array($_POST['price'])) {
         // Delete prices that were marked for removal
         if (!empty($_POST['deletePrices'])) {
             $deletes = array();
             if (strpos($_POST['deletePrices'], ",")) {
                 $deletes = explode(',', $_POST['deletePrices']);
             } else {
                 $deletes = array($_POST['deletePrices']);
             }
             foreach ($deletes as $option) {
                 $Price = new ShoppPrice($option);
                 $Price->delete();
             }
         }
         $Product->resum();
         // Save prices that there are updates for
         foreach ($_POST['price'] as $i => $priceline) {
             if (empty($priceline['id'])) {
                 $Price = new ShoppPrice();
                 $priceline['product'] = $Product->id;
             } else {
                 $Price = new ShoppPrice($priceline['id']);
             }
             $priceline['sortorder'] = array_search($i, $_POST['sortorder']) + 1;
             $priceline['shipfee'] = Shopp::floatval($priceline['shipfee']);
             if (isset($priceline['recurring']['trialprice'])) {
                 $priceline['recurring']['trialprice'] = Shopp::floatval($priceline['recurring']['trialprice']);
             }
             if ($Price->stock != $priceline['stocked']) {
                 $priceline['stock'] = (int) $priceline['stocked'];
                 do_action('shopp_stock_product', $priceline['stock'], $Price, $Price->stock, $Price->stocklevel);
             } else {
                 unset($priceline['stocked']);
             }
             $Price->updates($priceline);
             $Price->save();
             // Save 'price' meta records after saving the price record
             if (isset($priceline['dimensions']) && is_array($priceline['dimensions'])) {
                 $priceline['dimensions'] = array_map(array('Shopp', 'floatval'), $priceline['dimensions']);
             }
             $settings = array('donation', 'recurring', 'membership', 'dimensions');
             $priceline['settings'] = array();
             foreach ($settings as $setting) {
                 if (!isset($priceline[$setting])) {
                     continue;
                 }
                 $priceline['settings'][$setting] = $priceline[$setting];
             }
             if (!empty($priceline['settings'])) {
                 shopp_set_meta($Price->id, 'price', 'settings', $priceline['settings']);
             }
             if (!empty($priceline['options'])) {
                 shopp_set_meta($Price->id, 'price', 'options', $priceline['options']);
             }
             $Product->sumprice($Price);
             if (!empty($priceline['download'])) {
                 $Price->attach_download($priceline['download']);
             }
             if (!empty($priceline['downloadpath'])) {
                 // Attach file specified by URI/path
                 if (!empty($Price->download->id) || empty($Price->download) && $Price->load_download()) {
                     $File = $Price->download;
                 } else {
                     $File = new ProductDownload();
                 }
                 $stored = false;
                 $tmpfile = sanitize_path($priceline['downloadpath']);
                 $File->storage = false;
                 $Engine = $File->engine();
                 // Set engine from storage settings
                 $File->parent = $Price->id;
                 $File->context = "price";
                 $File->type = "download";
                 $File->name = !empty($priceline['downloadfile']) ? $priceline['downloadfile'] : basename($tmpfile);
                 $File->filename = $File->name;
                 if ($File->found($tmpfile)) {
                     $File->uri = $tmpfile;
                     $stored = true;
                 } else {
                     $stored = $File->store($tmpfile, 'file');
                 }
                 if ($stored) {
                     $File->readmeta();
                     $File->save();
                 }
             }
             // END attach file by path/uri
         }
         // END foreach()
         unset($Price);
     }
     // END if (!empty($_POST['price']))
     $Product->load_sold($Product->id);
     // Refresh accurate product sales stats
     $Product->sumup();
     // Update taxonomies after pricing summary is generated
     // Summary table entry is needed for ProductTaxonomy::recount() to
     // count properly based on aggregate product inventory, see #2968
     foreach (get_object_taxonomies(Product::$posttype) as $taxonomy) {
         $tags = '';
         $taxonomy_obj = get_taxonomy($taxonomy);
         if (isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy])) {
             $tags = $_POST['tax_input'][$taxonomy];
             if (is_array($tags)) {
                 // array = hierarchical, string = non-hierarchical.
                 $tags = array_filter($tags);
             }
         }
         if (current_user_can($taxonomy_obj->cap->assign_terms)) {
             wp_set_post_terms($Product->id, $tags, $taxonomy);
         }
     }
     // Ensure taxonomy counts are updated on status changes, see #2968
     if ($status != $_POST['status']) {
         $Post = new StdClass();
         $Post->ID = $Product->id;
         $Post->post_type = ShoppProduct::$posttype;
         wp_transition_post_status($_POST['status'], $Product->status, $Post);
     }
     if (!empty($_POST['meta']['options'])) {
         $_POST['meta']['options'] = stripslashes_deep($_POST['meta']['options']);
     } else {
         $_POST['meta']['options'] = false;
     }
     // No variation options at all, delete all variation-pricelines
     if (!empty($Product->prices) && is_array($Product->prices) && (empty($_POST['meta']['options']['v']) || empty($_POST['meta']['options']['a']))) {
         foreach ($Product->prices as $priceline) {
             // Skip if not tied to variation options
             if ($priceline->optionkey == 0) {
                 continue;
             }
             if (empty($_POST['meta']['options']['v']) && $priceline->context == "variation" || empty($_POST['meta']['options']['a']) && $priceline->context == "addon") {
                 $Price = new ShoppPrice($priceline->id);
                 $Price->delete();
             }
         }
     }
     // Handle product spec/detail data
     if (!empty($_POST['details']) || !empty($_POST['deletedSpecs'])) {
         // Delete specs queued for removal
         $ids = array();
         $deletes = array();
         if (!empty($_POST['deletedSpecs'])) {
             if (strpos($_POST['deleteImages'], ",") !== false) {
                 $deletes = explode(',', $_POST['deleteImages']);
             } else {
                 $deletes = array($_POST['deletedSpecs']);
             }
             $ids = db::escape($_POST['deletedSpecs']);
             $Spec = new Spec();
             db::query("DELETE FROM {$Spec->_table} WHERE id IN ({$ids})");
         }
         if (is_array($_POST['details'])) {
             foreach ($_POST['details'] as $i => $spec) {
                 if (in_array($spec['id'], $deletes)) {
                     continue;
                 }
                 if (isset($spec['new'])) {
                     $Spec = new Spec();
                     $spec['id'] = '';
                     $spec['parent'] = $Product->id;
                 } else {
                     $Spec = new Spec($spec['id']);
                 }
                 $spec['sortorder'] = array_search($i, $_POST['details-sortorder']) + 1;
                 $Spec->updates($spec);
                 $Spec->save();
             }
         }
     }
     // Save any meta data
     if (isset($_POST['meta']) && is_array($_POST['meta'])) {
         foreach ($_POST['meta'] as $name => $value) {
             if (isset($Product->meta[$name])) {
                 $Meta = $Product->meta[$name];
                 if (is_array($Meta)) {
                     $Meta = reset($Product->meta[$name]);
                 }
             } else {
                 $Meta = new ShoppMetaObject(array('parent' => $Product->id, 'context' => 'product', 'type' => 'meta', 'name' => $name));
             }
             $Meta->parent = $Product->id;
             $Meta->name = $name;
             $Meta->value = $value;
             $Meta->save();
         }
     }
     $Product->load_data();
     // Reload data so everything is fresh for shopp_product_saved
     do_action_ref_array('shopp_product_saved', array(&$Product));
     unset($Product);
 }
示例#7
0
 public function updates(array $data, array $ignores = array())
 {
     parent::updates($data, $ignores);
     if (preg_match('/^.*?(\\d+[\\.\\,\\d]*).*$/', $this->value)) {
         $this->numeral = preg_replace('/^.*?(\\d+[\\.\\,\\d]*).*$/', '$1', $this->value);
     }
 }
示例#8
0
 public function save()
 {
     $properties = array('name' => null, 'slug' => null, 'description' => null, 'parent' => null);
     $updates = array_intersect_key(get_object_vars($this), $properties);
     remove_filter('pre_term_description', 'wp_filter_kses');
     // Allow HTML in category descriptions
     if ($this->id) {
         wp_update_term($this->id, $this->taxonomy, $updates);
     } else {
         list($this->id, $this->term_taxonomy_id) = array_values(wp_insert_term($this->name, $this->taxonomy, $updates));
     }
     if (!$this->id) {
         return false;
     }
     // If the term successfully saves, save all meta data too
     foreach ($this->meta as $name => $Meta) {
         if (is_a($Meta, 'ShoppMetaObject')) {
             $MetaObject = $Meta;
         } else {
             $MetaObject = new ShoppMetaObject();
             $MetaObject->populate($Meta);
         }
         $MetaObject->parent = $this->id;
         $MetaObject->context = 'category';
         $MetaObject->save();
     }
     return true;
 }
示例#9
0
 /**
  * Save the record to the database
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @return void
  **/
 public function save()
 {
     if (empty($this->password)) {
         // Do not save empty password updates
         unset($this->password);
     }
     parent::save();
     if (empty($this->info) || !is_array($this->info)) {
         return true;
     }
     foreach ((array) $this->info as $name => $value) {
         $Meta = new ShoppMetaObject(array('parent' => $this->id, 'context' => 'customer', 'type' => 'meta', 'name' => $name));
         $Meta->parent = $this->id;
         $Meta->context = 'customer';
         $Meta->type = 'meta';
         $Meta->name = $name;
         $Meta->value = $value;
         $Meta->save();
     }
 }
示例#10
0
/**
 * Remove a meta entry by meta id, or parent id, context, type, and name
 *
 * @api
 * @since 1.2
 *
 * @param int $id (required) - meta entry id or, with context, the parent object id
 * @param int $context (required for parent object id) - the parent object context
 * @param string $name (required with parent object context) - the meta name
 * @param string $type  (optional default: meta) - the meta type
 * @return bool true if the meta entry was removed, false on failure
 **/
function shopp_rmv_meta($id = false, $context = false, $name = false, $type = 'meta')
{
    if (!($id || $id && $context)) {
        shopp_debug(__FUNCTION__ . " failed: Must specify at least a meta id or parent id and context.");
        return false;
    }
    // remove existing meta record by meta id
    if ($id && !$context) {
        $meta = new ShoppMetaObject();
        $meta->load($id);
        if ($meta->id) {
            $meta->delete();
        }
        return true;
    }
    // fully spec'd meta entry
    if ($id && $context && $type && $name) {
        $meta = new ShoppMetaObject();
        $meta->load(array('parent' => $id, 'context' => $context, 'type' => $type, 'name' => $name));
        if ($meta->id) {
            $meta->delete();
        }
        return true;
    }
    // general meta entries
    if ($id && $context) {
        $table = ShoppDatabaseObject::tablename(ShoppMetaObject::$table);
        $id = db::escape($id);
        $context = db::escape($context);
        $name = db::escape($name);
        $type = db::escape($type);
        $where = "parent={$id} AND context='{$context}'";
        $where .= $type && !empty($type) ? " AND type='{$type}'" : "";
        $where .= $name && !empty($name) ? " AND type='{$name}'" : "";
        return db::query("DELETE FROM {$table} WHERE {$where}");
    }
}
示例#11
0
 public function metaloader(&$records, &$record)
 {
     if (empty($this->categories)) {
         return;
     }
     if (empty($record->name)) {
         return;
     }
     if (is_array($this->categories) && isset($this->categories[$record->parent])) {
         $target = $this->categories[$record->parent];
     } else {
         return;
     }
     $Meta = new ShoppMetaObject();
     $Meta->populate($record);
     $target->meta[$record->name] = $Meta;
     if (!isset($this->{$record->name})) {
         $target->{$record->name} =& $Meta->value;
     }
 }
示例#12
0
 /**
  * Interface processor for the customer list screen
  *
  * Handles processing customer list actions and displaying the
  * customer list screen
  *
  * @author Jonathan Davis
  * @return void
  **/
 public function customers()
 {
     global $wpdb;
     $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'paged' => false, 'per_page' => 20, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => '');
     $args = array_merge($defaults, $_GET);
     extract($args, EXTR_SKIP);
     if ($page == $this->Admin->pagename('customers') && !empty($deleting) && !empty($selected) && is_array($selected) && current_user_can('shopp_delete_customers')) {
         foreach ($selected as $deletion) {
             $Customer = new ShoppCustomer($deletion);
             $Billing = new BillingAddress($Customer->id, 'customer');
             $Billing->delete();
             $Shipping = new ShippingAddress($Customer->id, 'customer');
             $Shipping->delete();
             $Customer->delete();
         }
     }
     $updated = false;
     if (!empty($_POST['save'])) {
         check_admin_referer('shopp-save-customer');
         $wp_integration = 'wordpress' === shopp_setting('account_system');
         if ($_POST['id'] !== 'new') {
             $Customer = new ShoppCustomer($_POST['id']);
             $Billing = new BillingAddress($Customer->id, 'customer');
             $Shipping = new ShippingAddress($Customer->id, 'customer');
         } else {
             $Customer = new ShoppCustomer();
         }
         if (!empty($Customer->wpuser)) {
             $user = get_user_by('id', $Customer->wpuser);
         }
         $new_customer = empty($Customer->id);
         $Customer->updates($_POST);
         // Reassign WordPress login
         if ($wp_integration && isset($_POST['userlogin']) && $_POST['userlogin'] != $user->user_login) {
             $newlogin = get_user_by('login', $_POST['userlogin']);
             if (!empty($newlogin->ID)) {
                 if (sDB::query("SELECT count(*) AS used FROM {$Customer->_table} WHERE wpuser={$newlogin->ID}", 'auto', 'col', 'used') == 0) {
                     $Customer->wpuser = $newlogin->ID;
                     $updated = sprintf(__('Updated customer login to %s.', 'Shopp'), "<strong>{$newlogin->user_login}</strong>");
                 } else {
                     $updated = sprintf(__('Could not update customer login to &quot;%s&quot; because that user is already assigned to another customer.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
                 }
             } else {
                 $updated = sprintf(__('Could not update customer login to &quot;%s&quot; because the user does not exist in WordPress.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
             }
             if (empty($_POST['userlogin'])) {
                 $Customer->wpuser = 0;
             }
         }
         if (!empty($_POST['new-password']) && !empty($_POST['confirm-password']) && $_POST['new-password'] == $_POST['confirm-password']) {
             $Customer->password = wp_hash_password($_POST['new-password']);
             if (!empty($Customer->wpuser)) {
                 wp_set_password($_POST['new-password'], $Customer->wpuser);
             }
         }
         $valid_email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
         $password = !empty($_POST['new_password']);
         if ($wp_integration && $new_customer && $valid_email && $password) {
             $Customer->loginname = $_POST['userlogin'];
             $Customer->email = $_POST['email'];
             $Customer->firstname = $_POST['firstname'];
             $Customer->lastname = $_POST['lastname'];
             $return = $Customer->create_wpuser();
             if ($return) {
                 $updated = sprintf(__('The Shopp and WordPress accounts have been created with the username &quot;%s&quot;.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
             } else {
                 $updated = sprintf(__('Could not create a WordPress account for customer &quot;%s&quot;.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
             }
         } elseif ($new_customer && (!$valid_email || !$password)) {
             $updated = __('Could not create new user. You must enter a valid email address and a password first.', 'Shopp');
             $no_save = true;
         }
         if (!isset($new_save)) {
             $Customer->info = false;
             // No longer used from DB
             $Customer->save();
         }
         if (isset($_POST['info']) && !empty($_POST['info'])) {
             foreach ((array) $_POST['info'] as $id => $info) {
                 $Meta = new ShoppMetaObject($id);
                 $Meta->value = $info;
                 $Meta->save();
             }
         }
         if (isset($Customer->id)) {
             $Billing->customer = $Customer->id;
         }
         $Billing->updates($_POST['billing']);
         $Billing->save();
         if (isset($Customer->id)) {
             $Shipping->customer = $Customer->id;
         }
         $Shipping->updates($_POST['shipping']);
         $Shipping->save();
         if (!$updated) {
             __('Customer updated.', 'Shopp');
         }
         $Customer = false;
     }
     $pagenum = absint($paged);
     if (empty($pagenum)) {
         $pagenum = 1;
     }
     if (!$per_page || $per_page < 0) {
         $per_page = 20;
     }
     $index = $per_page * ($pagenum - 1);
     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);
     }
     $customer_table = ShoppDatabaseObject::tablename(Customer::$table);
     $billing_table = ShoppDatabaseObject::tablename(BillingAddress::$table);
     $purchase_table = ShoppDatabaseObject::tablename(ShoppPurchase::$table);
     $users_table = $wpdb->users;
     $where = array();
     if (!empty($s)) {
         $s = stripslashes($s);
         if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER)) {
             foreach ($props as $search) {
                 $keyword = !empty($search[2]) ? $search[2] : $search[3];
                 switch (strtolower($search[1])) {
                     case "company":
                         $where[] = "c.company LIKE '%{$keyword}%'";
                         break;
                     case "login":
                         $where[] = "u.user_login LIKE '%{$keyword}%'";
                         break;
                     case "address":
                         $where[] = "(b.address LIKE '%{$keyword}%' OR b.xaddress='%{$keyword}%')";
                         break;
                     case "city":
                         $where[] = "b.city LIKE '%{$keyword}%'";
                         break;
                     case "province":
                     case "state":
                         $where[] = "b.state='{$keyword}'";
                         break;
                     case "zip":
                     case "zipcode":
                     case "postcode":
                         $where[] = "b.postcode='{$keyword}'";
                         break;
                     case "country":
                         $where[] = "b.country='{$keyword}'";
                         break;
                 }
             }
         } elseif (strpos($s, '@') !== false) {
             $where[] = "c.email='{$s}'";
         } elseif (is_numeric($s)) {
             $where[] = "c.id='{$s}'";
         } else {
             $where[] = "(CONCAT(c.firstname,' ',c.lastname) LIKE '%{$s}%' OR c.company LIKE '%{$s}%')";
         }
     }
     if (!empty($starts) && !empty($ends)) {
         $where[] = ' (UNIX_TIMESTAMP(c.created) >= ' . $starts . ' AND UNIX_TIMESTAMP(c.created) <= ' . $ends . ')';
     }
     $select = array('columns' => 'SQL_CALC_FOUND_ROWS c.*,city,state,country,user_login', 'table' => "{$customer_table} as c", 'joins' => array($billing_table => "LEFT JOIN {$billing_table} AS b ON b.customer=c.id AND b.type='billing'", $users_table => "LEFT JOIN {$users_table} AS u ON u.ID=c.wpuser AND (c.wpuser IS NULL OR c.wpuser != 0)"), 'where' => $where, 'groupby' => "c.id", 'orderby' => "c.created DESC", 'limit' => "{$index},{$per_page}");
     $query = sDB::select($select);
     $Customers = sDB::query($query, 'array', 'index', 'id');
     $total = sDB::found();
     // Add order data to customer records in this view
     $orders = sDB::query("SELECT customer,SUM(total) AS total,count(id) AS orders FROM {$purchase_table} WHERE customer IN (" . join(',', array_keys($Customers)) . ") GROUP BY customer", 'array', 'index', 'customer');
     foreach ($Customers as &$record) {
         $record->total = 0;
         $record->orders = 0;
         if (!isset($orders[$record->id])) {
             continue;
         }
         $record->total = $orders[$record->id]->total;
         $record->orders = $orders[$record->id]->orders;
     }
     $num_pages = ceil($total / $per_page);
     $ListTable = ShoppUI::table_set_pagination($this->screen, $total, $num_pages, $per_page);
     $ranges = array('all' => __('Show New Customers', '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&reg; Excel.xls', 'Shopp'));
     $formatPref = shopp_setting('customerexport_format');
     if (!$formatPref) {
         $formatPref = 'tab';
     }
     $columns = array_merge(Customer::exportcolumns(), BillingAddress::exportcolumns(), ShippingAddress::exportcolumns());
     $selected = shopp_setting('customerexport_columns');
     if (empty($selected)) {
         $selected = array_keys($columns);
     }
     $authentication = shopp_setting('account_system');
     $action = add_query_arg(array('page' => $this->Admin->pagename('customers')), admin_url('admin.php'));
     include $this->ui('customers.php');
 }
示例#13
0
文件: Orders.php 项目: msigley/shopp
 public function edit()
 {
     if (!$this->form('edit-note')) {
         return;
     }
     $edited = $this->form('note-editor');
     $id = key($edited);
     if (empty($edited[$id])) {
         return;
     }
     $Note = new ShoppMetaObject(array('id' => $id, 'type' => 'order_note'));
     if (!$Note->exists()) {
         return;
     }
     $Note->value->message = stripslashes($edited[$id]);
     $Note->save();
     $this->notice(Shopp::__('Note updated.'));
 }