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'); }
?> </label></th> <td><select name="settings[country]" id="base_operations"> <option value=""> </option> <?php echo $countrymenu; ?> </select> <select name="settings[state]" id="base_operations_zone"<?php if (empty($statesmenu)) { ?> disabled="disabled" class="hide-if-no-js"<?php } else { ?> placeholder="<?php Shopp::_e('Select your %s…', strtolower(ShoppBaseLocale()->division())); ?> "<?php } ?> > <?php echo $statesmenu; ?> </select> <br /> <?php Shopp::_e('Select your primary business location.'); ?> <br /> <?php
/** * Helper method to render markup for state/province input fields * * @internal * @since 1.3 * * @param string $result The output * @param array $options The options * - **mode**: `input` (input, value) Displays the field `input` or the current value of the property * - **type**: `menu` (menu, text) Changes the input type to a drop-down menu or text input field * - **options**: A comma-separated list of options for the drop-down menu when the **type** is set to `menu` * - **required**: `auto` (auto,on,off) Sets the field to be required automatically, always `on` or disabled `off` * - **class**: The class attribute specifies one or more class-names for the input * - **label**: The label shown as the default option of the drop-down menu when the **type** is set to `menu` * - **address**: `billing` (billing,shipping) Used to specify which address the field takes input for * @param ShoppCustomer $O The working object * @return string The state input markup **/ private static function state($result, $options, $O) { $defaults = array('mode' => 'input', 'type' => 'menu', 'options' => '', 'required' => 'auto', 'class' => '', 'label' => '', 'address' => 'billing'); $options = array_merge($defaults, $options); $options['address'] = self::valid_address($options['address']); $Address = self::AddressObject($options['address']); if (!isset($options['value'])) { $options['value'] = $Address->state; } $options['selected'] = $options['value']; $options['id'] = "{$options['address']}-state"; extract($options, EXTR_SKIP); if ('value' == $mode) { return $value; } $countries = (array) shopp_setting('target_markets'); $select_attrs = array('title', 'required', 'class', 'disabled', 'required', 'size', 'tabindex', 'accesskey'); $country = ShoppBaseLocale()->country(); if (!empty($Address->country)) { $country = $Address->country; } if (!array_key_exists($country, $countries)) { $country = key($countries); } $regions = Lookup::country_zones(); $states = isset($regions[$country]) ? $regions[$country] : array(); if (!empty($options['options']) && empty($states)) { $states = explode(',', $options['options']); } $classes = false === strpos($class, ' ') ? explode(' ', $class) : array(); $classes[] = $id; if ('auto' == $required) { unset($options['required']); // prevent inputattrs from handling required=auto $classes[] = 'auto-required'; } $options['class'] = join(' ', $classes); if ('text' == $type) { return '<input type="text" name="' . $address . '[state]" id="' . $id . '" ' . inputattrs($options) . '/>'; } $options['disabled'] = 'disabled'; $options['class'] = join(' ', array_merge($classes, array('disabled', 'hidden'))); $result = '<select name="' . $address . '[state]" id="' . $id . '-menu" ' . inputattrs($options, $select_attrs) . '>' . '<option value="">' . $label . '</option>' . (!empty($states) ? menuoptions($states, $selected, true) : '') . '</select>'; unset($options['disabled']); $options['class'] = join(' ', $classes); $result .= '<input type="text" name="' . $address . '[state]" id="' . $id . '" ' . inputattrs($options) . '/>'; return $result; }
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 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'); }
/** * Displays the shipping estimate widget * * The shipping estimate widget allows shoppers to provide location * information so that shipping costs can be calculated. * * @api `shopp('cart.shipping-estimates')` * @since 1.0 * * @param string $result The output * @param array $options The options * - **class**: CSS class names to apply to the widget * - **postcode**: `on` (on, off) Show the post code field in the widget * @param ShoppCart $O The working object * @return string The markup for the shipping estimate widget **/ public static function shipping_estimates($result, $options, $O) { $defaults = array('postcode' => 'on', 'class' => 'ship-estimates', 'label' => Shopp::__('Estimate Shipping & Taxes')); $options = array_merge($defaults, $options); extract($options); if (empty($O->shipped)) { return ''; } $markets = shopp_setting('target_markets'); $Shipping = ShoppOrder()->Shipping; if (empty($markets)) { return ''; } if (!empty($Shipping->country)) { $selected = $Shipping->country; } else { $selected = ShoppBaseLocale()->country(); } $postcode = Shopp::str_true($postcode) || $O->showpostcode; $_ = '<div class="' . $class . '">'; if (count($markets) > 1) { $_ .= '<span>'; $_ .= '<select name="shipping[country]" id="shipping-country">'; $_ .= menuoptions($markets, $selected, true); $_ .= '</select>'; $_ .= '</span>'; } else { $_ .= '<input type="hidden" name="shipping[country]" id="shipping-country" value="' . key($markets) . '" />'; } if ($postcode) { $_ .= '<span>'; $_ .= '<input type="text" name="shipping[postcode]" id="shipping-postcode" size="6" value="' . $Shipping->postcode . '"' . inputattrs($options) . ' /> '; $_ .= '</span>'; $_ .= shopp('cart', 'get-update-button', array('value' => $label)); } return $_ . '</div>'; }
/** * Setup the module for runtime * * Auto-loads settings for the module and setups defaults * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function __construct() { $this->module = get_class($this); $this->session = ShoppShopping()->session; $this->Order = ShoppOrder(); if ('ShoppFreeOrder' != $this->module) { // There are no settings for ShoppFreeOrder $this->settings = shopp_setting($this->module); // @todo Remove legacy gateway settings migrations // Attempt to copy old settings if this is a new prefixed gateway class if (empty($this->settings) && false !== strpos($this->module, 'Shopp')) { $legacy = substr($this->module, 5); $this->settings = shopp_setting($legacy); if (!empty($this->settings)) { shopp_set_setting($this->module, $this->settings); } } } if (!isset($this->settings['label']) && $this->cards) { $this->settings['label'] = __('Credit Card', 'Shopp'); } $this->baseop = ShoppBaseLocale()->settings(); $this->currency = ShoppBaseCurrency()->code(); $this->precision = ShoppBaseCurrency()->precision(); $this->_loadcards(); $gateway = GatewayModules::hookname($this->module); add_action('shopp_init', array($this, 'myactions'), 30); add_action('shopp_' . $gateway . '_refunded', array($this, 'cancelorder')); if ($this->authonly) { add_filter('shopp_purchase_order_' . $gateway . '_processing', create_function('', 'return "auth";')); } elseif ($this->saleonly) { add_filter('shopp_purchase_order_' . $gateway . '_processing', create_function('', 'return "sale";')); } }
/** * Sets the address location for calculating tax and shipping estimates * * @author Jonathan Davis * @since 1.1 * * @param array $data New address data to update * @return void **/ public function locate(array $data = null) { if ($data) { $this->updates($data); } if (empty($this->country)) { if (1 == count($markets)) { // If the target markets are set to single country, $this->country = key($markets); } else { $this->country = ShoppBaseLocale()->country(); } // base of operations } $Locale = new ShoppLocale($this->country); $this->region = $Locale->region(); // Update state if the postcode exists for tax updates if (isset($this->postcode)) { $this->postmap(); } }
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 taxrates() { if (!current_user_can('shopp_settings_taxes')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $edit = false; if (isset($_REQUEST['id'])) { $edit = (int) $_REQUEST['id']; } $localerror = false; $rates = shopp_setting('taxrates'); if (!is_array($rates)) { $rates = array(); } if (isset($_GET['delete'])) { check_admin_referer('shopp_delete_taxrate'); $delete = (int) $_GET['delete']; if (isset($rates[$delete])) { array_splice($rates, $delete, 1); } shopp_set_setting('taxrates', $rates); } if (isset($_POST['editing'])) { $rates[$edit] = $_POST['settings']['taxrates'][$edit]; } if (isset($_POST['addrule'])) { $rates[$edit]['rules'][] = array('p' => '', 'v' => ''); } if (isset($_POST['deleterule'])) { check_admin_referer('shopp-settings-taxrates'); list($rateid, $row) = explode(',', $_POST['deleterule']); if (isset($rates[$rateid]) && isset($rates[$rateid]['rules'])) { array_splice($rates[$rateid]['rules'], $row, 1); shopp_set_setting('taxrates', $rates); } } if (isset($rates[$edit]['haslocals'])) { $rates[$edit]['haslocals'] = $rates[$edit]['haslocals'] == 'true' || $rates[$edit]['haslocals'] == '1'; } if (isset($_POST['add-locals'])) { $rates[$edit]['haslocals'] = true; } if (isset($_POST['remove-locals'])) { $rates[$edit]['haslocals'] = false; $rates[$edit]['locals'] = array(); } $upload = $this->taxrate_upload(); if ($upload !== false) { if (isset($upload['error'])) { $localerror = $upload['error']; } else { $rates[$edit]['locals'] = $upload; } } if (isset($_POST['editing'])) { // Re-sort taxes from generic to most specific usort($rates, array($this, 'taxrates_sorting')); $rates = stripslashes_deep($rates); shopp_set_setting('taxrates', $rates); } if (isset($_POST['addrate'])) { $edit = count($rates); } if (isset($_POST['submit'])) { $edit = false; } $specials = array(ShoppTax::ALL => Shopp::__('All Markets')); if (ShoppTax::euvat(false, ShoppBaseLocale()->country(), ShoppTax::EUVAT)) { $specials[ShoppTax::EUVAT] = Shopp::__('European Union'); } $countries = array_merge($specials, (array) shopp_setting('target_markets')); $zones = Lookup::country_zones(); include $this->ui('taxrates.php'); }
/** * Initializes a shipping module * * Grabs settings that most shipping modules will needs and establishes * the event listeners to trigger module functionality. * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function __construct() { $Order = ShoppOrder(); $this->module = get_class($this); if ($this->singular) { // @todo Remove legacy gateway settings migrations // Attempt to copy old settings if this is a new prefixed gateway class $this->settings = shopp_setting($this->module); if (empty($this->settings) && false !== strpos($this->module, 'Shopp')) { $legacy = substr($this->module, 5); $this->settings = shopp_setting($legacy); if (!empty($this->settings)) { shopp_set_setting($this->module, $this->settings); shopp_rmv_setting($legacy); // Clean up legacy setting } } } else { $active = shopp_setting('active_shipping'); if (isset($active[$this->module]) && is_array($active[$this->module])) { $this->methods = array(); $this->fallbacks = array(); foreach ($active[$this->module] as $index => $set) { $setting = shopp_setting("{$this->module}-{$index}"); if (isset($setting['fallback']) && 'on' == $setting['fallback']) { $this->fallbacks["{$this->module}-{$index}"] = $setting; } else { $this->methods["{$this->module}-{$index}"] = $setting; } } } } $this->base = ShoppBaseLocale()->settings(); $this->units = shopp_setting('weight_unit'); // Setup default packaging for shipping module $this->settings['shipping_packaging'] = shopp_setting('shipping_packaging'); // Shipping module can override the default behavior and the global setting by specifying the local packaging property if (isset($this->packaging) && $this->packaging != $this->settings['shipping_packaging']) { $this->settings['shipping_packaging'] = $this->packaging; } $this->packager = apply_filters('shopp_' . strtolower($this->module) . '_packager', new ShippingPackager(array('type' => $this->settings['shipping_packaging']), $this->module)); $this->destinations = __('Service provider markets', 'Shopp'); add_action('shopp_calculate_shipping_init', array(&$this, 'init')); add_action('shopp_calculate_item_shipping', array(&$this, 'calcitem'), 10, 2); add_action('shopp_calculate_shipping', array(&$this, 'calculate'), 10, 2); if (isset($this->fallbacks) && !empty($this->fallbacks)) { add_action('shopp_calculate_fallback_shipping_init', array(&$this, 'fallbacks')); add_action('shopp_calculate_fallback_shipping', array(&$this, 'calculate')); add_action('shopp_calculate_fallback_shipping', array(&$this, 'reset'), 20); } }
/** * Helper method to sort target markets by region. * * Note that the sort order within the region is defined by the order specified in * the core/locales/regions.php file. * * @since 1.4 * * @param array $targets The list of enabled target markets * @return array The region-sorted list of enabled target markets */ private static function regionsort(array $targets) { $locale = ShoppBaseLocale()->region(); $base = ShoppBaseLocale()->country(); $regionsdata = ShoppLookup::regions(true); $baselocale = $regionsdata[$locale]; unset($regionsdata[$locale]); $regions = array($locale => $baselocale) + $regionsdata; $marketcodes = array_keys($targets); $sorted = array(); $sorted[$base] = $targets[$base]; // Add base locale country first foreach ($regions as $name => $countries) { foreach ($countries as $country) { if ($country == $base) { continue; } // Skip base locale if (in_array($country, $marketcodes)) { $sorted[$country] = $targets[$country]; } } } return $sorted; }
public static function baserates($Item = null) { // Get base tax rate $BaseTax = new ShoppTax(); $BaseTax->location(ShoppBaseLocale()->country(), false, false); // Calculate the deduction $baserates = array(); $BaseTax->rates($baserates, $BaseTax->item($Item)); return (array) $baserates; }
/** * 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'); }