public function updates() { $form = $this->form(); if (empty($form)) { return; } do_action('shopp_save_payment_settings'); $Gateways = Shopp::object()->Gateways; $gateways = array_keys($Gateways->activated()); $gateway = key($form); // Handle Multi-instance payment systems $indexed = false; if (preg_match('/\\[(\\d+)\\]/', $gateway, $matched)) { $indexed = '-' . $matched[1]; $gateway = str_replace($matched[0], '', $gateway); } // Merge the existing gateway settings with the newly updated settings if (isset($Gateways->active[$gateway])) { $Gateway = $Gateways->active[$gateway]; // Cannot use array_merge() because it adds numeric index values instead of overwriting them $this->form[$gateway] = (array) $this->form[$gateway] + (array) $Gateway->settings; } // Add newly activated gateways if (!in_array($gateway . $indexed, $gateways)) { $gateways[] = $gateway . $indexed; shopp_set_setting('active_gateways', join(',', $gateways)); } // Save the gateway settings shopp_set_formsettings(); $this->notice(Shopp::__('Shopp payments settings saved.')); Shopp::redirect(add_query_arg()); }
public function screen() { $Shopp = Shopp::object(); if (!current_user_can('shopp_settings_checkout')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $purchasetable = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $next = sDB::query("SELECT IF ((MAX(id)) > 0,(MAX(id)+1),1) AS id FROM {$purchasetable} LIMIT 1"); $next_setting = shopp_setting('next_order_id'); if ($next->id > $next_setting) { $next_setting = $next->id; } $term_recount = false; if (!empty($_POST['save'])) { check_admin_referer('shopp-setup-management'); $next_order_id = $_POST['settings']['next_order_id'] = intval($_POST['settings']['next_order_id']); if ($next_order_id >= $next->id) { if (sDB::query("ALTER TABLE {$purchasetable} AUTO_INCREMENT=" . sDB::escape($next_order_id))) { $next_setting = $next_order_id; } } $_POST['settings']['order_shipfee'] = Shopp::floatval($_POST['settings']['order_shipfee']); // Recount terms when this setting changes if (isset($_POST['settings']['inventory']) && $_POST['settings']['inventory'] != shopp_setting('inventory')) { $term_recount = true; } shopp_set_formsettings(); $this->notice(Shopp::__('Management settings saved.'), 'notice', 20); } if ($term_recount) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } $states = array(__('Map the label to an order state:', 'Shopp') => array_merge(array('' => ''), Lookup::txnstatus_labels())); $statusLabels = shopp_setting('order_status'); $statesLabels = shopp_setting('order_states'); $reasonLabels = shopp_setting('cancel_reasons'); if (empty($reasonLabels)) { $reasonLabels = array(__('Not as described or expected', 'Shopp'), __('Wrong size', 'Shopp'), __('Found better prices elsewhere', 'Shopp'), __('Product is missing parts', 'Shopp'), __('Product is defective or damaaged', 'Shopp'), __('Took too long to deliver', 'Shopp'), __('Item out of stock', 'Shopp'), __('Customer request to cancel', 'Shopp'), __('Item discontinued', 'Shopp'), __('Other reason', 'Shopp')); } $promolimit = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '15', '20', '25'); $lowstock = shopp_setting('lowstock_level'); if (empty($lowstock)) { $lowstock = 0; } include $this->ui('management.php'); }
public function updates() { $CatalogPage = ShoppPages()->get('catalog'); $catalog_slug = $CatalogPage->slug(); $defaults = ShoppPages()->settings(); $this->form['storefront_pages'] = array_merge($defaults, $this->form('storefront_pages')); shopp_set_formsettings(); // Re-register page, collection, taxonomies and product rewrites // so that the new slugs work immediately $Shopp = Shopp::object(); $Shopp->pages(); $Shopp->collections(); $Shopp->taxonomies(); $Shopp->products(); // If the catalog slug changes // $hardflush is false (soft flush... plenty of fiber, no .htaccess update needed) $hardflush = ShoppPages()->baseslug() != $catalog_slug; flush_rewrite_rules($hardflush); }
public function updates() { $rates = shopp_setting('taxrates'); $updates = $this->form('taxrates'); if (!empty($updates)) { if (array_key_exists('new', $updates)) { $rates[] = $updates['new']; } else { $rates = array_replace($rates, $updates); } // Re-sort taxes from generic to most specific usort($rates, array($this, 'sortrates')); $rates = stripslashes_deep($rates); shopp_set_setting('taxrates', $rates); unset($_POST['settings']['taxrates']); } shopp_set_formsettings(); // Save other tax settings $this->notice(Shopp::__('Tax settings saved.')); Shopp::redirect(add_query_arg()); }
public function updates() { $builtin_path = SHOPP_PATH . '/templates'; $theme_path = sanitize_path(STYLESHEETPATH . '/shopp'); if (Shopp::str_true($this->form('theme_templates')) && !is_dir($theme_path)) { $this->form['theme_templates'] = 'off'; $this->notice(Shopp::__("Shopp theme templates can't be used because they don't exist."), 'error'); } if (empty($this->form('catalog_pagination'))) { $this->form['catalog_pagination'] = 0; } // Recount terms when this setting changes if ($this->form('outofstock_catalog') != shopp_setting('outofstock_catalog')) { $taxonomy = ProductCategory::$taxon; $terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids')); if (!empty($terms)) { wp_update_term_count_now($terms, $taxonomy); } } shopp_set_formsettings(); $this->notice(Shopp::__('Presentation settings saved.'), 'notice', 20); }
public function updates() { if (!isset($_POST['settings']['target_markets'])) { asort($_POST['settings']['target_markets']); } // Save all other settings shopp_set_formsettings(); $update = false; // Update country changes $country = ShoppBaseLocale()->country(); if ($country != $this->form('country')) { $country = strtoupper($this->form('country')); $countries = ShoppLookup::countries(); // Validate the country if (!isset($countries[$country])) { return $this->notice(Shopp::__('The country provided is not valid.'), 'error'); } $update = true; } // Update state changes $state = ShoppBaseLocale()->state(); if (ShoppBaseLocale()->state() != $this->form('state')) { $state = strtoupper($this->form('state')); $states = ShoppLookup::country_zones(array($country)); // Validate the state if (!empty($states) && !isset($states[$country][$state])) { return $this->notice(Shopp::__('The %s provided is not valid.', ShoppBaseLocale()->division()), 'error'); } $update = true; } // Save base locale changes if ($update) { ShoppBaseLocale()->save($country, $state); } $this->notice(Shopp::__('Shopp settings saved.')); }
public function screen() { $shipcarriers = Lookup::shipcarriers(); $serviceareas = array('*', ShoppBaseLocale()->code()); foreach ($shipcarriers as $c => $record) { if (!in_array($record->areas, $serviceareas)) { continue; } $carriers[$c] = $record->name; } unset($shipcarriers); $shipping_carriers = shopp_setting('shipping_carriers'); if (empty($shipping_carriers)) { $shipping_carriers = array_keys($carriers); } $imperial = 'imperial' == ShoppBaseLocale()->units(); $weights = $imperial ? array('oz' => Shopp::__('ounces (oz)'), 'lb' => Shopp::__('pounds (lbs)')) : array('g' => Shopp::__('gram (g)'), 'kg' => Shopp::__('kilogram (kg)')); $weightsmenu = menuoptions($weights, shopp_setting('weight_unit'), true); $dimensions = $imperial ? array('in' => Shopp::__('inches (in)'), 'ft' => Shopp::__('feet (ft)')) : array('cm' => Shopp::__('centimeters (cm)'), 'm' => Shopp::__('meters (m)')); $dimsmenu = menuoptions($dimensions, shopp_setting('dimension_unit'), true); $rates = shopp_setting('shipping_rates'); if (!empty($rates)) { ksort($rates); } $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 (isset($_POST['module'])) { $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.')); } } } $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')); $Table = $this->table; $Table->prepare_items(); include $this->ui('shipping.php'); }
public function pages() { if (!current_user_can('shopp_settings')) { wp_die(__('You do not have sufficient permissions to access this page.')); } if (!empty($_POST['save'])) { check_admin_referer('shopp-settings-pages'); $CatalogPage = ShoppPages()->get('catalog'); $catalog_slug = $CatalogPage->slug(); $defaults = ShoppPages()->settings(); $_POST['settings']['storefront_pages'] = array_merge($defaults, $_POST['settings']['storefront_pages']); shopp_set_formsettings(); // Re-register page, collection, taxonomies and product rewrites // so that the new slugs work immediately $Shopp = Shopp::object(); $Shopp->pages(); $Shopp->collections(); $Shopp->taxonomies(); $Shopp->products(); // If the catalog slug changes // $hardflush is false (soft flush... plenty of fiber, no .htaccess update needed) $hardflush = ShoppPages()->baseslug() != $catalog_slug; flush_rewrite_rules($hardflush); } $pages = ShoppPages()->settings(); include $this->ui('pages.php'); }
/** * Delivers customer export files to the browser * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function export_customers() { if (!current_user_can('shopp_export_customers')) { exit; } if (!isset($_POST['settings']['customerexport_columns'])) { $Customer = ShoppCustomer::exportcolumns(); $Billing = BillingAddress::exportcolumns(); $Shipping = ShippingAddress::exportcolumns(); $_POST['settings']['customerexport_columns'] = array_keys(array_merge($Customer, $Billing, $Shipping)); $_POST['settings']['customerexport_headers'] = 'on'; } shopp_set_formsettings(); // Save workflow setting $format = shopp_setting('customerexport_format'); if (empty($format)) { $format = 'tab'; } switch ($format) { case 'csv': new CustomersCSVExport(); break; default: new CustomersTabExport(); } exit; }
public function storage() { $Shopp = Shopp::object(); $Storage = $Shopp->Storage; $Storage->settings(); // Load all installed storage engines for settings UIs if (!empty($_POST['save'])) { check_admin_referer('shopp-system-storage'); shopp_set_formsettings(); // Re-initialize Storage Engines with new settings $Storage->settings(); $this->notice(Shopp::__('Shopp system settings saved.')); } elseif (!empty($_POST['rebuild'])) { $assets = ShoppDatabaseObject::tablename(ProductImage::$table); $query = "DELETE FROM {$assets} WHERE context='image' AND type='image'"; if (sDB::query($query)) { $updated = __('All cached images have been cleared.', 'Shopp'); } } // Build the storage options menu $storage = $engines = $storageset = array(); foreach ($Storage->active as $module) { $storage[$module->module] = $module->name; $engines[$module->module] = sanitize_title_with_dashes($module->module); $storageset[$module->module] = $Storage->get($module->module)->settings; } $Storage->ui(); // Setup setting UIs $ImageStorage = false; $DownloadStorage = false; if (isset($_POST['image-settings'])) { $ImageStorage = $Storage->get(shopp_setting('image_storage')); } if (isset($_POST['download-settings'])) { $DownloadStorage = $Storage->get(shopp_setting('product_storage')); } add_action('shopp_storage_engine_settings', array($Storage, 'templates')); include $this->ui('storage.php'); }
/** * Handles saving updated category information from the category editor * * @author Jonathan Davis * @since 1.0 * @return void **/ public function save($Category) { $Shopp = Shopp::object(); check_admin_referer('shopp-save-category'); if (!current_user_can('shopp_categories')) { wp_die(__('You do not have sufficient permissions to access this page.')); } shopp_set_formsettings(); // Save workflow setting if (empty($Category->meta)) { $Category->load_meta(); } if (isset($_POST['content'])) { $_POST['description'] = $_POST['content']; } $Category->name = $_POST['name']; $Category->description = $_POST['description']; $Category->parent = $_POST['parent']; $Category->prices = array(); // Variation price templates if (!empty($_POST['price']) && is_array($_POST['price'])) { foreach ($_POST['price'] as &$pricing) { $pricing['price'] = Shopp::floatval($pricing['price'], false); $pricing['saleprice'] = Shopp::floatval($pricing['saleprice'], false); $pricing['shipfee'] = Shopp::floatval($pricing['shipfee'], false); $pricing['dimensions'] = array_map(array('Shopp', 'floatval'), $pricing['dimensions']); } } $_POST['prices'] = isset($_POST['price']) ? $_POST['price'] : array(); if (empty($_POST['specs'])) { $Category->specs = array(); } /* @todo Move the rest of category meta inputs to [meta] inputs eventually */ if (isset($_POST['meta']) && isset($_POST['meta']['options'])) { // Moves the meta options input to 'options' index for compatibility $_POST['options'] = $_POST['meta']['options']; } if (empty($_POST['meta']['options']) || count($_POST['meta']['options']['v']) == 1 && !isset($_POST['meta']['options']['v'][1]['options'])) { $_POST['options'] = $Category->options = array(); $_POST['prices'] = $Category->prices = array(); } $metaprops = array('spectemplate', 'facetedmenus', 'variations', 'pricerange', 'priceranges', 'specs', 'options', 'prices'); $metadata = array_filter_keys($_POST, $metaprops); // Update existing entries $updates = array(); foreach ($Category->meta as $id => $MetaObject) { $name = $MetaObject->name; if (isset($metadata[$name])) { $MetaObject->value = stripslashes_deep($metadata[$name]); $updates[] = $name; } } // Create any new missing meta entries $new = array_diff(array_keys($metadata), $updates); // Determine new entries from the exsting updates foreach ($new as $name) { if (!isset($metadata[$name])) { continue; } $Meta = new MetaObject(); $Meta->name = $name; $Meta->value = stripslashes_deep($metadata[$name]); $Category->meta[] = $Meta; } $Category->save(); if (!empty($_POST['deleteImages'])) { $deletes = array(); if (strpos($_POST['deleteImages'], ",")) { $deletes = explode(',', $_POST['deleteImages']); } else { $deletes = array($_POST['deleteImages']); } $Category->delete_images($deletes); } if (!empty($_POST['images']) && is_array($_POST['images'])) { $Category->link_images($_POST['images']); $Category->save_imageorder($_POST['images']); if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) { foreach ($_POST['imagedetails'] as $i => $data) { $Image = new CategoryImage($data['id']); $Image->title = $data['title']; $Image->alt = $data['alt']; $Image->save(); } } } do_action_ref_array('shopp_category_saved', array($Category)); $this->notice(Shopp::__('%s category saved.', '<strong>' . $Category->name . '</strong>')); }
public function screen() { if (!empty($_POST['save'])) { if (!isset($_POST['settings']['error_notifications'])) { $_POST['settings']['error_notifications'] = array(); } shopp_set_formsettings(); // Reinitialize Error System ShoppErrors()->reporting((int) shopp_setting('error_logging')); ShoppErrorLogging()->loglevel((int) shopp_setting('error_logging')); ShoppErrorNotification()->setup(); if (isset($_POST['shopp_services_plugins']) && $this->helper_installed()) { add_option('shopp_services_plugins'); // Add if it doesn't exist update_option('shopp_services_plugins', $_POST['shopp_services_plugins']); } $this->notice(Shopp::__('Advanced settings saved.')); } elseif (!empty($_POST['rebuild'])) { $assets = ShoppDatabaseObject::tablename(ProductImage::$table); $query = "DELETE FROM {$assets} WHERE context='image' AND type='image'"; if (sDB::query($query)) { $this->notice(Shopp::__('All cached images have been cleared.')); } } elseif (!empty($_POST['resum'])) { $summaries = ShoppDatabaseObject::tablename(ProductSummary::$table); $query = "UPDATE {$summaries} SET modified='" . ProductSummary::RECALCULATE . "'"; if (sDB::query($query)) { $this->notice(Shopp::__('Product summaries are set to recalculate.')); } } elseif (isset($_POST['shopp_services_helper'])) { $plugin = 'ShoppServices.php'; $source = SHOPP_PATH . "/core/library/{$plugin}"; $install = WPMU_PLUGIN_DIR . '/' . $plugin; if (false === ($creds = request_filesystem_credentials($this->url, '', false, false, null))) { return true; } // stop the normal page form from displaying if (!WP_Filesystem($creds)) { // credentials were no good, ask for them again request_filesystem_credentials($this->url, '', false, false, null); return true; } global $wp_filesystem; if ('install' == $_POST['shopp_services_helper']) { if (!$wp_filesystem->exists($install)) { if ($wp_filesystem->exists(WPMU_PLUGIN_DIR) || $wp_filesystem->mkdir(WPMU_PLUGIN_DIR, FS_CHMOD_DIR)) { // Install the mu-plugin helper $wp_filesystem->copy($source, $install, true, FS_CHMOD_FILE); } else { $this->notice(Shopp::_mi('The services helper could not be installed because the `mu-plugins` directory could not be created. Check the file permissions of the `%s` directory on the web aserver.', WP_CONTENT_DIR), 'error'); } } if ($wp_filesystem->exists($install)) { shopp_set_setting('shopp_services_helper', 'on'); $this->notice(Shopp::__('Services helper installed.')); } else { $this->notice(Shopp::__('The services helper failed to install.'), 'error'); } } elseif ('remove' == $_POST['shopp_services_helper']) { global $wp_filesystem; if ($wp_filesystem->exists($install)) { $wp_filesystem->delete($install); } if (!$wp_filesystem->exists($install)) { shopp_set_setting('shopp_services_helper', 'off'); $this->notice(Shopp::__('Services helper uninstalled.')); } else { $this->notice(Shopp::__('Services helper could not be uninstalled.'), 'error'); } } } $notifications = shopp_setting('error_notifications'); if (empty($notifications)) { $notifications = array(); } $notification_errors = array(SHOPP_TRXN_ERR => Shopp::__('Transaction Errors'), SHOPP_AUTH_ERR => Shopp::__('Login Errors'), SHOPP_ADDON_ERR => Shopp::__('Add-on Errors'), SHOPP_COMM_ERR => Shopp::__('Communication Errors'), SHOPP_STOCK_ERR => Shopp::__('Inventory Warnings')); $errorlog_levels = array(0 => Shopp::__('Disabled'), SHOPP_ERR => Shopp::__('General Shopp Errors'), SHOPP_TRXN_ERR => Shopp::__('Transaction Errors'), SHOPP_AUTH_ERR => Shopp::__('Login Errors'), SHOPP_ADDON_ERR => Shopp::__('Add-on Errors'), SHOPP_COMM_ERR => Shopp::__('Communication Errors'), SHOPP_STOCK_ERR => Shopp::__('Inventory Warnings'), SHOPP_ADMIN_ERR => Shopp::__('Admin Errors'), SHOPP_DB_ERR => Shopp::__('Database Errors'), SHOPP_PHP_ERR => Shopp::__('PHP Errors'), SHOPP_ALL_ERR => Shopp::__('All Errors'), SHOPP_DEBUG_ERR => Shopp::__('Debugging Messages')); $plugins = get_plugins(); $service_plugins = get_option('shopp_services_plugins'); include $this->ui('advanced.php'); }
public function saveform() { $_POST['settings'] = $this->form; return shopp_set_formsettings(); }
public function updates() { shopp_set_formsettings(); $this->notice(Shopp::__('Downloads settings saved.')); }