function wpsc_get_terms_variation_sort_filter($terms) { $new_terms = array(); $unsorted = array(); foreach ($terms as $term) { if (!is_object($term)) { return $terms; } $term_order = $term->taxonomy == 'wpsc-variation' ? wpsc_get_meta($term->term_id, 'sort_order', 'wpsc_variation') : null; $term_order = (int) $term_order; // unsorted categories should go to the top of the list if ($term_order == 0) { $term->sort_order = $term_order; $unsorted[] = $term; continue; } while (isset($new_terms[$term_order])) { $term_order++; } $term->sort_order = $term_order; $new_terms[$term_order] = $term; } if (!empty($new_terms)) { ksort($new_terms); } for ($i = count($unsorted) - 1; $i >= 0; $i--) { array_unshift($new_terms, $unsorted[$i]); } return array_values($new_terms); }
/** * getOrderMeta - get the order details from the purchase log meta details * * @param int $purchase_id purchase number * @return mixed purchase log details */ function getOrderMeta($purchase_id) { $meta_key = '_wpsc_auth_net_status'; $type = 'wpsc_purchase_log'; return wpsc_get_meta($purchase_id, $meta_key, $type); }
function wpsc_update_files() { global $wpdb, $user_ID; $product_files = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_FILES . ""); $wpsc_update = WPSC_Update::get_instance(); foreach ($product_files as $product_file) { $wpsc_update->check_timeout(); $variation_post_ids = array(); if (!empty($product_file->product_id)) { $product_post_id = (int) $wpdb->get_var($wpdb->prepare("SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $product_file->product_id)); } else { $product_post_id = (int) $wpdb->get_var("SELECT `id` FROM " . WPSC_TABLE_PRODUCT_LIST . " WHERE file=" . $product_file->id); $product_post_id = (int) $wpdb->get_var($wpdb->prepare("SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $product_post_id)); } $variation_items = $wpdb->get_col("SELECT `id` FROM " . WPSC_TABLE_VARIATION_PROPERTIES . " WHERE `file` = '{$product_file->id}'"); if (count($variation_items) > 0) { $variation_post_ids = $wpdb->get_col("SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = '_wpsc_original_variation_id' AND `meta_value` IN(" . implode(", ", $variation_items) . ")"); } $attachment_template = array('post_mime_type' => $product_file->mimetype, 'post_title' => $product_file->filename, 'post_name' => $product_file->idhash, 'post_content' => '', 'post_parent' => $product_post_id, 'post_type' => "wpsc-product-file", 'post_status' => 'inherit'); $file_id = wpsc_get_meta($product_file->id, '_new_file_id', 'wpsc_files'); if ($file_id == null && count($variation_post_ids) == 0) { $file_data = $attachment_template; $file_data['post_parent'] = $product_post_id; $new_file_id = wp_insert_post($file_data); wpsc_update_meta($product_file->id, '_new_file_id', $new_file_id, 'wpsc_files'); } if (count($variation_post_ids) > 0) { foreach ($variation_post_ids as $variation_post_id) { $old_file_id = get_product_meta($variation_post_id, 'old_file_id', true); if ($old_file_id == null) { $file_data = $attachment_template; $file_data['post_parent'] = $variation_post_id; $new_file_id = wp_insert_post($file_data); update_product_meta($variation_post_id, 'old_file_id', $product_file->id, 'wpsc_files'); } } } if (!empty($product_file->preview)) { $preview_template = array('post_mime_type' => $product_file->preview_mimetype, 'post_title' => $product_file->preview, 'post_name' => $product_file->filename, 'post_content' => '', 'post_parent' => $new_file_id, 'post_type' => "wpsc-product-preview", 'post_status' => 'inherit'); wp_insert_post($preview_template); } } $download_ids = $wpdb->get_col("SELECT `id` FROM " . WPSC_TABLE_DOWNLOAD_STATUS . ""); foreach ($download_ids as $download_id) { if (wpsc_get_meta($download_id, '_is_legacy', 'wpsc_downloads') !== 'false') { wpsc_update_meta($download_id, '_is_legacy', 'true', 'wpsc_downloads'); } } }
/** * returns a country's property matching the key, either a well know property or a property defined elsewhere * * @access public * * @since 3.8.14 * * @return varies value of the property. Returns NULL for nonexistent property. */ public function get($key) { $property_name = '_' . $key; if (property_exists($this, $property_name)) { $value = $this->{$property_name}; } else { $value = wpsc_get_meta($this->_id, $key, __CLASS__); } return apply_filters('wpsc_country_get_property', $value, $key, $this); }
/** * submit checkout function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_submit_checkout() { global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; $num_items = 0; $use_shipping = 0; $disregard_shipping = 0; $_SESSION['wpsc_checkout_misc_error_messages'] = array(); $wpsc_checkout = new wpsc_checkout(); $selected_gateways = get_option('custom_gateway_options'); $submitted_gateway = $_POST['custom_gateway']; $options = get_option('custom_shipping_options'); $form_validity = $wpsc_checkout->validate_forms(); extract($form_validity); // extracts $is_valid and $error_messages if ($_POST['agree'] != 'yes') { $_SESSION['wpsc_checkout_misc_error_messages'][] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } $selectedCountry = $wpdb->get_results("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape($_SESSION['wpsc_delivery_country']) . "'", ARRAY_A); foreach ($wpsc_cart->cart_items as $cartitem) { if ($cartitem->meta[0]['no_shipping'] == 1) { continue; } $categoriesIDs = $cartitem->category_id_list; foreach ((array) $categoriesIDs as $catid) { if (is_array($catid)) { $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category'); } else { $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category'); } if (!empty($countries) && !in_array($selectedCountry[0]['id'], (array) $countries)) { $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->product_name, $selectedCountry[0]['country']); $_SESSION['categoryAndShippingCountryConflict'] = $errormessage; $is_valid = false; } } //count number of items, and number of items using shipping $num_items++; if ($cartitem->uses_shipping != 1) { $disregard_shipping++; } else { $use_shipping++; } } if (array_search($submitted_gateway, $selected_gateways) !== false) { $_SESSION['wpsc_previous_selected_gateway'] = $submitted_gateway; } else { $is_valid = false; } if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) { $_SESSION['wpsc_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '' && $num_items != $disregard_shipping) { $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed', 'wpsc'); $is_valid = false; } if ($is_valid == true) { $_SESSION['categoryAndShippingCountryConflict'] = ''; // check that the submitted gateway is in the list of selected ones $sessionid = mt_rand(100, 999) . time(); $_SESSION['wpsc_sessionid'] = $sessionid; $subtotal = $wpsc_cart->calculate_subtotal(); if ($wpsc_cart->has_total_shipping_discount() == false) { $base_shipping = $wpsc_cart->calculate_base_shipping(); } else { $base_shipping = 0; } $delivery_country = $wpsc_cart->delivery_country; $delivery_region = $wpsc_cart->delivery_region; if (wpsc_uses_shipping()) { $shipping_method = $wpsc_cart->selected_shipping_method; $shipping_option = $wpsc_cart->selected_shipping_option; } else { $shipping_method = ''; $shipping_option = ''; } if (isset($_POST['how_find_us'])) { $find_us = $_POST['how_find_us']; } else { $find_us = ''; } //keep track of tax if taxes are exclusive $wpec_taxes_controller = new wpec_taxes_controller(); if (!$wpec_taxes_controller->wpec_taxes_isincluded()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0.0; $tax_percentage = 0.0; } $total = $wpsc_cart->calculate_total_price(); $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => strtotime(current_time('mysql')), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage)); $purchase_log_id = $wpdb->insert_id; $wpsc_checkout->save_forms_to_db($purchase_log_id); $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); if (get_option('wpsc_also_bought') == 1) { wpsc_populate_also_bought_list(); } if (!isset($our_user_id) && isset($user_ID)) { $our_user_id = $user_ID; } $wpsc_cart->log_id = $purchase_log_id; do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id)); if (get_option('permalink_structure') != '') { $separator = "?"; } else { $separator = "&"; } // submit to gateway $current_gateway_data =& $wpsc_gateways[$submitted_gateway]; if ($current_gateway_data['api_version'] >= 2.0) { $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id); $merchant_instance->construct_value_array(); $merchant_instance->submit(); } elseif ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') { $gateway_used = $current_gateway_data['internalname']; $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $log_id)); $current_gateway_data['function']($separator, $sessionid); } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) { $gateway_used = $current_gateway_data['internalname']; $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $log_id)); $_SESSION['gateway'] = 'google'; wp_redirect(get_option('shopping_cart_url')); } } }
function wpsc_admin_category_forms_edit() { global $wpdb; $category_value_count = 0; $category_name = ''; $category = array(); $category_id = absint($_REQUEST["tag_ID"]); $category = get_term($category_id, 'wpsc_product_category', ARRAY_A); $category['nice-name'] = wpsc_get_categorymeta($category['term_id'], 'nice-name'); $category['description'] = wpsc_get_categorymeta($category['term_id'], 'description'); $category['image'] = wpsc_get_categorymeta($category['term_id'], 'image'); $category['fee'] = wpsc_get_categorymeta($category['term_id'], 'fee'); $category['active'] = wpsc_get_categorymeta($category['term_id'], 'active'); $category['order'] = wpsc_get_categorymeta($category['term_id'], 'order'); $category['display_type'] = wpsc_get_categorymeta($category['term_id'], 'display_type'); $category['image_height'] = wpsc_get_categorymeta($category['term_id'], 'image_height'); $category['image_width'] = wpsc_get_categorymeta($category['term_id'], 'image_width'); $category['use_additional_form_set'] = wpsc_get_categorymeta($category['term_id'], 'use_additional_form_set'); ?> <tr> <td colspan="2"> <h3><?php esc_html_e('Advanced Store Settings', 'wpsc'); ?> </h3> <h4><?php esc_html_e('Shortcodes and Template Tags', 'wpsc'); ?> </h4> <p class='description'><?php esc_html_e('These settings override the general presentation settings found in Settings > Store > Presentation.', 'wpsc'); ?> </p> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="display_type"><?php esc_html_e('Catalog View', 'wpsc'); ?> </label> </th> <td> <?php $display_type = isset($category['display_type']) ? $category['display_type'] : ''; ?> <select name='display_type'> <option value='default'<?php selected($display_type, 'default'); ?> ><?php esc_html_e('Default View', 'wpsc'); ?> </option> <option value='list'<?php disabled(_wpsc_is_display_type_supported('list'), false); selected($display_type, 'list'); ?> ><?php esc_html_e('List View', 'wpsc'); ?> </option> <option value='grid' <?php disabled(_wpsc_is_display_type_supported('grid'), false); selected($display_type, 'grid'); ?> ><?php esc_html_e('Grid View', 'wpsc'); ?> </option> </select><br /> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Category Image', 'wpsc'); ?> </label> </th> <td> <?php $category_image = wpsc_category_image($category['term_id']); if ($category_image) { echo '<p><img src=' . esc_url($category_image) . ' alt="' . esc_attr($category['name']) . '" title="' . esc_attr($category['name']) . '" class="wpsc_category_image" /></p>'; } ?> <input type='file' name='image' value='' /><br /> <label><input type='checkbox' name='deleteimage' class="wpsc_cat_box" value='1' /><?php esc_html_e('Delete Image', 'wpsc'); ?> </label><br/> <span class="description"><?php esc_html_e('You can set an image for the category here. If one exists, check the box to delete.', 'wpsc'); ?> </span> </td> </tr> <?php if (function_exists("getimagesize")) { ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Thumbnail Size', 'wpsc'); ?> </label> </th> <td> <fieldset class="wpsc-width-height-fields"> <legend class="screen-reader-text"><span><?php esc_html_e('Thumbnail Size', 'wpsc'); ?> </span></legend> <label for="image_width"><?php esc_html_e('Width', 'wpsc'); ?> </label> <input name="image_width" type="number" step="1" min="0" id="image_width" value="<?php if (isset($category['image_width'])) { echo esc_attr($category['image_width']); } ?> " class="small-text"> <label for="large_size_h"><?php esc_html_e('Height', 'wpsc'); ?> </label> <input name="image_height" type="number" step="1" min="0" id="image_height" value="<?php if (isset($category['image_height'])) { echo esc_attr($category['image_height']); } ?> " class="small-text"> </fieldset> </td> </tr> <?php } // 'getimagesize' condition ?> <tr> <td colspan="2"><h4><?php esc_html_e('Shortcodes and Template Tags', 'wpsc'); ?> </h4></td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Display Category Shortcode', 'wpsc'); ?> </label> </th> <td> <code>[wpsc_products category_url_name='<?php echo $category["slug"]; ?> ']</code><br /> <span class="description"><?php esc_html_e('Shortcodes are used to display a particular category or group within any WordPress page or post.', 'wpsc'); ?> </span> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Display Category Template Tag', 'wpsc'); ?> </label> </th> <td> <code><?php echo wpsc_display_products_page( array( 'category_url_name' => '<?php echo $category["slug"]; ?> ' ) ); ?></code><br /> <span class="description"><?php esc_html_e('Template tags are used to display a particular category or group within your theme / template.', 'wpsc'); ?> </span> </td> </tr> <!-- START OF TARGET MARKET SELECTION --> <tr> <td colspan="2"> <h4><?php esc_html_e('Target Market Restrictions', 'wpsc'); ?> </h4> </td> </tr> <?php $countrylist = WPSC_Countries::get_countries_array(true, true); $selectedCountries = wpsc_get_meta($category_id, 'target_market', 'wpsc_category'); ?> <tr> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Target Markets', 'wpsc'); ?> </label> </th> <td> <?php if (wpsc_is_suhosin_enabled()) { ?> <em><?php esc_html_e('The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature, then disable the suhosin extension. If you can not do this, you will need to contact your hosting provider.', 'wpsc'); ?> </em> <?php } else { ?> <span><?php esc_html_e('Select', 'wpsc'); ?> : <a href='' class='wpsc_select_all'><?php esc_html_e('All', 'wpsc'); ?> </a> <a href='' class='wpsc_select_none'><?php esc_html_e('None', 'wpsc'); ?> </a></span><br /> <div id='resizeable' class='ui-widget-content multiple-select'> <?php foreach ($countrylist as $country) { if (in_array($country['id'], (array) $selectedCountries)) { ?> <input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo $country['id']; ?> ' value='<?php echo $country['id']; ?> ' checked='<?php echo $country['visible']; ?> ' /> <label for="countrylist2-<?php echo $country['id']; ?> "><?php esc_html_e($country['country']); ?> </label><br /> <?php } else { ?> <input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo $country['id']; ?> ' value='<?php echo $country['id']; ?> ' /> <label for="countrylist2-<?php echo $country['id']; ?> "><?php esc_html_e($country['country']); ?> </label><br /> <?php } } ?> </div> <?php } ?> <br /> <span class="description"><?php esc_html_e('Select the markets you are selling this category to.', 'wpsc'); ?> </span> </td> </tr> <!-- Checkout settings --> <tr> <td colspan="2"> <h4><?php esc_html_e('Checkout Settings', 'wpsc'); ?> </h4> </td> </tr> <?php if (!isset($category['term_id'])) { $category['term_id'] = ''; } $used_additonal_form_set = wpsc_get_categorymeta($category['term_id'], 'use_additional_form_set'); $checkout_sets = get_option('wpsc_checkout_form_sets'); unset($checkout_sets[0]); $uses_billing_address = (bool) wpsc_get_categorymeta($category['term_id'], 'uses_billing_address'); ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Category requires additional checkout form fields', 'wpsc'); ?> </label> </th> <td> <select name='use_additional_form_set'> <option value=''><?php esc_html_e('None', 'wpsc'); ?> </option> <?php foreach ((array) $checkout_sets as $key => $value) { $selected_state = ""; if ($used_additonal_form_set == $key) { $selected_state = "selected='selected'"; } ?> <option <?php echo $selected_state; ?> value='<?php echo $key; ?> '><?php echo esc_html($value); ?> </option> <?php } ?> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php esc_html_e('Address to calculate shipping with', 'wpsc'); ?> </label> </th> <td> <label><input type="radio" class="wpsc_cat_box" value="0" name="uses_billing_address" <?php echo $uses_billing_address != true ? 'checked="checked"' : ''; ?> /> <?php esc_html_e('Shipping Address (default)', 'wpsc'); ?> </label><br /> <label><input type="radio" class="wpsc_cat_box" value="1" name="uses_billing_address" <?php echo $uses_billing_address == true ? 'checked="checked"' : ''; ?> /> <?php esc_html_e('Billing Address', 'wpsc'); ?> </label> <p class='description'><?php esc_html_e('Products in this category will use the address specified to calculate shipping costs.', 'wpsc'); ?> </p> </td> </tr> <?php }
/** * Retrieve meta field for a category * * @param int $cat_id Category ID. * @param string $meta_key The meta key to retrieve. * @return mixed Will be value of meta data field */ function wpsc_get_categorymeta($cat_id, $meta_key) { return wpsc_get_meta($cat_id, $meta_key, 'wpsc_category'); }
function wpsc_admin_category_forms_edit() { global $wpdb; $category_value_count = 0; $category_name = ''; $category = array(); $category_id = absint($_REQUEST["tag_ID"]); $category = get_term($category_id, 'wpsc_product_category', ARRAY_A); $category['nice-name'] = wpsc_get_categorymeta($category['term_id'], 'nice-name'); $category['description'] = wpsc_get_categorymeta($category['term_id'], 'description'); $category['image'] = wpsc_get_categorymeta($category['term_id'], 'image'); $category['fee'] = wpsc_get_categorymeta($category['term_id'], 'fee'); $category['active'] = wpsc_get_categorymeta($category['term_id'], 'active'); $category['order'] = wpsc_get_categorymeta($category['term_id'], 'order'); $category['display_type'] = wpsc_get_categorymeta($category['term_id'], 'display_type'); $category['image_height'] = wpsc_get_categorymeta($category['term_id'], 'image_height'); $category['image_width'] = wpsc_get_categorymeta($category['term_id'], 'image_width'); $category['use_additional_form_set'] = wpsc_get_categorymeta($category['term_id'], 'use_additional_form_set'); ?> <tr> <td colspan="2"> <h3><?php _e('Advanced Settings', 'wpsc'); ?> </h3> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="display_type"><?php _e('Catalog View', 'wpsc'); ?> </label> </th> <td> <?php //Could probably be *heavily* refactored later just to use do_action here and in GoldCart. Baby steps. if (!isset($category['display_type'])) { $category['display_type'] = ''; } if ($category['display_type'] == 'grid') { $display_type1 = "selected='selected'"; } else { if ($category['display_type'] == 'default') { $display_type2 = "selected='selected'"; } } switch ($category['display_type']) { case "default": $category_view1 = "selected ='selected'"; break; case "grid": if (function_exists('product_display_grid')) { $category_view3 = "selected ='selected'"; break; } case "list": if (function_exists('product_display_list')) { $category_view2 = "selected ='selected'"; break; } default: $category_view0 = "selected ='selected'"; break; } ?> <select name='display_type'> <option value=''<?php echo $category_view0; ?> ><?php _e('Please select', 'wpsc'); ?> </option> <option value='default' <?php if (isset($category_view1)) { echo $category_view1; } ?> ><?php _e('Default View', 'wpsc'); ?> </option> <?php if (function_exists('product_display_list')) { ?> <option value='list' <?php echo $category_view2; ?> ><?php _e('List View', 'wpsc'); ?> </option> <?php } else { ?> <option value='list' disabled='disabled' <?php if (isset($category_view2)) { echo $category_view2; } ?> ><?php _e('List View', 'wpsc'); ?> </option> <?php } ?> <?php if (function_exists('product_display_grid')) { ?> <option value='grid' <?php if (isset($category_view3)) { echo $category_view3; } ?> ><?php _e('Grid View', 'wpsc'); ?> </option> <?php } else { ?> <option value='grid' disabled='disabled' <?php if (isset($category_view3)) { echo $category_view3; } ?> ><?php _e('Grid View', 'wpsc'); ?> </option> <?php } ?> </select><br /> <span class="description"><?php _e('To over-ride the presentation settings for this group you can enter in your prefered settings here', 'wpsc'); ?> </span> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Category Image', 'wpsc'); ?> </label> </th> <td> <input type='file' name='image' value='' /><br /> <label><input type='checkbox' name='deleteimage' class="wpsc_cat_box" value='1' /><?php _e('Delete Image', 'wpsc'); ?> </label><br/> <span class="description"><?php _e('You can set an image for the category here. If one exists, check the box to delete.', 'wpsc'); ?> </span> </td> </tr> <?php if (function_exists("getimagesize")) { ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Thumbnail Size', 'wpsc'); ?> </label> </th> <td> <?php _e('Width', 'wpsc'); ?> <input type='text' class="wpsc_cat_image_size" value='<?php if (isset($category['image_width'])) { echo $category['image_width']; } ?> ' name='image_width' size='6' /> <?php _e('Height', 'wpsc'); ?> <input type='text' class="wpsc_cat_image_size" value='<?php if (isset($category['image_height'])) { echo $category['image_height']; } ?> ' name='image_height' size='6' /><br/> </td> </tr> <?php } // 'getimagesize' condition ?> <tr> <td colspan="2"><h3><?php _e('Shortcodes and Template Tags', 'wpsc'); ?> </h3></td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Display Category Shortcode', 'wpsc'); ?> :</label> </th> <td> <span>[wpsc_products category_url_name='<?php echo $category["slug"]; ?> ']</span><br /> <span class="description"><?php _e('Shortcodes are used to display a particular category or group within any WordPress page or post.', 'wpsc'); ?> </span> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Display Category Template Tag', 'wpsc'); ?> :</label> </th> <td> <span><?php echo wpsc_display_products_page( array( 'category_url_name'=>'<?php echo $category["slug"]; ?> ' ) ); ?></span><br /> <span class="description"><?php _e('Template tags are used to display a particular category or group within your theme / template.', 'wpsc'); ?> </span> </td> </tr> <!-- START OF TARGET MARKET SELECTION --> <tr> <td colspan="2"> <h3><?php _e('Target Market Restrictions', 'wpsc'); ?> </h3> </td> </tr> <?php $countrylist = $wpdb->get_results("SELECT id,country,visible FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC ", ARRAY_A); $selectedCountries = wpsc_get_meta($category_id, 'target_market', 'wpsc_category'); ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Target Markets', 'wpsc'); ?> :</label> </th> <td> <?php if (@extension_loaded('suhosin')) { ?> <em><?php _e('The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature, then disable the suhosin extension. If you can not do this, you will need to contact your hosting provider.', 'wpsc'); ?> </em> <?php } else { ?> <span><?php _e('Select', 'wpsc'); ?> : <a href='' class='wpsc_select_all'><?php _e('All', 'wpsc'); ?> </a> <a href='' class='wpsc_select_none'><?php _e('None', 'wpsc'); ?> </a></span><br /> <div id='resizeable' class='ui-widget-content multiple-select'> <?php foreach ($countrylist as $country) { if (in_array($country['id'], (array) $selectedCountries)) { echo " <input type='checkbox' class='wpsc_cat_box' name='countrylist2[]' value='" . $country['id'] . "' checked='" . $country['visible'] . "' />" . $country['country'] . "<br />"; } else { echo " <input type='checkbox' class='wpsc_cat_box' name='countrylist2[]' value='" . $country['id'] . "' />" . $country['country'] . "<br />"; } } ?> </div> <?php } ?> <br /> <span class="description"><?php _e('Select the markets you are selling this category to.', 'wpsc'); ?> </span> </td> </tr> <!-- Checkout settings --> <tr> <td colspan="2"> <h3><?php _e('Checkout Settings', 'wpsc'); ?> </h3> </td> </tr> <?php if (!isset($category['term_id'])) { $category['term_id'] = ''; } $used_additonal_form_set = wpsc_get_categorymeta($category['term_id'], 'use_additional_form_set'); $checkout_sets = get_option('wpsc_checkout_form_sets'); unset($checkout_sets[0]); $uses_billing_address = (bool) wpsc_get_categorymeta($category['term_id'], 'uses_billing_address'); ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Category requires additional checkout form fields', 'wpsc'); ?> </label> </th> <td> <select name='use_additional_form_set'> <option value=''><?php _e('None', 'wpsc'); ?> </option> <?php foreach ((array) $checkout_sets as $key => $value) { $selected_state = ""; if ($used_additonal_form_set == $key) { $selected_state = "selected='selected'"; } ?> <option <?php echo $selected_state; ?> value='<?php echo $key; ?> '><?php echo stripslashes($value); ?> </option> <?php } ?> </select><br /> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php _e('Products in this category use the billing address to calculate shipping', 'wpsc'); ?> </label> </th> <td> <input type='radio' class="wpsc_cat_box" value='1' name='uses_billing_address' <?php echo $uses_billing_address == true ? "checked='checked'" : ""; ?> /><?php _e('Yes', 'wpsc'); ?> <input type='radio' class="wpsc_cat_box" value='0' name='uses_billing_address' <?php echo $uses_billing_address != true ? "checked='checked'" : ""; ?> /><?php _e('No', 'wpsc'); ?> <br /> </td> </tr> <?php }
/** * Cycles through the categories represented by the products in the cart. * Retrieves their target markets and returns an array of acceptable markets * We're only listing target markets that are acceptable for ALL categories in the cart * * @since 3.8.9 * @return array Countries that can be shipped to. If empty, sets session variable with appropriate error message */ function wpsc_get_acceptable_countries() { global $wpdb; $cart_category_ids = array_unique(wpsc_cart_item_categories(true)); $target_market_ids = array(); foreach ($cart_category_ids as $category_id) { $target_markets = wpsc_get_meta($category_id, 'target_market', 'wpsc_category'); if (!empty($target_markets)) { $target_market_ids[$category_id] = $target_markets; } } $have_target_market = !empty($target_market_ids); //If we're comparing multiple categories if (count($target_market_ids) > 1) { $target_market_ids = call_user_func_array('array_intersect', $target_market_ids); } elseif ($have_target_market) { $target_market_ids = array_values($target_market_ids); $target_market_ids = $target_market_ids[0]; } $country_data = WPSC_Countries::get_countries_array(); $have_target_market = $have_target_market && count($country_data) != count($target_market_ids); $GLOBALS['wpsc_country_data'] = $country_data; // TODO Is this ever used? $conflict_error = wpsc_get_customer_meta('category_shipping_conflict'); $target_conflict = wpsc_get_customer_meta('category_shipping_target_market_conflict'); // Return true if there are no restrictions if (!$have_target_market) { // clear out the target market messages if (!empty($target_conflict)) { wpsc_delete_customer_meta('category_shipping_conflict'); } wpsc_update_customer_meta('category_shipping_target_market_conflict', false); wpsc_update_customer_meta('category_shipping_conflict', false); return true; } // temporarily hijack this session variable to display target market restriction warnings if (!empty($target_conflict) || !wpsc_has_category_and_country_conflict()) { wpsc_update_customer_meta('category_shipping_target_market_conflict', true); wpsc_update_customer_meta('category_shipping_conflict', __("Some of your cart items are targeted specifically to certain markets. As a result, you can only select those countries as your shipping destination.", 'wp-e-commerce')); } if (empty($target_market_ids)) { wpsc_update_customer_meta('category_shipping_target_market_conflict', true); wpsc_update_customer_meta('category_shipping_conflict', __('It appears that some products in your cart have conflicting target market restrictions. As a result, there is no common destination country where your cart items can be shipped to. Please contact the site administrator for more information.', 'wp-e-commerce')); } return $target_market_ids; }
/** * wpsc display products function * @return string - html displaying one or more products */ function wpsc_display_products_page($query) { global $wpdb, $wpsc_query, $wp_query, $wp_the_query; remove_filter('the_title', 'wpsc_the_category_title'); // If the data is coming from a shortcode parse the values into the args variable, // I did it this was to preserve backwards compatibility if (!empty($query)) { $args = array(); $args['post_type'] = 'wpsc-product'; if (!empty($query['product_id']) && is_array($query['product_id'])) { $args['post__in'] = $query['product_id']; } elseif (is_string($query['product_id'])) { $args['post__in'] = (array) $query['product_id']; } if (!empty($query['old_product_id'])) { $post_id = wpsc_get_the_new_id($query['old_product_id']); $args['post__in'] = (array) $post_id; } if (!empty($query['price']) && 'sale' != $query['price']) { $args['meta_key'] = '_wpsc_price'; $args['meta_value'] = $query['price']; } elseif (!empty($query['price']) && 'sale' == $query['price']) { $args['meta_key'] = '_wpsc_special_price'; $args['meta_compare'] = '>='; $args['meta_value'] = '1'; } if (!empty($query['product_name'])) { $args['pagename'] = $query['product_name']; } if (!empty($query['category_id'])) { $term = get_term($query['category_id'], 'wpsc_product_category'); $id = wpsc_get_meta($query['category_id'], 'category_id', 'wpsc_old_category'); if (!empty($id)) { $term = get_term($id, 'wpsc_product_category'); $args['wpsc_product_category'] = $term->slug; $args['wpsc_product_category__in'] = $term->term_id; } else { $args['wpsc_product_category'] = $term->slug; $args['wpsc_product_category__in'] = $term->term_id; } } if (!empty($query['category_url_name'])) { $args['wpsc_product_category'] = $query['category_url_name']; } $orderby = !empty($query['sort_order']) ? $query['sort_order'] : null; $args = array_merge($args, wpsc_product_sort_order_query_vars($orderby)); if (!empty($query['order'])) { $args['order'] = $query['order']; } if (!empty($query['limit_of_items']) && '1' == get_option('use_pagination')) { $args['posts_per_page'] = $query['limit_of_items']; } if (!empty($query['number_per_page']) && '1' == get_option('use_pagination')) { $args['posts_per_page'] = $query['number_per_page']; $args['paged'] = $query['page']; } if ('0' == get_option('use_pagination')) { $args['nopaging'] = true; $args['posts_per_page'] = '-1'; } if (!empty($query['tag'])) { $args['product_tag'] = $query['tag']; } query_posts($args); } // swap the wpsc_query objects $GLOBALS['nzshpcrt_activateshpcrt'] = true; // Pretty sure this single_product code is legacy...but fixing it up just in case. // get the display type for the selected category if (!empty($wpsc_query->query_vars['term'])) { $display_type = wpsc_get_the_category_display($wpsc_query->query_vars['term']); } elseif (!empty($args['wpsc_product_category'])) { $display_type = wpsc_get_the_category_display($args['wpsc_product_category']); } else { $display_type = 'default'; } $saved_display = wpsc_get_customer_meta('display_type'); $display_type = !empty($saved_display) ? $saved_display : $display_type; ob_start(); do_action('wpsc_display_products_page', $display_type); if (isset($wp_query->post) && 'wpsc-product' == $wp_query->post->post_type && !is_archive() && $wp_query->post_count <= 1) { include wpsc_get_template_file_path('wpsc-single_product.php'); } else { wpsc_include_products_page_template($display_type); } $output = ob_get_contents(); ob_end_clean(); $output = str_replace('\\$', '$', $output); if (!empty($query)) { wp_reset_query(); wp_reset_postdata(); } return $output; }
/** * Adds a link to resend the tickets to the customer * in the order edit screen. */ public function add_resend_tickets_action() { if (empty($_GET['id'])) { return; } $order = $_GET['id']; $has_tickets = wpsc_get_meta($order, $this->order_done, 'tribe_tickets'); if (!$has_tickets) { return; } $url = add_query_arg('tribe_resend_ticket', 1); echo sprintf("<img src='%s'> ", esc_url($this->pluginUrl . 'src/resources/images/ticket.png')); echo sprintf("<a href='%s'>%s</a>", esc_url($url), esc_html__('Resend Tickets', 'event-tickets-plus')); if (!empty($_GET['tribe_resend_ticket'])) { $this->send_email(new WPSC_Purchase_Log($order, 'id')); echo esc_html__(' [Sent]', 'event-tickets-plus'); } echo '<br/><br/>'; }
/** * submit checkout function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_submit_checkout($collected_data = true) { global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; if ($collected_data && isset($_POST['collected_data']) && is_array($_POST['collected_data'])) { _wpsc_checkout_customer_meta_update($_POST['collected_data']); } // initialize our checkout status variab;e, we start be assuming // checkout is falid, until we find a reason otherwise $is_valid = true; $num_items = 0; $use_shipping = 0; $disregard_shipping = 0; do_action('wpsc_before_submit_checkout'); $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages'); if (!is_array($error_messages)) { $error_messages = array(); } $wpsc_checkout = new wpsc_checkout(); $selected_gateways = get_option('custom_gateway_options'); $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : ''; if ($collected_data) { $form_validity = $wpsc_checkout->validate_forms(); extract($form_validity); // extracts $is_valid and $error_messages if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) { $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } } else { $is_valid = true; $error_messages = array(); } $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry')); $country_id = $wpsc_country->get_id(); $country_name = $wpsc_country->get_name(); foreach ($wpsc_cart->cart_items as $cartitem) { if (!empty($cartitem->meta[0]['no_shipping'])) { continue; } $categoriesIDs = $cartitem->category_id_list; foreach ((array) $categoriesIDs as $catid) { if (is_array($catid)) { $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category'); } else { $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category'); } if (!empty($countries) && !in_array($country_id, (array) $countries)) { $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->get_title(), $country_name); wpsc_update_customer_meta('category_shipping_conflict', $errormessage); $is_valid = false; } } //count number of items, and number of items using shipping $num_items++; if ($cartitem->uses_shipping != 1) { $disregard_shipping++; } else { $use_shipping++; } } // check to see if the current gateway is in the list of available gateways if (array_search($submitted_gateway, $selected_gateways) !== false) { wpsc_update_customer_meta('selected_gateway', $submitted_gateway); } else { $is_valid = false; } if ($collected_data) { // Test for required shipping information if (wpsc_core_shipping_enabled() && $num_items != $disregard_shipping) { // for shipping to work we need a method, option and a quote if (!$wpsc_cart->shipping_method_selected() || !$wpsc_cart->shipping_quote_selected()) { $error_messages[] = __('Please select one of the available shipping options, then we can process your order.', 'wpsc'); $is_valid = false; } // if we don't have a valid zip code ( the function also checks if we need it ) we have an error if (!wpsc_have_valid_shipping_zipcode()) { wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc')); $is_valid = false; } } } wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages); if ($is_valid == true) { wpsc_delete_customer_meta('category_shipping_conflict'); // check that the submitted gateway is in the list of selected ones $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('checkout_session_id', $sessionid); $subtotal = $wpsc_cart->calculate_subtotal(); if ($wpsc_cart->has_total_shipping_discount() == false) { $base_shipping = $wpsc_cart->calculate_base_shipping(); } else { $base_shipping = 0; } $delivery_country = $wpsc_cart->delivery_country; $delivery_region = $wpsc_cart->delivery_region; if (wpsc_uses_shipping()) { $shipping_method = $wpsc_cart->selected_shipping_method; $shipping_option = $wpsc_cart->selected_shipping_option; } else { $shipping_method = ''; $shipping_option = ''; } if (isset($_POST['how_find_us'])) { $find_us = $_POST['how_find_us']; } else { $find_us = ''; } //keep track of tax if taxes are exclusive $wpec_taxes_controller = new wpec_taxes_controller(); if (!$wpec_taxes_controller->wpec_taxes_isincluded()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0.0; $tax_percentage = 0.0; } $total = $wpsc_cart->calculate_total_price(); $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage); $purchase_log = new WPSC_Purchase_Log($args); $purchase_log->save(); $purchase_log_id = $purchase_log->get('id'); if ($collected_data) { $wpsc_checkout->save_forms_to_db($purchase_log_id); } $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); if (!isset($our_user_id) && isset($user_ID)) { $our_user_id = $user_ID; } $wpsc_cart->log_id = $purchase_log_id; do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => $our_user_id)); do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log); } }
/** * wpsc_get_terms_category_sort_filter * * This sorts the categories when a call to get_terms is made * @param object array $terms * @param array $taxonomies * @param array $args * @return object array $terms */ function wpsc_get_terms_category_sort_filter($terms) { $new_terms = array(); $i = 0; foreach ($terms as $term) { if (!is_object($term)) { return $terms; } $term_order = wpsc_get_meta($term->term_id, 'sort_order', 'wpsc_category'); if (isset($term_order) && is_numeric($term_order) && !isset($new_terms[$term_order])) { $term->sort_order = $term_order; $new_terms[$term_order] = $term; } elseif (isset($new_terms[$term_order])) { //this must have been recently moved or something, palce it at the end $newID = count($terms); while (isset($new_terms[$newID])) { $newID++; } $term->sort_order = $newID; $new_terms[$newID] = $term; } elseif (is_object($term)) { //Term has no order make one up, also helps if it's not one of our terms $term->sort_order = $i; $new_terms[$i] = $term; $i++; } } ksort($new_terms); return $new_terms; }
function wpsc_st_get_ip_address($purchase_id) { global $wpdb; $output = '-'; if ($purchase_id) { $ip_address = wpsc_get_meta($purchase_id, 'ip_address', 'purchase_log'); if ($ip_address) { $output = $ip_address; } } return $output; }
/** * Pushes sales data back to Baikonur * * Only pushes once. Accounts for annoying potential edge case of status-switching admins * * @param WPSC_Purchase_Log object $purchase_log Purchase Log object * @return void */ public static function push_sales_data($purchase_log_id, $current_status, $old_status, $purchase_log) { $purchase_log = new WPSC_Purchase_Log($purchase_log_id); $id = absint($purchase_log->get('id')); //Also checking is_order_received, as that's what Manual Payments do. if ($purchase_log->is_transaction_completed() || $purchase_log->is_order_received()) { $pushed_to_sass = wpsc_get_meta($id, '_pushed_to_wpeconomy', 'purchase_log'); if (empty($pushed_to_saas)) { $data = $purchase_log->get_data(); $cart_contents = $purchase_log->get_cart_contents(); //We want to push sales data - but naturally, IDs will differ, even names could potentially. //So we add the slug to the object we POST foreach ($cart_contents as $key => $cart_item) { $slug = get_post_field('post_name', $cart_item->prodid); $cart_contents[$key]->slug = $slug; } $args = array('body' => array('data' => json_encode($data), 'cart_contents' => json_encode($cart_contents))); $request = wp_remote_post('http://www.wpeconomy.org/?sales_data=true', $args); $response = wp_remote_retrieve_response_code($request); //For some reason, if the site is down, we want the ability to ensure we can grab the sale later. $success = 200 === $response; wpsc_update_meta($id, '_pushed_to_wpeconomy', $success, 'purchase_log'); } } }