public function lookup($code = false) { $countries = ShoppLookup::countries(); if (!isset($countries[$code])) { return false; } $this->code = $code; $this->name = $countries[$code]; // Currency $currencies = (include $this->data('currencies.php')); $currency = Shopp::array_search_deep($code, $currencies); $this->Currency = new ShoppLocaleCurrency($currency, $code); // Region $regions = (include $this->data('regions.php')); $this->region = Shopp::array_search_deep($code, $regions); // Addressing $addrs = (include $this->data('addressing.php')); if (isset($addrs[$code])) { $this->addressing = $addrs[$code]; } else { $this->addressing = SHOPP_DEFAULT_ADDRESSING; } // Units $imperial = array_flip(ShoppLookup::imperial_units()); if (isset($imperial[$code])) { $this->units = 'imperial'; } }
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'); }
/** * Builds the interface layout for the customer editor * * @author Jonathan Davis * @return void **/ public function layout() { $Shopp = Shopp::object(); $Admin = ShoppAdmin(); $Customer = $this->Model; $default = array('' => ' '); $countries = array_merge($default, ShoppLookup::countries()); $Customer->_countries = $countries; $states = ShoppLookup::country_zones(array($Customer->Billing->country, $Customer->Shipping->country)); $Customer->_billing_states = array_merge($default, (array) $states[$Customer->Billing->country]); $Customer->_shipping_states = array_merge($default, (array) $states[$Customer->Shipping->country]); new ShoppAdminCustomerSaveBox($this->id, 'side', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerSettingsBox($this->id, 'side', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerLoginBox($this->id, 'side', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerContactBox($this->id, 'normal', 'core', array('Customer' => $Customer)); if (!empty($Customer->info->meta) && is_array($Customer->info->meta)) { new ShoppAdminCustomerInfoBox($this->id, 'normal', 'core', array('Customer' => $Customer)); } new ShoppAdminCustomerBillingAddressBox($this->id, 'normal', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerShippingAddressBox($this->id, 'normal', 'core', array('Customer' => $Customer)); }
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) . ';'); }
function screen() { if (!current_user_can('shopp_orders')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } $Purchase = ShoppPurchase(); $Purchase->Customer = new ShoppCustomer($Purchase->customer); $Gateway = $Purchase->gateway(); if (!empty($_POST['send-note'])) { $user = wp_get_current_user(); shopp_add_order_event($Purchase->id, 'note', array('note' => stripslashes($_POST['note']), 'user' => $user->ID)); $Purchase->load_events(); } if (isset($_POST['submit-shipments']) && isset($_POST['shipment']) && !empty($_POST['shipment'])) { $shipments = $_POST['shipment']; foreach ((array) $shipments as $shipment) { shopp_add_order_event($Purchase->id, 'shipped', array('tracking' => $shipment['tracking'], 'carrier' => $shipment['carrier'])); } $updated = __('Shipping notice sent.', 'Shopp'); // Save shipping carrier default preference for the user $userid = get_current_user_id(); $setting = 'shopp_shipping_carrier'; if (!get_user_meta($userid, $setting, true)) { add_user_meta($userid, $setting, $shipment['carrier']); } else { update_user_meta($userid, $setting, $shipment['carrier']); } unset($_POST['ship-notice']); $Purchase->load_events(); } if (isset($_POST['order-action']) && 'refund' == $_POST['order-action']) { if (!current_user_can('shopp_refund')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } $user = wp_get_current_user(); $reason = (int) $_POST['reason']; $amount = Shopp::floatval($_POST['amount']); if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } if (!Shopp::str_true($_POST['send'])) { // Force the order status shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'refunded', 'notice' => __('Marked Refunded', 'Shopp'))); shopp_add_order_event($Purchase->id, 'refunded', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount)); shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module)); } else { shopp_add_order_event($Purchase->id, 'refund', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount, 'reason' => $reason, 'user' => $user->ID)); } if (!empty($_POST['message'])) { $this->addnote($Purchase->id, $_POST['message']); } $Purchase->load_events(); } if (isset($_POST['order-action']) && 'cancel' == $_POST['order-action']) { if (!current_user_can('shopp_void')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } // unset($_POST['refund-order']); $user = wp_get_current_user(); $reason = (int) $_POST['reason']; $message = ''; if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } else { $message = 0; } if (!Shopp::str_true($_POST['send'])) { // Force the order status shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'cancelled', 'notice' => __('Marked Cancelled', 'Shopp'))); shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module)); } else { shopp_add_order_event($Purchase->id, 'void', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'reason' => $reason, 'user' => $user->ID, 'note' => $message)); } if (!empty($_POST['message'])) { $this->addnote($Purchase->id, $_POST['message']); } $Purchase->load_events(); } if (isset($_POST['billing']) && is_array($_POST['billing'])) { $Purchase->updates($_POST['billing']); $Purchase->save(); } if (isset($_POST['shipping']) && is_array($_POST['shipping'])) { $shipping = array(); foreach ($_POST['shipping'] as $name => $value) { $shipping["ship{$name}"] = $value; } $Purchase->updates($shipping); $Purchase->shipname = $shipping['shipfirstname'] . ' ' . $shipping['shiplastname']; $Purchase->save(); } if (isset($_POST['order-action']) && 'update-customer' == $_POST['order-action'] && !empty($_POST['customer'])) { $Purchase->updates($_POST['customer']); $Purchase->save(); } if (isset($_POST['cancel-edit-customer'])) { unset($_POST['order-action'], $_POST['edit-customer'], $_POST['select-customer']); } // Create a new customer if (isset($_POST['order-action']) && 'new-customer' == $_POST['order-action'] && !empty($_POST['customer']) && !isset($_POST['cancel-edit-customer'])) { $Customer = new ShoppCustomer(); $Customer->updates($_POST['customer']); $Customer->password = wp_generate_password(12, true); if ('wordpress' == shopp_setting('account_system')) { $Customer->create_wpuser(); } else { unset($_POST['loginname']); } $Customer->save(); if ((int) $Customer->id > 0) { $Purchase->customer = $Customer->id; $Purchase->copydata($Customer); $Purchase->save(); // New billing address, create record for new customer if (isset($_POST['billing']) && is_array($_POST['billing']) && empty($_POST['billing']['id'])) { $Billing = new BillingAddress($_POST['billing']); $Billing->customer = $Customer->id; $Billing->save(); } // New shipping address, create record for new customer if (isset($_POST['shipping']) && is_array($_POST['shipping']) && empty($_POST['shipping']['id'])) { $Shipping = new ShippingAddress($_POST['shipping']); $Shipping->customer = $Customer->id; $Shipping->save(); } } else { $this->notice(Shopp::__('An unknown error occured. The customer could not be created.'), 'error'); } } if (isset($_GET['order-action']) && 'change-customer' == $_GET['order-action'] && !empty($_GET['customerid'])) { $Customer = new ShoppCustomer((int) $_GET['customerid']); if ((int) $Customer->id > 0) { $Purchase->copydata($Customer); $Purchase->customer = $Customer->id; $Purchase->save(); } else { $this->notice(Shopp::__('The selected customer was not found.'), 'error'); } } if (isset($_POST['save-item']) && isset($_POST['lineid'])) { if (isset($_POST['lineid']) && '' == $_POST['lineid']) { $lineid = 'new'; } else { $lineid = (int) $_POST['lineid']; } $name = $_POST['itemname']; if (!empty($_POST['product'])) { list($productid, $priceid) = explode('-', $_POST['product']); $Product = new ShoppProduct($productid); $Price = new ShoppPrice($priceid); $name = $Product->name; if (Shopp::__('Price & Delivery') != $Price->label) { $name .= ": {$Price->label}"; } } // Create a cart representation of the order to recalculate order totals $Cart = new ShoppCart(); $taxcountry = $Purchase->country; $taxstate = $Purchase->state; if (!empty($Purchase->shipcountry) && !empty($Purchase->shipstate)) { $taxcountry = $Purchase->shipcountry; $taxstate = $Purchase->shipstate; } ShoppOrder()->Tax->location($taxcountry, $taxstate); if ('new' == $lineid) { $NewLineItem = new ShoppPurchased(); $NewLineItem->purchase = $Purchase->id; $Purchase->purchased[] = $NewLineItem; } foreach ($Purchase->purchased as &$Purchased) { $CartItem = new ShoppCartItem($Purchased); if ($Purchased->id == $lineid || 'new' == $lineid && empty($Purchased->id)) { if (!empty($_POST['product'])) { list($CartItem->product, $CartItem->priceline) = explode('-', $_POST['product']); } elseif (!empty($_POST['id'])) { list($CartItem->product, $CartItem->priceline) = explode('-', $_POST['id']); } $CartItem->name = $name; $CartItem->unitprice = Shopp::floatval($_POST['unitprice']); $Cart->additem((int) $_POST['quantity'], $CartItem); $CartItem = $Cart->get($CartItem->fingerprint()); $Purchased->name = $CartItem->name; $Purchased->product = $CartItem->product; $Purchased->price = $CartItem->priceline; $Purchased->quantity = $CartItem->quantity; $Purchased->unitprice = $CartItem->unitprice; $Purchased->total = $CartItem->total; $Purchased->save(); } else { $Cart->additem($CartItem->quantity, $CartItem); } } $Cart->Totals->register(new OrderAmountShipping(array('id' => 'cart', 'amount' => $Purchase->freight))); $Purchase->total = $Cart->total(); $Purchase->subtotal = $Cart->total('order'); $Purchase->discount = $Cart->total('discount'); $Purchase->tax = $Cart->total('tax'); $Purchase->freight = $Cart->total('shipping'); $Purchase->save(); $Purchase->load_purchased(); } if (!empty($_POST['save-totals'])) { $totals = array(); if (!empty($_POST['totals'])) { $totals = $_POST['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(); } if (!empty($_GET['rmvline'])) { $lineid = (int) $_GET['rmvline']; if (isset($Purchase->purchased[$lineid])) { $Purchase->purchased[$lineid]->delete(); unset($Purchase->purchased[$lineid]); } $Cart = new ShoppCart(); $taxcountry = $Purchase->country; $taxstate = $Purchase->state; if (!empty($Purchase->shipcountry) && !empty($Purchase->shipstate)) { $taxcountry = $Purchase->shipcountry; $taxstate = $Purchase->shipstate; } ShoppOrder()->Tax->location($taxcountry, $taxstate); foreach ($Purchase->purchased as &$Purchased) { $Cart->additem($Purchased->quantity, new ShoppCartItem($Purchased)); } $Cart->Totals->register(new OrderAmountShipping(array('id' => 'cart', 'amount' => $Purchase->freight))); $Purchase->total = $Cart->total(); $Purchase->subtotal = $Cart->total('order'); $Purchase->discount = $Cart->total('discount'); $Purchase->tax = $Cart->total('tax'); $Purchase->freight = $Cart->total('shipping'); $Purchase->save(); $Purchase->load_purchased(); } if (isset($_POST['charge']) && $Gateway && $Gateway->captures) { if (!current_user_can('shopp_capture')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } $user = wp_get_current_user(); shopp_add_order_event($Purchase->id, 'capture', array('txnid' => $Purchase->txnid, 'gateway' => $Purchase->gateway, 'amount' => $Purchase->capturable(), 'user' => $user->ID)); $Purchase->load_events(); } $targets = shopp_setting('target_markets'); $default = array('' => ' '); $Purchase->_countries = array_merge($default, ShoppLookup::countries()); $regions = Lookup::country_zones(); $Purchase->_billing_states = array_merge($default, (array) $regions[$Purchase->country]); $Purchase->_shipping_states = array_merge($default, (array) $regions[$Purchase->shipcountry]); // Setup shipping carriers menu and JS data $carriers_menu = $carriers_json = array(); $shipping_carriers = (array) shopp_setting('shipping_carriers'); // The store-preferred shipping carriers $shipcarriers = Lookup::shipcarriers(); // The full list of available shipping carriers $notrack = Shopp::__('No Tracking'); // No tracking label $default = get_user_meta(get_current_user_id(), 'shopp_shipping_carrier', true); if (isset($shipcarriers[$default])) { $carriers_menu[$default] = $shipcarriers[$default]->name; $carriers_json[$default] = array($shipcarriers[$default]->name, $shipcarriers[$default]->trackpattern); } else { $carriers_menu['NOTRACKING'] = $notrack; $carriers_json['NOTRACKING'] = array($notrack, false); } $serviceareas = array('*', ShoppBaseLocale()->country()); foreach ($shipcarriers as $code => $carrier) { if ($code == $default) { continue; } if (!empty($shipping_carriers) && !in_array($code, $shipping_carriers)) { continue; } if (!in_array($carrier->areas, $serviceareas)) { continue; } $carriers_menu[$code] = $carrier->name; $carriers_json[$code] = array($carrier->name, $carrier->trackpattern); } if (isset($shipcarriers[$default])) { $carriers_menu['NOTRACKING'] = $notrack; $carriers_json['NOTRACKING'] = array($notrack, false); } if (empty($statusLabels)) { $statusLabels = array(''); } $Purchase->taxes(); $Purchase->discounts(); $columns = get_column_headers($this->id); $hidden = get_hidden_columns($this->id); include $this->ui('new.php'); }
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 location_menu($destination = false, $row = 0, $module = false) { if (!$module) { $module = $this->module; } $menuarrow = ' ▾'; $tab = str_repeat('⋅', 3) . ' '; $regions = ShoppLookup::regions(); $countries = ShoppLookup::countries(); $regional_countries = array(); $country_areas = array(); $country_zones = array(); $postcode = false; $subregions = isset($_POST[$module]['table'][$row]['subregions']); $selection = array(); $selected = array('region' => '*', 'country' => '', 'area' => '', 'zone' => ''); if (strpos($destination, ',') !== false) { $selection = explode(',', $destination); } else { $selection = array($destination); } if ($subregions && isset($_POST[$module]['table'][$row]['destination'])) { $selection = explode(',', $_POST[$module]['table'][$row]['destination']); } if (!is_array($selection)) { $selection = array($selection); } $keys = array_slice(array_keys($selected), 0, count($selection)); $selected = array_merge($selected, array_combine($keys, $selection)); // $regional_countries = array_filter($countries, create_function('$c','return (\''.($selected['region']).'\' === (string)$c[\'region\']);')); if (!empty($selected['country'])) { $ca = Lookup::country_areas(); if (isset($ca[$selected['country']])) { $country_areas = $ca[$selected['country']]; } $cz = Lookup::country_zones(); if (isset($cz[$selected['country']])) { $country_zones = $cz[$selected['country']]; } } $options = array('*' => __('Anywhere', 'Shopp')); foreach ($regions as $index => $region) { if ($index == $selected['region'] && !empty($regional_countries) && ($subregions || !empty($selected['country']))) { $options[$index] = $region . $menuarrow; foreach ($regional_countries as $country => $country_data) { $country_name = $country_data['name']; if ($country == $selected['country']) { $postcodes = Lookup::postcodes(); $postcode = isset($postcodes[$selected['country']]); if (!empty($country_areas) && ($subregions || !empty($selected['area']))) { $options["{$index},{$country}"] = $country_name . $menuarrow; $areas = array_keys($country_areas); foreach ($areas as $area => $area_name) { if ((string) $area == (string) $selected['area']) { $zones = array_flip($country_areas[$area_name]); $zones = array_intersect_key($country_zones, $zones); $group_name = $area_name . $menuarrow; $options[$group_name] = array(); // Setup option group for area zones if (empty($selected['zone'])) { $selected['zone'] = key($zones); } foreach ($zones as $zone => $zone_name) { $options[$group_name]["{$index},{$country},{$area},{$zone}"] = $zone_name . ', ' . substr($country, 0, 2); } // end foreach($country_zones) } else { $options["{$index},{$country},{$area}"] = str_repeat(' ', 2) . $area_name; } } // end foreach($areas) } elseif (!empty($country_zones) && ($subregions || !empty($selected['area']))) { $options[$country_name] = array(); if (empty($selected['area'])) { $selected['area'] = key($country_zones); } foreach ($country_zones as $zone => $zone_name) { $options[$country_name]["{$index},{$country},{$zone}"] = $zone_name . ', ' . substr($country, 0, 2); } // end foreach($country_zones) } else { $options["{$index},{$country}"] = $country_name; } } else { $options["{$index},{$country}"] = $tab . $country_name; } } // end foreach ($regional_countries) } else { $options[$index] = $region; } } // end foreach ($regions) $selected = array_filter($selected, create_function('$i', 'return (\'\' != $i);')); $selection = join(',', $selected); return array('options' => $options, 'selection' => $selection, 'postcode' => $postcode); }
/** * 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'); }