public function screen() { if (!current_user_can('shopp_settings')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // Welcome screen handling if (!empty($_POST['setup'])) { shopp_set_setting('display_welcome', 'off'); } $countries = ShoppLookup::countries(); $basecountry = ShoppBaseLocale()->country(); $countrymenu = Shopp::menuoptions($countries, $basecountry, true); $basestates = ShoppLookup::country_zones(array($basecountry)); $statesmenu = ''; if (!empty($basestates)) { $statesmenu = Shopp::menuoptions($basestates[$basecountry], ShoppBaseLocale()->state(), true); } $targets = shopp_setting('target_markets'); if (is_array($targets)) { $targets = array_map('stripslashes', $targets); } if (!$targets) { $targets = array(); } $zones_ajaxurl = wp_nonce_url(admin_url('admin-ajax.php'), 'wp_ajax_shopp_country_zones'); include $this->ui('setup.php'); }
/** * Interface processor for the customer editor * * Handles rendering the interface, processing updated customer details * and handing saving them back to the database * * @author Jonathan Davis * @return void **/ public function screen() { if (!current_user_can('shopp_customers')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $Customer = $this->load(); if ($Customer->exists()) { $purchase_table = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $r = sDB::query("SELECT count(id) AS purchases,SUM(total) AS total FROM {$purchase_table} WHERE customer='{$Customer->id}' LIMIT 1"); $Customer->orders = $r->purchases; $Customer->total = $r->total; } $regions = ShoppLookup::country_zones(); include $this->ui('editor.php'); }
public function prepare_items() { $this->id = 'taxrates'; $defaults = array('paged' => 1, 'per_page' => 25, 'action' => false); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); $rates = (array) shopp_setting('taxrates'); $this->items = array(); foreach ($rates as $index => $taxrate) { $this->items[$index] = array_merge(self::$template, array('id' => $index), $taxrate); } $specials = array(ShoppTax::ALL => Shopp::__('All Markets')); if (ShoppTax::euvat(false, ShoppBaseLocale()->country(), ShoppTax::EUVAT)) { $specials[ShoppTax::EUVAT] = Shopp::__('European Union'); } $this->countries = array_filter(array_merge($specials, (array) shopp_setting('target_markets'))); $this->zones = ShoppLookup::country_zones(); $total = count($this->items); $this->set_pagination_args(array('total_items' => $total, 'total_pages' => $total / $per_page, 'per_page' => $per_page)); shopp_custom_script('taxrates', ' var suggurl = "' . wp_nonce_url(admin_url('admin-ajax.php'), 'wp_ajax_shopp_suggestions') . '", rates = ' . json_encode($this->items) . ', zones = ' . json_encode($this->zones) . ', lookup = ' . json_encode(ShoppLookup::localities()) . ', taxrates = []; '); }
public function prepare_items() { $active = (array) shopp_setting('active_shipping'); $Shopp = Shopp::object(); $Shipping = $Shopp->Shipping; $Shipping->settings(); // Load all installed shipping modules for settings UIs $Shipping->ui(); // Setup setting UIs $settings = array(); // Registry of loaded settings for table-based shipping rates for JS $this->items = array(); // Registry for activated shipping rate modules $this->installed = array(); // Registry of available shipping modules installed foreach ($Shipping->active as $name => $Module) { if (version_compare($Shipping->modules[$name]->since, '1.2') == -1) { continue; } // Skip 1.1 modules, they are incompatible $default_name = strtolower($name); $fullname = $Module->methods(); $this->installed[$name] = $fullname; if ($Module->ui->tables) { $defaults[$default_name] = $Module->ui->settings(); $defaults[$default_name]['name'] = $fullname; $defaults[$default_name]['label'] = Shopp::__('Shipping Method'); } if (array_key_exists($name, $active)) { $ModuleSetting = $active[$name]; } else { continue; } // Not an activated shipping module, go to the next one $Entry = new StdClass(); $Entry->id = sanitize_title_with_dashes($name); $Entry->label = $Shipping->modules[$name]->name; $Entry->type = $Shipping->modules[$name]->name; $Entry->setting = $name; if ($this->request('id') == $Entry->setting) { $Entry->editor = $Module->ui(); } // Setup shipping service shipping rate entries and settings if (!is_array($ModuleSetting)) { $Entry->destinations = array($Shipping->active[$name]->destinations); $this->items[$name] = $Entry; continue; } // Setup shipping calcualtor shipping rate entries and settings foreach ($ModuleSetting as $id => $m) { $Entry->setting = "{$name}-{$id}"; $Entry->settings = shopp_setting($Entry->setting); if ($this->request('id') == $Entry->setting) { $Entry->editor = $Module->ui(); } if (isset($Entry->settings['label'])) { $Entry->label = $Entry->settings['label']; } $Entry->destinations = array(); $min = $max = false; if (isset($Entry->settings['table']) && is_array($Entry->settings['table'])) { foreach ($Entry->settings['table'] as $tablerate) { $destination = false; $d = ShippingSettingsUI::parse_location($tablerate['destination']); if (!empty($d['zone'])) { $Entry->destinations[] = $d['zone'] . ' (' . $d['countrycode'] . ')'; } elseif (!empty($d['area'])) { $Entry->destinations[] = $d['area']; } elseif (!empty($d['country'])) { $Entry->destinations[] = $d['country']; } elseif (!empty($d['region'])) { $Entry->destinations[] = $d['region']; } } if (!empty($Entry->destinations)) { $Entry->destinations = array_keys(array_flip($Entry->destinations)); } // Combine duplicate destinations } $this->items[$Entry->setting] = $Entry; $settings[$Entry->setting] = shopp_setting($Entry->setting); $settings[$Entry->setting]['id'] = $Entry->setting; $settings[$Entry->setting] = array_merge($defaults[$default_name], $settings[$Entry->setting]); if (isset($settings[$Entry->setting]['table'])) { usort($settings[$Entry->setting]['table'], array('ShippingFramework', '_sorttier')); foreach ($settings[$Entry->setting]['table'] as &$r) { if (isset($r['tiers'])) { usort($r['tiers'], array('ShippingFramework', '_sorttier')); } } } } // end foreach ( $ModuleSetting ) } // end foreach ( $Shipping->active ) $this->set_pagination_args(array('total_items' => count($this->items), 'total_pages' => 1)); $postcodes = ShoppLookup::postcodes(); foreach ($postcodes as &$postcode) { $postcode = !empty($postcode); } $lookup = array('regions' => array_merge(array('*' => Shopp::__('Anywhere')), ShoppLookup::regions()), 'regionmap' => ShoppLookup::regions('id'), 'countries' => ShoppLookup::countries(), 'areas' => ShoppLookup::country_areas(), 'zones' => ShoppLookup::country_zones(), 'postcodes' => $postcodesscre); shopp_custom_script('shiprates', ' var shipping = ' . json_encode(array_map('sanitize_title_with_dashes', array_keys($this->installed))) . ', defaults = ' . json_encode($defaults) . ', settings = ' . json_encode($settings) . ', lookup = ' . json_encode($lookup) . ';'); }
public function country_zones() { check_admin_referer('wp_ajax_shopp_country_zones'); if (isset($_GET['country'])) { $country = $_GET['country']; } $states = ShoppLookup::country_zones(array($country)); if (!empty($states) && isset($states[$country])) { $labels = ShoppLookup::country_divisions($country); array_unshift($states[$country], strtolower($labels[0])); echo json_encode($states[$country]); } else { echo json_encode(false); } exit; }
/** * Provides overall layout for the order manager interface * * Makes use of WordPress postboxes to generate panels (box) content * containers that are customizable with drag & drop, collapsable, and * can be toggled to be hidden or visible in the interface. * * @return **/ public function layout() { $Purchase = ShoppPurchase(); $default = array('' => ' '); $Purchase->_countries = array_merge($default, ShoppLookup::countries()); $regions = ShoppLookup::country_zones(); $Purchase->_billing_states = array_merge($default, (array) $regions[$Purchase->country]); $Purchase->_shipping_states = array_merge($default, (array) $regions[$Purchase->shipcountry]); ShoppUI::register_column_headers($this->id, apply_filters('shopp_order_manager_columns', array('items' => Shopp::__('Items'), 'qty' => Shopp::__('Quantity'), 'price' => Shopp::__('Price'), 'total' => Shopp::__('Total')))); $references = array('Purchase' => $Purchase); new ShoppAdminOrderContactBox($this, 'side', 'core', $references); new ShoppAdminOrderBillingAddressBox($this, 'side', 'high', $references); if (!empty($Purchase->shipaddress)) { new ShoppAdminOrderShippingAddressBox($this, 'side', 'core', $references); } new ShoppAdminOrderManageBox($this, 'normal', 'core', $references); if (isset($Purchase->data) && '' != join('', (array) $Purchase->data) || apply_filters('shopp_orderui_show_orderdata', false)) { new ShoppAdminOrderDataBox($this, 'normal', 'core', $references); } if (count($Purchase->events) > 0) { new ShoppAdminOrderHistoryBox($this, 'normal', 'core', $references); } new ShoppAdminOrderNotesBox($this, 'normal', 'core', $references); do_action('shopp_order_manager_layout'); }
public function shiprates() { if (!current_user_can('shopp_settings_shipping')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $Shopp = Shopp::object(); $Shipping = $Shopp->Shipping; $Shipping->settings(); // Load all installed shipping modules for settings UIs $methods = $Shopp->Shipping->methods; $edit = false; if (isset($_REQUEST['id'])) { $edit = (int) $_REQUEST['id']; } $active = shopp_setting('active_shipping'); if (!$active) { $active = array(); } if (!empty($_GET['delete'])) { check_admin_referer('shopp_delete_shiprate'); $delete = $_GET['delete']; $index = false; if (strpos($delete, '-') !== false) { list($delete, $index) = explode('-', $delete); } if (array_key_exists($delete, $active)) { if (is_array($active[$delete])) { if (array_key_exists($index, $active[$delete])) { unset($active[$delete][$index]); if (empty($active[$delete])) { unset($active[$delete]); } } } else { unset($active[$delete]); } $updated = __('Shipping method setting removed.', 'Shopp'); shopp_set_setting('active_shipping', $active); } } if (isset($_POST['module'])) { check_admin_referer('shopp-settings-shiprate'); $setting = false; $module = isset($_POST['module']) ? $_POST['module'] : false; $id = isset($_POST['id']) ? $_POST['id'] : false; if ($id == $module) { if (isset($_POST['settings'])) { shopp_set_formsettings(); } /** Save shipping service settings **/ $active[$module] = true; shopp_set_setting('active_shipping', $active); $updated = __('Shipping settings saved.', 'Shopp'); // Cancel editing if saving if (isset($_POST['save'])) { unset($_REQUEST['id']); } $Errors = ShoppErrors(); do_action('shopp_verify_shipping_services'); if ($Errors->exist()) { // Get all addon related errors $failures = $Errors->level(SHOPP_ADDON_ERR); if (!empty($failures)) { $updated = __('Shipping settings saved but there were errors: ', 'Shopp'); foreach ($failures as $error) { $updated .= '<p>' . $error->message(true, true) . '</p>'; } } } } else { /** Save shipping calculator settings **/ $setting = $_POST['id']; if (empty($setting)) { // Determine next available setting ID $index = 0; if (is_array($active[$module])) { $index = count($active[$module]); } $setting = "{$module}-{$index}"; } // Cancel editing if saving if (isset($_POST['save'])) { unset($_REQUEST['id']); } $setting_module = $setting; $id = 0; if (false !== strpos($setting, '-')) { list($setting_module, $id) = explode('-', $setting); } // Prevent fishy stuff from happening if ($module != $setting_module) { $module = false; } // Save shipping calculator settings $Shipper = $Shipping->get($module); if ($Shipper && isset($_POST[$module])) { $Shipper->setting($id); $_POST[$module]['label'] = stripslashes($_POST[$module]['label']); // Sterilize $values foreach ($_POST[$module]['table'] as $i => &$row) { if (isset($row['rate'])) { $row['rate'] = Shopp::floatval($row['rate']); } if (!isset($row['tiers'])) { continue; } foreach ($row['tiers'] as &$tier) { if (isset($tier['rate'])) { $tier['rate'] = Shopp::floatval($tier['rate']); } } } // Delivery estimates: ensure max equals or exceeds min ShippingFramework::sensibleestimates($_POST[$module]['mindelivery'], $_POST[$module]['maxdelivery']); shopp_set_setting($Shipper->setting, $_POST[$module]); if (!array_key_exists($module, $active)) { $active[$module] = array(); } $active[$module][(int) $id] = true; shopp_set_setting('active_shipping', $active); $this->notice(Shopp::__('Shipping settings saved.')); } } } $Shipping->settings(); // Load all installed shipping modules for settings UIs $Shipping->ui(); // Setup setting UIs $installed = array(); $shiprates = array(); // Registry for activated shipping rate modules $settings = array(); // Registry of loaded settings for table-based shipping rates for JS foreach ($Shipping->active as $name => $module) { if (version_compare($Shipping->modules[$name]->since, '1.2') == -1) { continue; } // Skip 1.1 modules, they are incompatible $default_name = strtolower($name); $fullname = $module->methods(); $installed[$name] = $fullname; if ($module->ui->tables) { $defaults[$default_name] = $module->ui->settings(); $defaults[$default_name]['name'] = $fullname; $defaults[$default_name]['label'] = __('Shipping Method', 'Shopp'); } if (array_key_exists($name, $active)) { $ModuleSetting = $active[$name]; } else { continue; } // Not an activated shipping module, go to the next one // Setup shipping service shipping rate entries and settings if (!is_array($ModuleSetting)) { $shiprates[$name] = $name; continue; } // Setup shipping calcualtor shipping rate entries and settings foreach ($ModuleSetting as $id => $m) { $setting = "{$name}-{$id}"; $shiprates[$setting] = $name; $settings[$setting] = shopp_setting($setting); $settings[$setting]['id'] = $setting; $settings[$setting] = array_merge($defaults[$default_name], $settings[$setting]); if (isset($settings[$setting]['table'])) { usort($settings[$setting]['table'], array('ShippingFramework', '_sorttier')); foreach ($settings[$setting]['table'] as &$r) { if (isset($r['tiers'])) { usort($r['tiers'], array('ShippingFramework', '_sorttier')); } } } } } if (isset($_REQUEST['id'])) { $edit = $_REQUEST['id']; $id = false; if (strpos($edit, '-') !== false) { list($module, $id) = explode('-', $edit); } else { $module = $edit; } if (isset($Shipping->active[$module])) { $Shipper = $Shipping->get($module); if (!$Shipper->singular) { $Shipper->setting($id); $Shipper->initui($Shipping->modules[$module]->name); // Re-init setting UI with loaded settings } $editor = $Shipper->ui(); } } asort($installed); $postcodes = ShoppLookup::postcodes(); foreach ($postcodes as &$postcode) { $postcode = !empty($postcode); } $lookup = array('regions' => array_merge(array('*' => Shopp::__('Anywhere')), ShoppLookup::regions()), 'regionmap' => ShoppLookup::regions('id'), 'countries' => ShoppLookup::countries(), 'areas' => ShoppLookup::country_areas(), 'zones' => ShoppLookup::country_zones(), 'postcodes' => $postcodes); $ShippingTemplates = new TemplateShippingUI(); add_action('shopp_shipping_module_settings', array($Shipping, 'templates')); include $this->ui('shiprates.php'); }
public function tablerate($table) { $Order = ShoppOrder(); $Address = $Order->Shipping; $countries = ShoppLookup::countries(); $zones = ShoppLookup::country_zones(); $target = array('region' => false, 'country' => false, 'area' => false, 'zone' => false, 'postcode' => false); // Prepare address for comparison $target['region'] = ShoppLookup::region($Address->country, int); $target['country'] = $Address->country; if (isset($Address->postcode) && !empty($Address->postcode)) { $target['postcode'] = $Address->postcode; $Address->postmap(); } if (isset($Address->state) && !empty($Address->state)) { $target['zone'] = $Address->state; $areas = Lookup::country_areas(); if (isset($areas[$Address->country]) && !empty($areas[$Address->country])) { $target['area'] = array(); foreach ($areas[$Address->country] as $areaname => $areazones) { if (!in_array($Address->state, $areazones)) { continue; } $target['area'][] = $areaname; } rsort($target['area']); if (empty($target['area'])) { $target['area'] = false; } } else { $target['area'] = $target['zone']; } } // Sort table rules more specific to more generic matching usort($table, array('ShippingFramework', '_sorttable')); // Evaluate each destination rule foreach ($table as $index => $rate) { $r = Shopp::floatval(isset($rate['rate']) ? $rate['rate'] : 0); if (isset($rate['tiers'])) { $r = $rate['tiers']; usort($r, array('ShippingFramework', '_sorttier')); } $dr = strpos($rate['destination'], ',') !== false ? explode(',', $rate['destination']) : array($rate['destination']); $k = array_keys(array_slice($target, 0, count($dr))); $rule = array_combine($k, $dr); if (isset($rate['postcode']) && !empty($rate['postcode']) && '*' != $rate['postcode']) { $rule['postcode'] = $rate['postcode']; } $match = array_intersect_key($target, $rule); $d = array_diff($rule, $match); // Use the rate if the destination rule is for anywhere if ('*' == $rule['region']) { return $r; } // Exact match FTW! if (empty($d)) { return $r; } // Handle special case for area matching if (!empty($d['area']) && is_array($match['area'])) { // Some countries can have multiple country areas // the target address can match on (most specific matches first) if (in_array($rule['area'], $match['area'])) { unset($d['area']); } // Clear excpetion to match } // Handle postcode matching if (!empty($d['postcode'])) { if (false !== strpos($rule['postcode'], ',')) { $postcodes = explode(',', $rule['postcode']); } else { $postcodes = array($rule['postcode']); } //Exclusive rules need to be evaluated first usort($postcodes, create_function('$a, $b', '$a = ( "!" == $a{0} ); $b = ( "!" == $b{0} ); if ( $a == $b ) return 0; return ( $a < $b ) ? -1 : 1;')); $exclusions = 0; foreach ($postcodes as $coderule) { $coderule = trim($coderule); // Determine if rule is exclusive $exclude = false; if ('!' == substr($coderule, 0, 1)) { $exclude = true; $exclusions++; $coderule = substr($coderule, 1); } // Match numeric postcode ranges (only works for pure numeric postcodes like US zip codes) // Cannot be mixed with wildcard ranges (eg 55*-56* does not work, use 55000-56999) if (false !== strpos($coderule, '-')) { list($start, $end) = explode('-', $coderule); if ($match['postcode'] >= $start && $match['postcode'] <= $end) { if ($exclude) { return false; } unset($d['postcode']); // Clear exception to match } continue; } // Match wildcard postcode patterns if (false !== strpos($coderule, '*')) { $pattern = str_replace('*', '(.+?)', $coderule); if (preg_match("/^{$pattern}\$/i", $match['postcode'])) { if ($exclude) { return false; } unset($d['postcode']); // Clear exception to match } continue; } // Exact match if ($coderule == $match['postcode']) { if ($exclude) { return false; } unset($d['postcode']); // Clear exception to match continue; } } if ($exclusions == count($postcodes)) { unset($d['postcode']); } //All of the rules were exclusive and passed, clear exception } // If exceptions were cleared, return the matching rate if (empty($d)) { return $r; } } // No matches found!? return false; }
/** * Displays the General Settings screen and processes updates * * @author Jonathan Davis * @since 1.0 * * @return void **/ public function setup() { if (!current_user_can('shopp_settings')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // Welcome screen handling if (!empty($_POST['setup'])) { shopp_set_setting('display_welcome', 'off'); } $countries = ShoppLookup::countries(); $states = array(); // Save settings if (!empty($_POST['save']) && isset($_POST['settings'])) { check_admin_referer('shopp-setup'); if (!isset($_POST['settings']['target_markets'])) { asort($_POST['settings']['target_markets']); } shopp_set_formsettings(); if (isset($_POST['settings']['base_locale'])) { $baseop =& $_POST['settings']['base_locale']; if (isset($countries[strtoupper($baseop['country'])])) { // Validate country $country = strtoupper($baseop['country']); $state = ''; if (!empty($baseop['state'])) { // Valid state $states = ShoppLookup::country_zones(array($country)); if (isset($states[$country][strtoupper($baseop['state'])])) { $state = strtoupper($baseop['state']); } } ShoppBaseLocale()->save($country, $state); } shopp_set_setting('tax_inclusive', in_array($country, Lookup::country_inclusive_taxes()) ? 'on' : 'off'); } $updated = __('Shopp settings saved.', 'Shopp'); } $basecountry = ShoppBaseLocale()->country(); $countrymenu = Shopp::menuoptions($countries, $basecountry, true); $basestates = ShoppLookup::country_zones(array($basecountry)); $statesmenu = Shopp::menuoptions($basestates[$basecountry], ShoppBaseLocale()->state(), true); $targets = shopp_setting('target_markets'); if (is_array($targets)) { $targets = array_map('stripslashes', $targets); } if (!$targets) { $targets = array(); } include $this->ui('setup.php'); }