function wpsc_update_variations() { $product_id = absint($_POST["product_id"]); $product_type_object = get_post_type_object('wpsc-product'); if (!current_user_can($product_type_object->cap->edit_post, $product_id)) { return; } //Setup postdata $post_data = array(); $post_data['edit_var_val'] = isset($_POST['edit_var_val']) ? $_POST["edit_var_val"] : ''; //Add or delete variations wpsc_edit_product_variations($product_id, $post_data); }
function wpsc_update_variations() { $product_id = absint($_POST["product_id"]); $product_type_object = get_post_type_object('wpsc-product'); if (!current_user_can($product_type_object->cap->edit_post, $product_id)) { return; } //Setup postdata $post_data = array(); $post_data['edit_var_val'] = isset($_POST['edit_var_val']) ? $_POST["edit_var_val"] : ''; $post_data['description'] = isset($_POST['description']) ? $_POST["description"] : ''; $post_data['additional_description'] = isset($_POST['additional_description']) ? $_POST['additional_description'] : ''; $post_data['name'] = !empty($_POST['name']) ? $_POST['name'] : $_POST["post_title"]; //Add or delete variations wpsc_edit_product_variations($product_id, $post_data); if (defined('DOING_AJAX') && DOING_AJAX) { wpsc_admin_product_listing($product_id); die; } }
/** * wpsc_admin_submit_product function * @internal Was going to completely refactor sanitise forms and wpsc_insert_product, but they are also used by the import system * which I'm not really familiar with...so I'm not touching them :) Erring on the side of redundancy and caution I'll just * refactor this to do the job. * @return nothing */ function wpsc_admin_submit_product($post_ID, $post) { global $current_screen, $wpdb; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || empty($current_screen) || $current_screen->id != 'wpsc-product' || $post->post_type != 'wpsc-product' || empty($_POST['meta'])) { return $post_ID; } //Type-casting ( not so much sanitization, which would be good to do ) $post_data = $_POST; $product_id = $post_ID; $post_data['additional_description'] = isset($post_data['additional_description']) ? $post_data['additional_description'] : ''; $post_meta['meta'] = (array) $_POST['meta']; if (isset($post_data['meta']['_wpsc_price'])) { $post_data['meta']['_wpsc_price'] = abs((double) str_replace(',', '', $post_data['meta']['_wpsc_price'])); } if (isset($post_data['meta']['_wpsc_special_price'])) { $post_data['meta']['_wpsc_special_price'] = abs((double) str_replace(',', '', $post_data['meta']['_wpsc_special_price'])); } if ($post_data['meta']['_wpsc_sku'] == __('N/A', 'wpsc')) { $post_data['meta']['_wpsc_sku'] = ''; } if (isset($post_data['meta']['_wpsc_is_donation'])) { $post_data['meta']['_wpsc_is_donation'] = 1; } else { $post_data['meta']['_wpsc_is_donation'] = 0; } if (!isset($post_data['meta']['_wpsc_limited_stock'])) { $post_data['meta']['_wpsc_stock'] = false; } else { $post_data['meta']['_wpsc_stock'] = isset($post_data['meta']['_wpsc_stock']) ? (int) $post_data['meta']['_wpsc_stock'] : 0; } unset($post_data['meta']['_wpsc_limited_stock']); if (!isset($post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'])) { $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = ''; } if (!isset($post_data['quantity_limited'])) { $post_data['quantity_limited'] = ''; } if (!isset($post_data['special'])) { $post_data['special'] = ''; } if (!isset($post_data['meta']['_wpsc_product_metadata']['no_shipping'])) { $post_data['meta']['_wpsc_product_metadata']['no_shipping'] = ''; } $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left']; $post_data['meta']['_wpsc_product_metadata']['quantity_limited'] = (int) (bool) $post_data['quantity_limited']; $post_data['meta']['_wpsc_product_metadata']['special'] = (int) (bool) $post_data['special']; $post_data['meta']['_wpsc_product_metadata']['no_shipping'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['no_shipping']; // Product Weight if (!isset($post_data['meta']['_wpsc_product_metadata']['display_weight_as'])) { $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = ''; } if (!isset($post_data['meta']['_wpsc_product_metadata']['display_weight_as'])) { $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = ''; } $weight = wpsc_convert_weight($post_data['meta']['_wpsc_product_metadata']['weight'], $post_data['meta']['_wpsc_product_metadata']['weight_unit'], "pound", true); $post_data['meta']['_wpsc_product_metadata']['weight'] = (double) $weight; $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = $post_data['meta']['_wpsc_product_metadata']['weight_unit']; // table rate price $post_data['meta']['_wpsc_product_metadata']['table_rate_price'] = isset($post_data['table_rate_price']) ? $post_data['table_rate_price'] : array(); // if table_rate_price is unticked, wipe the table rate prices if (empty($post_data['table_rate_price']['state'])) { $post_data['meta']['_wpsc_product_metadata']['table_rate_price']['table_price'] = array(); $post_data['meta']['_wpsc_product_metadata']['table_rate_price']['quantity'] = array(); } if (!empty($post_data['meta']['_wpsc_product_metadata']['table_rate_price']['table_price'])) { foreach ((array) $post_data['meta']['_wpsc_product_metadata']['table_rate_price']['table_price'] as $key => $value) { if (empty($value)) { unset($post_data['meta']['_wpsc_product_metadata']['table_rate_price']['table_price'][$key]); unset($post_data['meta']['_wpsc_product_metadata']['table_rate_price']['quantity'][$key]); } } } $post_data['meta']['_wpsc_product_metadata']['shipping']['local'] = (double) $post_data['meta']['_wpsc_product_metadata']['shipping']['local']; $post_data['meta']['_wpsc_product_metadata']['shipping']['international'] = (double) $post_data['meta']['_wpsc_product_metadata']['shipping']['international']; // Advanced Options $post_data['meta']['_wpsc_product_metadata']['engraved'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['engraved']; $post_data['meta']['_wpsc_product_metadata']['can_have_uploaded_image'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['can_have_uploaded_image']; if (!isset($post_data['meta']['_wpsc_product_metadata']['google_prohibited'])) { $post_data['meta']['_wpsc_product_metadata']['google_prohibited'] = ''; } $post_data['meta']['_wpsc_product_metadata']['google_prohibited'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['google_prohibited']; $post_data['meta']['_wpsc_product_metadata']['enable_comments'] = $post_data['meta']['_wpsc_product_metadata']['enable_comments']; $post_data['meta']['_wpsc_product_metadata']['merchant_notes'] = $post_data['meta']['_wpsc_product_metadata']['merchant_notes']; $post_data['files'] = $_FILES; if (isset($post_data['post_title']) && $post_data['post_title'] != '') { $product_columns = array('name' => '', 'description' => '', 'additional_description' => '', 'price' => null, 'weight' => null, 'weight_unit' => '', 'pnp' => null, 'international_pnp' => null, 'file' => null, 'image' => '0', 'quantity_limited' => '', 'quantity' => null, 'special' => null, 'special_price' => null, 'display_frontpage' => null, 'notax' => null, 'publish' => null, 'active' => null, 'donation' => null, 'no_shipping' => null, 'thumbnail_image' => null, 'thumbnail_state' => null); foreach ($product_columns as $column => $default) { if (!isset($post_data[$column])) { $post_data[$column] = ''; } if ($post_data[$column] !== null) { $update_values[$column] = stripslashes($post_data[$column]); } else { if ($update != true && $default !== null) { $update_values[$column] = stripslashes($default); } } } // if we succeed, we can do further editing (todo - if_wp_error) // if we have no categories selected, assign one. if (isset($post_data['tax_input']['wpsc_product_category']) && count($post_data['tax_input']['wpsc_product_category']) == 1 && $post_data['tax_input']['wpsc_product_category'][0] == 0) { $post_data['tax_input']['wpsc_product_category'][1] = wpsc_add_product_category_default($product_id); } // and the meta wpsc_update_product_meta($product_id, $post_data['meta']); // and the custom meta wpsc_update_custom_meta($product_id, $post_data); // sort out the variations wpsc_edit_product_variations($product_id, $post_data); //and the alt currency if (!empty($post_data['newCurrency'])) { foreach ((array) $post_data['newCurrency'] as $key => $value) { wpsc_update_alt_product_currency($product_id, $value, $post_data['newCurrPrice'][$key]); } } if ($post_data['files']['file']['tmp_name'] != '') { wpsc_item_process_file($product_id, $post_data['files']['file']); } else { if (!isset($post_data['select_product_file'])) { $post_data['select_product_file'] = null; } wpsc_item_reassign_file($product_id, $post_data['select_product_file']); } if (isset($post_data['files']['preview_file']['tmp_name']) && $post_data['files']['preview_file']['tmp_name'] != '') { wpsc_item_add_preview_file($product_id, $post_data['files']['preview_file']); } do_action('wpsc_edit_product', $product_id); wpsc_ping(); } return $product_id; }
function sm_wpsc_update_variations($product_id, $edit_var_val) { $product_type_object = get_post_type_object('wpsc-product'); //Setup postdata $post_data = array(); $post_data['edit_var_val'] = count($edit_var_val) > 0 ? $edit_var_val : ''; $post_data['description'] = ''; $post_data['additional_description'] = ''; $post_data['name'] = get_the_title($product_id); $_REQUEST["product_id"] = $product_id; wpsc_edit_product_variations($product_id, $post_data); }