/** * Generate variations * * @since 3.8.9 * @access private * * @uses wpsc_update_variations() Updates product variations given * @uses wpsc_admin_product_listing() DEPRECATED * * @return array|WP_Error Response args if successful, WP_Error if otherwise */ function _wpsc_ajax_update_variations() { $product_id = absint($_REQUEST["product_id"]); wpsc_update_variations(); ob_start(); wpsc_admin_product_listing($product_id); $content = ob_get_clean(); return array('content' => $content); }
function wpsc_product_variation_forms() { require_once 'walker-variation-checklist.php'; global $post, $wpdb, $wp_query, $variations_processor, $wpsc_product_defaults; $db_version = get_option('db_version'); $product_data = get_post_custom($post->ID); $product_data['meta'] = maybe_unserialize($product_data); foreach ($product_data['meta'] as $meta_key => $meta_value) { $product_data['meta'][$meta_key] = $meta_value[0]; } $product_meta = array(); if (!empty($product_data["_wpsc_product_metadata"])) { $product_meta = maybe_unserialize($product_data["_wpsc_product_metadata"][0]); } $siteurl = get_option('siteurl'); $output = ''; ?> <a name="#wpsc_variation_metabox"></a> <?php if (empty($post->post_title)) { ?> <p><?php _e('You must first save this Product as a Draft before adding variations.', 'wpsc'); ?> </p> <h4><a href="<?php echo get_admin_url(); ?> /edit-tags.php?taxonomy=wpsc-variation&post_type=wpsc-product" target="_blank">+ Add New Variation Set</a></h4> <?php } else { ?> <div id="product_variations"> <p><a name='variation_control'> </a><?php _e('Select the Variation sets and then the corresponding Variants you want to add to this product.', 'wpsc'); ?> </p> <ul class="variation_checkboxes"> <?php wp_terms_checklist($post->ID, array('taxonomy' => 'wpsc-variation', 'walker' => new WPSC_Walker_Variation_Checklist(), 'checked_ontop' => false)); ?> </ul> <p class="update-variations"> <a class="button update_variations_action" href='#'><?php _e('Apply Variations →', 'wpsc'); ?> </a> <img src="<?php echo esc_url(admin_url('images/wpspin_light.gif')); ?> " class="ajax-feedback" title="" alt="" /><br class="clear" /> </p> <div class="clear"></div> <h4><a href="#wpsc_variation_metabox" class="add_variation_set_action"><?php esc_html_e('+ Add New Variants', 'wpsc'); ?> </a></h4> <div id="add-new-variation-set"> <p> <label for="new-variation-set-name"><?php esc_html_e("Enter variation set's name", 'wpsc'); ?> </label> <input type="text" class="text-field" id="new-variation-set-name" /><br /> </p> <p class="howto"><?php esc_html_e("Example: Color. If you want to add variants to an existing set, you can enter the name of that set here.", 'wpsc'); ?> </p> <p> <label for="new-variants"><?php esc_html_e("Enter new variants", 'wpsc'); ?> </label> <input type="text" class="text-field" id="new-variants" /><br /> </p> <p class="howto"><?php esc_html_e("Example: Red, Green, Blue. Separate variants with commas.", 'wpsc'); ?> </p> <p> <a class="button" href="#"><?php esc_html_e('Add New Variants', 'wpsc'); ?> </a> <img src="<?php echo esc_url(admin_url('images/wpspin_light.gif')); ?> " class="ajax-feedback" title="" alt="" /><br class="clear" /> </p> </div> </div> <?php $parent_product = $post->ID; $query = array('post_type' => 'wpsc-product', 'orderby' => 'menu_order post_title', 'post_parent' => $parent_product, 'post_status' => 'publish, inherit', 'order' => "ASC"); $args = array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $parent_product, 'orderby' => 'menu_order', 'order' => 'ASC'); $image_data = (array) get_posts($args); $parent_product_data['image'] = array_shift($image_data); query_posts($query); if (!isset($parent_product_data)) { $parent_product_data = null; } ?> <table class="widefat page" id='wpsc_product_list' cellspacing="0"> <thead> <tr> <?php print_column_headers('wpsc-product_variants'); ?> </tr> </thead> <tfoot> <tr> <?php print_column_headers('wpsc-product_variants', false); ?> </tr> </tfoot> <tbody> <?php wpsc_admin_product_listing($parent_product_data); if (!have_posts()) { ?> <tr> <td colspan="8"> <?php _e('You have no Variations added.', 'wpsc'); ?> </td> </tr> <?php } ?> </tbody> </table> <?php } wp_reset_query(); // reset the global $id variable. This is to prevent incompatibility with Genesis framework, // which (wrongly) relies on this global. $GLOBALS['id'] = null; }
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; } }
function wpsc_product_variation_forms() { global $post, $wpdb, $wp_query, $variations_processor, $wpsc_product_defaults; $db_version = get_option('db_version'); $product_data = get_post_custom($post->ID); $product_data['meta'] = maybe_unserialize($product_data); foreach ($product_data['meta'] as $meta_key => $meta_value) { $product_data['meta'][$meta_key] = $meta_value[0]; } $product_meta = array(); if (!empty($product_data["_wpsc_product_metadata"])) { $product_meta = maybe_unserialize($product_data["_wpsc_product_metadata"][0]); } $siteurl = get_option('siteurl'); $output = ''; // Get variation data from WP Terms $product_term_data = wp_get_object_terms($post->ID, 'wpsc-variation'); if (!empty($product_term_data)) { foreach ($product_term_data as $product_term) { $product_terms[] = $product_term->term_id; } } else { $product_terms = array(); } ?> <?php if (empty($post->post_title)) { ?> <p><?php _e('You must first save this Product as a Draft before adding variations', 'wpsc'); ?> </p> <?php } else { ?> <div id="product_variations"> <div class="variation_checkboxes"> <?php // Get the terms from variations $variation_sets = get_terms('wpsc-variation', array('hide_empty' => 0, 'parent' => 0)); // Loop through each variation set foreach ((array) $variation_sets as $variation_set) { $set_checked_state = ''; // If this Product includes this variation, check it if (in_array($variation_set->term_id, $product_terms)) { $set_checked_state = "checked='checked'"; } ?> <div class="variation_set"> <label class='set_label'> <input type="checkbox" <?php echo $set_checked_state; ?> name="variations[<?php echo $variation_set->term_id; ?> ]" value="1"> <?php echo $variation_set->name; ?> </label> <?php $variations = get_terms('wpsc-variation', array('hide_empty' => 0, 'parent' => $variation_set->term_id)); // Loop through the variations foreach ((array) $variations as $variation) { $checked_state = ''; if (in_array($variation->term_id, $product_terms)) { $checked_state = "checked='checked'"; } ?> <div class="variation"> <label> <input type="checkbox" <?php echo $checked_state; ?> name="edit_var_val[<?php echo $variation_set->term_id; ?> ][<?php echo $variation->term_id; ?> ]" value="1"> <?php echo $variation->name; ?> </label> </div> <?php } ?> </div> <?php } ?> </div> <a class="preview button update_variations_action" href='#'><?php _e('Update Variations →', 'wpsc'); ?> </a> </div> <?php $parent_product = $post->ID; $query = array('post_type' => 'wpsc-product', 'orderby' => 'menu_order post_title', 'post_parent' => $parent_product, 'post_status' => 'publish, inherit', 'order' => "ASC"); $args = array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $parent_product, 'orderby' => 'menu_order', 'order' => 'ASC'); $image_data = (array) get_posts($args); $parent_product_data['image'] = array_shift($image_data); $wp_query = new WP_Query($query); if (!isset($parent_product_data)) { $parent_product_data = null; } ?> <p><a name='variation_control'> </a><?php _e('Check or uncheck variation boxes and then click Update Variations to add or remove variations.', 'wpsc'); ?> </p> <table class="widefat page" id='wpsc_product_list' cellspacing="0"> <thead> <tr> <?php print_column_headers('wpsc-product_variants'); ?> </tr> </thead> <tfoot> <tr> <?php print_column_headers('wpsc-product_variants', false); ?> </tr> </tfoot> <tbody> <?php wpsc_admin_product_listing($parent_product_data); if (count($wp_query->posts) < 1) { ?> <tr> <td colspan="8"> <?php _e('You have no Variations added.', 'wpsc'); ?> </td> </tr> <?php } ?> </tbody> </table> <?php } }