当前位置: 首页>>代码示例>>PHP>>正文


PHP wpsc_convert_weight函数代码示例

本文整理汇总了PHP中wpsc_convert_weight函数的典型用法代码示例。如果您正苦于以下问题:PHP wpsc_convert_weight函数的具体用法?PHP wpsc_convert_weight怎么用?PHP wpsc_convert_weight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wpsc_convert_weight函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save_variation_meta

 private function save_variation_meta($id, $data)
 {
     $product_meta = get_product_meta($id, 'product_metadata', true);
     if (!is_array($product_meta)) {
         $product_meta = array();
     }
     $product_meta = $this->merge_meta_deep($product_meta, $data['product_metadata']);
     // convert to pound to maintain backward compat with shipping modules
     if (isset($data['product_metadata']['weight']) || isset($data['product_metadata']['weight_unit'])) {
         $product_meta['weight'] = wpsc_convert_weight($product_meta['weight'], $product_meta['weight_unit'], 'pound', true);
     }
     update_product_meta($id, 'product_metadata', $product_meta);
     if (isset($data['price'])) {
         update_product_meta($id, 'price', wpsc_string_to_float($data['price']));
     }
     if (isset($data['sale_price'])) {
         $sale_price = wpsc_string_to_float($data['sale_price']);
         if (is_numeric($sale_price)) {
             update_product_meta($id, 'special_price', wpsc_string_to_float($data['sale_price']));
         } else {
             update_product_meta($id, 'special_price', '');
         }
     }
     if (isset($data['sku'])) {
         update_product_meta($id, 'sku', $data['sku']);
     }
     if (isset($data['stock'])) {
         if (is_numeric($data['stock'])) {
             update_product_meta($id, 'stock', (int) $data['stock']);
         } else {
             update_product_meta($id, 'stock', '');
         }
     }
 }
开发者ID:dreamteam111,项目名称:dreamteam,代码行数:34,代码来源:product-variations-page.class.php

示例2: wpsc_the_product_weight

 function wpsc_the_product_weight($product_id = null)
 {
     global $wp_query;
     if (!$product_id) {
         $product_id = $wp_query->post->ID;
     }
     $product_data = get_post_meta($product_id, '_wpsc_product_metadata', true);
     $weight = $product_data['weight'];
     $weight_unit = $product_data['weight_unit'];
     if ($weight && $weight_unit) {
         $output = wpsc_convert_weight($weight, 'pound', $weight_unit);
         switch ($weight_unit) {
             case 'pound':
                 $weight_unit = __(' lbs.', 'wpsc');
                 break;
             case 'ounce':
                 $weight_unit = __(' oz.', 'wpsc');
                 break;
             case 'gram':
                 $weight_unit = __(' g', 'wpsc');
                 break;
             case 'kilograms':
             case 'kilogram':
                 $weight_unit = __(' kgs.', 'wpsc');
                 break;
         }
         $output .= ' ' . $weight_unit;
         echo $output;
     }
 }
开发者ID:Kilbourne,项目名称:restart,代码行数:30,代码来源:template.php

示例3: _wpsc_manage_products_column_weight

/**
 * Weight column in Manage Products page
 *
 * @since 3.8.9
 * @access private
 *
 * @param  object  $post    Post object
 * @param  int     $post_id Post ID
 * @param  boolean $has_variations Whether the product has variations
 *
 * @uses esc_html_e()                Safe HTML with translation
 * @uses get_post_meta()             Gets post meta given key and post_id
 * @uses maybe_unserialize()         Unserialize value only if it was serialized.
 * @uses wpsc_convert_weight()       Does weight conversions
 * @uses esc_html()                  Makes sure things are safe
 * @uses wpsc_weight_unit_display()  Gets weight unit for display
 */
function _wpsc_manage_products_column_weight($post, $post_id, $has_variations)
{
    if ($has_variations) {
        esc_html_e('N/A', 'wpsc');
        return;
    }
    $product_data = array();
    $product_data['meta'] = array();
    $product_data['meta'] = get_post_meta($post->ID, '');
    foreach ($product_data['meta'] as $meta_name => $meta_value) {
        $product_data['meta'][$meta_name] = maybe_unserialize(array_pop($meta_value));
    }
    $product_data['transformed'] = array();
    if (!isset($product_data['meta']['_wpsc_product_metadata']['weight'])) {
        $product_data['meta']['_wpsc_product_metadata']['weight'] = "";
    }
    if (!isset($product_data['meta']['_wpsc_product_metadata']['weight_unit'])) {
        $product_data['meta']['_wpsc_product_metadata']['weight_unit'] = "";
    }
    $product_data['transformed']['weight'] = wpsc_convert_weight($product_data['meta']['_wpsc_product_metadata']['weight'], "pound", $product_data['meta']['_wpsc_product_metadata']['weight_unit']);
    $weight = $product_data['transformed']['weight'];
    if ($weight == '') {
        $weight = '0';
    }
    $unit = $product_data['meta']['_wpsc_product_metadata']['weight_unit'];
    echo $weight . wpsc_weight_unit_display($unit);
    echo '<div id="inline_' . $post->ID . '_weight" class="hidden">' . esc_html($weight) . '</div>';
}
开发者ID:dreamteam111,项目名称:dreamteam,代码行数:45,代码来源:display-items.page.php

示例4: wpsc_convert_weights

function wpsc_convert_weights($weight, $unit)
{
    _wpsc_deprecated_function(__FUNCTION__, '3.8', 'wpsc_convert_weight');
    if (is_array($weight)) {
        $weight = $weight['weight'];
    }
    return wpsc_convert_weight($weight, $unit, 'gram', true);
}
开发者ID:AngryBird3,项目名称:WP-e-Commerce,代码行数:8,代码来源:wpsc-deprecated.php

示例5: wpsc_sanitise_product_forms

/**
* wpsc_sanitise_product_forms function
*
* @return array - Sanitised product details
*/
function wpsc_sanitise_product_forms($post_data = null)
{
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    $post_data['name'] = isset($post_data['post_title']) ? $post_data['post_title'] : '';
    $post_data['title'] = $post_data['name'];
    $post_data['description'] = isset($post_data['content']) ? $post_data['content'] : '';
    $post_data['additional_description'] = isset($post_data['additional_description']) ? $post_data['additional_description'] : '';
    $post_data['post_status'] = 'draft';
    if (isset($post_data['publish'])) {
        $post_data['post_status'] = 'publish';
    } else {
        if (isset($post_data['unpublish'])) {
            $post_data['post_status'] = 'draft';
        }
    }
    $post_data['meta']['_wpsc_price'] = (double) str_replace(',', '', $post_data['meta']['_wpsc_price']);
    $post_data['meta']['_wpsc_special_price'] = (double) str_replace(',', '', $post_data['meta']['_wpsc_special_price']);
    $post_data['meta']['_wpsc_sku'] = $post_data['meta']['_wpsc_sku'];
    if (!isset($post_data['meta']['_wpsc_is_donation'])) {
        $post_data['meta']['_wpsc_is_donation'] = '';
    }
    $post_data['meta']['_wpsc_is_donation'] = (int) (bool) $post_data['meta']['_wpsc_is_donation'];
    $post_data['meta']['_wpsc_stock'] = (int) $post_data['meta']['_wpsc_stock'];
    if (!isset($post_data['meta']['_wpsc_limited_stock'])) {
        $post_data['meta']['_wpsc_limited_stock'] = '';
    }
    if ((bool) $post_data['meta']['_wpsc_limited_stock'] != true) {
        $post_data['meta']['_wpsc_stock'] = false;
    }
    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'];
    $post_data['files'] = $_FILES;
    return $post_data;
}
开发者ID:nikitanaumov,项目名称:WP-e-Commerce,代码行数:66,代码来源:product-functions.php

示例6: getQuote

 function getQuote()
 {
     global $wpdb, $wpsc_cart;
     if ($this->base_country != 'FR' || strlen($this->base_zipcode) != 5 || !count($wpsc_cart->cart_items)) {
         return;
     }
     $dest = $_SESSION['wpsc_delivery_country'];
     $destzipcode = '';
     if (isset($_POST['zipcode'])) {
         $destzipcode = $_POST['zipcode'];
         $_SESSION['wpsc_zipcode'] = $_POST['zipcode'];
     } else {
         if (isset($_SESSION['wpsc_zipcode'])) {
             $destzipcode = $_SESSION['wpsc_zipcode'];
         }
     }
     //echo '*****'.$dest;
     if ($dest == 'FR' && strlen($destzipcode) != 5) {
         return array();
     }
     /*
     3 possible scenarios:
     1. Cart consists of only item(s) that have "disregard shipping" ticked.
     In this case, WPEC doesn't mention shipping at all during checkout, and this shipping module probably won't be executed at all.
     Just in case it does get queried, we should still override the quoted price(s) to $0.00 so the customer is able to get free shipping.
     2. Cart consists of only item(s) where "disregard shipping" isn't ticked (ie. all item(s) attract shipping charges).
     In this case, we should query the quote as per normal.
     3. Cart consists of one or more "disregard shipping" product(s), and one or more other products that attract shipping charges.
     In this case, we should query the quote, only taking into account the product(s) that attract shipping charges.
     Products with "disregard shipping" ticked shouldn't have their weight or dimensions included in the quote.
     */
     // Weight is in grams
     $weight = wpsc_convert_weight($wpsc_cart->calculate_total_weight(true), 'pound', 'gram');
     // Calculate the total cart dimensions by adding the volume of each product then calculating the cubed root
     $volume = 0;
     // Total number of item(s) in the cart
     $numItems = count($wpsc_cart->cart_items);
     if ($numItems == 0) {
         // The customer's cart is empty. This probably shouldn't occur, but just in case!
         return array();
     }
     // Total number of item(s) that don't attract shipping charges.
     $numItemsWithDisregardShippingTicked = 0;
     foreach ($wpsc_cart->cart_items as $cart_item) {
         if (!$cart_item->uses_shipping) {
             // The "Disregard Shipping for this product" option is ticked for this item.
             // Don't include it in the shipping quote.
             $numItemsWithDisregardShippingTicked++;
             continue;
         }
         // If we are here then this item attracts shipping charges.
         $meta = get_product_meta($cart_item->product_id, 'product_metadata', true);
         $meta = $meta['dimensions'];
         if ($meta && is_array($meta)) {
             $productVolume = 1;
             foreach (array('width', 'height', 'length') as $dimension) {
                 // Cubi square of the dimension to get the volume of the box it will be squared later
                 switch ($meta["{$dimension}_unit"]) {
                     // we need the units in mm
                     case 'cm':
                         // convert from cm to mm
                         $productVolume = $productVolume * (floatval($meta[$dimension]) * 10);
                         break;
                     case 'meter':
                         // convert from m to mm
                         $productVolume = $productVolume * (floatval($meta[$dimension]) * 1000);
                         break;
                     case 'in':
                         // convert from in to mm
                         $productVolume = $productVolume * (floatval($meta[$dimension]) * 25.4);
                         break;
                 }
             }
             $volume += floatval($productVolume);
         }
     }
     // Calculate the cubic root of the total volume, rounding up
     $cuberoot = ceil(pow($volume, 1 / 3));
     // Use default dimensions of 100mm if the volume is zero
     $height = 100;
     // Mettre dans les options, todo
     $width = 100;
     $length = 100;
     if ($cuberoot > 0) {
         $height = $width = $length = $cuberoot;
     }
     if ($length < 100) {
         $length = 100;
     }
     if ($width < 100) {
         $width = 100;
     }
     $shippingPriceNeedsToBeZero = false;
     if ($numItemsWithDisregardShippingTicked == $numItems) {
         // The cart consists of entirely "disregard shipping" products, so the shipping quote(s) should be $0.00
         // Set the weight to 1 gram so that we can obtain valid Australia Post quotes (which we will then ignore the quoted price of)
         $weight = 1;
         $shippingPriceNeedsToBeZero = true;
     }
     //API :
//.........这里部分代码省略.........
开发者ID:Reghyz,项目名称:wpcb,代码行数:101,代码来源:livraison.php

示例7: wpsc_ajax_ie_save

/**
 * wpsc_ajax_ie_save save changes made using inline edit
 *
 * @public
 *
 * @3.8
 * @returns nothing
 */
function wpsc_ajax_ie_save()
{
    $product_post_type = get_post_type_object('wpsc-product');
    if (!current_user_can($product_post_type->cap->edit_posts)) {
        echo '({"error":"' . __('Error: you don\'t have required permissions to edit this product', 'wpsc') . '", "id": "' . $_POST['id'] . '"})';
        die;
    }
    $product = array('ID' => $_POST['id'], 'post_title' => $_POST['title']);
    $id = wp_update_post($product);
    if ($id > 0) {
        //need parent meta to know which weight unit we are using
        $post = get_post($id);
        $parent_meta = get_product_meta($post->post_parent, 'product_metadata', true);
        $product_meta = get_product_meta($product['ID'], 'product_metadata', true);
        if (is_numeric($_POST['weight']) || empty($_POST['weight'])) {
            $product_meta['weight'] = wpsc_convert_weight($_POST['weight'], $parent_meta['weight_unit'], 'pound', true);
            $product_meta['weight_unit'] = $parent_meta['weight_unit'];
        }
        update_product_meta($product['ID'], 'product_metadata', $product_meta);
        update_product_meta($product['ID'], 'price', (double) $_POST['price']);
        update_product_meta($product['ID'], 'special_price', (double) $_POST['special_price']);
        update_product_meta($product['ID'], 'sku', $_POST['sku']);
        if (!is_numeric($_POST['stock'])) {
            update_product_meta($product['ID'], 'stock', '');
        } else {
            update_product_meta($product['ID'], 'stock', absint($_POST['stock']));
        }
        $post = get_post($id);
        $meta = get_product_meta($id, 'product_metadata', true);
        $price = get_product_meta($id, 'price', true);
        $special_price = get_product_meta($id, 'special_price', true);
        $sku = get_product_meta($id, 'sku', true);
        $sku = $sku ? $sku : __('N/A', 'wpsc');
        $stock = get_product_meta($id, 'stock', true);
        $stock = $stock === '' ? __('N/A', 'wpsc') : $stock;
        $results = array('id' => $id, 'title' => $post->post_title, 'weight' => wpsc_convert_weight($meta['weight'], 'pound', $parent_meta['weight_unit']), 'price' => wpsc_currency_display($price), 'special_price' => wpsc_currency_display($special_price), 'sku' => $sku, 'stock' => $stock);
        echo '(' . json_encode($results) . ')';
        die;
    } else {
        echo '({"error":"' . __('Error updating product', 'wpsc') . '", "id": "' . $_POST['id'] . '"})';
    }
    die;
}
开发者ID:hornet9,项目名称:Morato,代码行数:51,代码来源:admin.php

示例8: wpsc_convert_variation_combinations


//.........这里部分代码省略.........
                $i++;
                $progress->update($i);
                set_transient('wpsc_update_variation_comb_offset', $i, 604800);
                continue;
            }
            $variation_set_id_sql = "SELECT meta_value FROM " . WPSC_TABLE_META . " WHERE object_type='wpsc_variation_set' AND object_id IN (" . implode(',', $variation_set_associations) . ") AND meta_key = 'variation_set_id'";
            $variation_set_terms = $wpdb->get_col($variation_set_id_sql);
            $variation_associations_sql = "SELECT meta_value FROM " . WPSC_TABLE_META . " WHERE object_type='wpsc_variation' AND object_id IN (" . implode(',', $variation_associations) . ") AND meta_key = 'variation_id'";
            $variation_associations_terms = $wpdb->get_col($variation_associations_sql);
            $base_product_terms = array_merge($base_product_terms, $variation_set_terms, $variation_associations_terms);
            // Now that we have the term IDs, we need to retrieve the slugs, as wp_set_object_terms will not use IDs in the way we want
            // If we pass IDs into wp_set_object_terms, it creates terms using the ID as the name.
            $parent_product_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $base_product_terms), 'orderby' => 'parent'));
            $base_product_term_slugs = array();
            foreach ($parent_product_terms as $parent_product_term) {
                $base_product_term_slugs[] = $parent_product_term->slug;
            }
            wp_set_object_terms($post->ID, $base_product_term_slugs, 'wpsc-variation');
            // select all variation "products"
            $variation_items = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_VARIATION_PROPERTIES . " WHERE `product_id` = '{$original_id}'");
            foreach ((array) $variation_items as $variation_item) {
                $wpsc_update->check_timeout();
                // initialize the requisite arrays to empty
                $variation_ids = array();
                $term_data = array('ids' => array(), 'slugs' => array(), 'names' => array());
                // make a temporary copy of the product teplate
                $product_values = $child_product_template;
                // select all values this "product" is associated with, then loop through them, getting the term id of the variation using the value ID
                $variation_associations_combinations = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_VARIATION_COMBINATIONS . " WHERE `priceandstock_id` = '{$variation_item->id}'");
                foreach ((array) $variation_associations_combinations as $association) {
                    $variation_id = (int) wpsc_get_meta($association->value_id, 'variation_id', 'wpsc_variation');
                    // discard any values that are null, as they break the selecting of the terms
                    if ($variation_id > 0 && in_array($association->value_id, $variation_associations)) {
                        $variation_ids[] = $variation_id;
                    }
                }
                // if we have more than zero remaining terms, get the term data, then loop through it to convert it to a more useful set of arrays.
                if (count($variation_ids) > 0 && count($variation_set_associations) == count($variation_ids)) {
                    $combination_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $variation_ids)));
                    foreach ($combination_terms as $term) {
                        $term_data['ids'][] = $term->term_id;
                        $term_data['slugs'][] = $term->slug;
                        $term_data['names'][] = $term->name;
                    }
                    $product_values['post_title'] .= " (" . implode(", ", $term_data['names']) . ")";
                    $product_values['post_name'] = sanitize_title($product_values['post_title']);
                    $selected_post = get_posts(array('name' => $product_values['post_name'], 'post_parent' => $post->ID, 'post_type' => "wpsc-product", 'post_status' => 'all', 'suppress_filters' => true));
                    $selected_post = array_shift($selected_post);
                    $key = md5($post->ID . ':' . count($term_data['ids']) . ':' . implode(',', $term_data['ids']));
                    $child_product_id = false;
                    if (!empty($child_products[$key])) {
                        $child_product_id = $child_products[$key];
                    }
                    $post_data = array();
                    $post_data['_wpsc_price'] = (double) $variation_item->price;
                    $post_data['_wpsc_stock'] = (double) $variation_item->stock;
                    if (!is_numeric($parent_stock)) {
                        $post_data['_wpsc_stock'] = false;
                    }
                    $post_data['_wpsc_original_variation_id'] = (double) $variation_item->id;
                    // Product Weight
                    $post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($variation_item->weight, $variation_item->weight_unit, "pound", true);
                    $post_data['_wpsc_product_metadata']['display_weight_as'] = $variation_item->weight_unit;
                    $post_data['_wpsc_product_metadata']['weight_unit'] = $variation_item->weight_unit;
                    // Parts of the code (eg wpsc_product_variation_price_from() make the assumption that these meta keys exist
                    $post_data['_wpsc_special_price'] = 0;
                    $post_data['_wpsc_sku'] = '';
                    $already_exists = true;
                    if (!empty($selected_post) && $selected_post->ID != $child_product_id) {
                        $child_product_id = $selected_post->ID;
                    } elseif (empty($child_product_id)) {
                        $child_product_id = wp_insert_post($product_values);
                        $already_exists = false;
                    }
                    if ($child_product_id > 0) {
                        foreach ($post_data as $meta_key => $meta_value) {
                            // prefix all meta keys with _wpsc_
                            update_post_meta($child_product_id, $meta_key, $meta_value);
                        }
                        wp_set_object_terms($child_product_id, $term_data['slugs'], 'wpsc-variation');
                        if (!$already_exists) {
                            $child_products[$key] = $child_product_id;
                            set_transient('wpsc_update_current_child_products', $child_products, 604800);
                        }
                    }
                    unset($term_data);
                }
            }
            $i++;
            $progress->update($i);
            set_transient('wpsc_update_variation_comb_offset', $i, 604800);
            delete_transient('wpsc_update_current_child_products');
        }
        $offset += $limit;
    }
    delete_option("wpsc-variation_children");
    _get_term_hierarchy('wpsc-variation');
    delete_option("wpsc_product_category_children");
    _get_term_hierarchy('wpsc_product_category');
}
开发者ID:ashik968,项目名称:digiplot,代码行数:101,代码来源:updating-functions.php

示例9: wpsc_save_quickedit_box

/**
 * wpsc_save_quickedit_box function
 * Saves input for the various meta in the quick edit boxes
 *
 * @todo UI
 * @todo Data validation / sanitization / security
 * @todo AJAX should probably return weight unit
 * @return $post_id (int) Post ID
 */
function wpsc_save_quickedit_box($post_id)
{
    global $current_screen, $doaction;
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || empty($current_screen) || $current_screen->id != 'edit-wpsc-product') {
        return;
    }
    $bulk = isset($doaction) && $doaction == 'edit';
    $custom_fields = array('weight' => 'product_metadata', 'stock' => 'stock', 'price' => 'price', 'sale_price' => 'special_price', 'sku' => 'sku');
    $args = array('post_parent' => $post_id, 'post_type' => 'wpsc-product', 'post_status' => 'inherit');
    $children = get_children($args);
    $is_parent = (bool) $children;
    foreach ($custom_fields as $post_key => $meta_key) {
        $overideVariant = isset($_REQUEST[$post_key . '_variant']) && $_REQUEST[$post_key . '_variant'] == 'on';
        // don't update if we're bulk updating and the field is left blank, or if the product has children and the field is one of those fields defined below (unles overridden)
        if (!isset($_REQUEST[$post_key]) || $bulk && empty($_REQUEST[$post_key]) || $is_parent && in_array($post_key, array('weight', 'stock', 'price', 'special_price')) && !$overideVariant) {
            continue;
        }
        if ($is_parent && count($children) > 0) {
            $products = $children;
        } else {
            $products = array($post_id);
        }
        foreach ($products as $product) {
            $value = $_REQUEST[$post_key];
            if ($is_parent) {
                $post_id = $product->ID;
            } else {
                $post_id = $product;
            }
            switch ($post_key) {
                case 'weight':
                    $product_meta = get_post_meta($post_id, '_wpsc_product_metadata', true);
                    if (!is_array($product_meta)) {
                        $product_meta = array();
                    }
                    // draft products don't have product metadata set yet
                    $weight_unit = isset($product_meta["weight_unit"]) ? $product_meta["weight_unit"] : 'pound';
                    $weight = wpsc_convert_weight($value, $weight_unit, "pound", true);
                    if (isset($product_meta["weight"])) {
                        unset($product_meta["weight"]);
                    }
                    $product_meta["weight"] = $weight;
                    $value = $product_meta;
                    break;
                case 'stock':
                    if (!is_numeric($value)) {
                        $value = '';
                    }
                    break;
                case 'sku':
                    if ($value == __('N/A', 'wpsc')) {
                        $value = '';
                    }
                    break;
            }
            update_post_meta($post_id, "_wpsc_{$meta_key}", $value);
        }
    }
    return $post_id;
}
开发者ID:pankajsinghjarial,项目名称:SYLC,代码行数:69,代码来源:display-items-functions.php

示例10: getQuote

 function getQuote()
 {
     global $wpdb, $wpsc_cart, $CodeEnseigne, $CodeMarque, $Pays, $ClePrivee;
     $wpcb_livraison_options = get_option('wpcb_livraison');
     if ($this->base_country != 'FR' || strlen($this->base_zipcode) != 5 || !count($wpsc_cart->cart_items)) {
         return;
     }
     $dest = $_SESSION['wpsc_delivery_country'];
     $destzipcode = '';
     if (isset($_POST['zipcode'])) {
         $destzipcode = $_POST['zipcode'];
         $_SESSION['wpsc_zipcode'] = $_POST['zipcode'];
     } else {
         if (isset($_SESSION['wpsc_zipcode'])) {
             $destzipcode = $_SESSION['wpsc_zipcode'];
         }
     }
     if ($dest == 'FR' && strlen($destzipcode) != 5) {
         return array();
     }
     // Weight is in grams
     $weight = wpsc_convert_weight($wpsc_cart->calculate_total_weight(true), 'pound', 'gram');
     // Calculate the total cart dimensions by adding the volume of each product then calculating the cubed root
     $volume = 0;
     // Total number of item(s) in the cart
     $numItems = count($wpsc_cart->cart_items);
     if ($numItems == 0) {
         // The customer's cart is empty. This probably shouldn't occur, but just in case!
         return array();
     }
     // Total number of item(s) that don't attract shipping charges.
     $numItemsWithDisregardShippingTicked = 0;
     foreach ($wpsc_cart->cart_items as $cart_item) {
         if (!$cart_item->uses_shipping) {
             // The "Disregard Shipping for this product" option is ticked for this item.
             // Don't include it in the shipping quote.
             $numItemsWithDisregardShippingTicked++;
             continue;
         }
         // If we are here then this item attracts shipping charges.
         $meta = get_product_meta($cart_item->product_id, 'product_metadata', true);
         $meta = $meta['dimensions'];
         if ($meta && is_array($meta)) {
             $productVolume = 1;
             foreach (array('width', 'height', 'length') as $dimension) {
                 // Cubi square of the dimension to get the volume of the box it will be squared later
                 switch ($meta["{$dimension}_unit"]) {
                     // we need the units in mm
                     case 'cm':
                         // convert from cm to mm
                         $productVolume = $productVolume * (floatval($meta[$dimension]) * 10);
                         break;
                     case 'meter':
                         // convert from m to mm
                         $productVolume = $productVolume * (floatval($meta[$dimension]) * 1000);
                         break;
                     case 'in':
                         // convert from in to mm
                         $productVolume = $productVolume * (floatval($meta[$dimension]) * 25.4);
                         break;
                 }
             }
             $volume += floatval($productVolume);
         }
     }
     // Calculate the cubic root of the total volume, rounding up
     $cuberoot = ceil(pow($volume, 1 / 3));
     // Use default dimensions of 100mm if the volume is zero
     $height = 100;
     // Mettre dans les options, todo
     $width = 100;
     $length = 100;
     if ($cuberoot > 0) {
         $height = $width = $length = $cuberoot;
     }
     if ($length < 100) {
         $length = 100;
     }
     if ($width < 100) {
         $width = 100;
     }
     // todo : calculer la longueur déroulée.
     // todo : forcer la taille par un custom field dans le produit
     $shippingPriceNeedsToBeZero = false;
     if ($numItemsWithDisregardShippingTicked == $numItems) {
         // The cart consists of entirely "disregard shipping" products, so the shipping quote(s) should be $0.00
         // Set the weight to 1 gram so that we can obtain valid Australia Post quotes (which we will then ignore the quoted price of)
         $weight = 1;
         $shippingPriceNeedsToBeZero = true;
     }
     $params = array('Pickup_Postcode' => $this->base_zipcode, 'Destination_Postcode' => $destzipcode, 'Quantity' => 1, 'Weight' => $weight, 'Height' => $height, 'Width' => $width, 'Length' => $length, 'Country' => $dest);
     // Tableaux des destinations COLIS :
     $dest_colis_fr = array('FR');
     // to do ajouter les tableaux pour les autres pays
     // Param API
     if ($wpcb_livraison_options['mr_ComptePro']) {
         $ComptePro = true;
         $CodeEnseigne = $wpcb_livraison_options['mr_CodeEnseigne'];
         //'BDTESTMR';
         $ClePrivee = $wpcb_livraison_options['mr_ClePrivee'];
//.........这里部分代码省略.........
开发者ID:Reghyz,项目名称:wpcb,代码行数:101,代码来源:mondialrelay.php

示例11: wpsc_save_quickedit_box

/**
 * wpsc_save_quickedit_box function
 * Saves input for the various meta in the quick edit boxes
 *
 * @todo UI
 * @todo Data validation / sanitization / security
 * @todo AJAX should probably return weight unit
 * @return $post_id (int) Post ID
 */
function wpsc_save_quickedit_box($post_id)
{
    global $current_screen;
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || empty($current_screen) || $current_screen->id != 'edit-wpsc-product' || !defined('DOING_AJAX') || !DOING_AJAX) {
        return;
    }
    $is_parent = (bool) wpsc_product_has_children($post_id);
    $product_meta = get_post_meta($post_id, '_wpsc_product_metadata', true);
    $weight_unit = $product_meta["weight_unit"];
    $weight = wpsc_convert_weight($_POST["weight"], $weight_unit, "pound", true);
    if (isset($product_meta["weight"])) {
        unset($product_meta["weight"]);
    }
    $product_meta["weight"] = $weight;
    if (!$is_parent) {
        update_post_meta($post_id, '_wpsc_product_metadata', $product_meta);
        if (is_numeric($_POST['stock'])) {
            update_post_meta($post_id, '_wpsc_stock', $_POST['stock']);
        } else {
            update_post_meta($post_id, '_wpsc_stock', '');
        }
        update_post_meta($post_id, '_wpsc_price', $_POST['price']);
        update_post_meta($post_id, '_wpsc_special_price', $_POST['sale_price']);
    }
    if ($_POST['sku'] == __('N/A', 'wpsc')) {
        update_post_meta($post_id, '_wpsc_sku', '');
    } else {
        update_post_meta($post_id, '_wpsc_sku', $_POST['sku']);
    }
    return $post_id;
}
开发者ID:nikitanaumov,项目名称:WP-e-Commerce,代码行数:40,代码来源:display-items-functions.php

示例12: wpsc_convert_variation_combinations

function wpsc_convert_variation_combinations()
{
    global $wpdb, $user_ID, $current_version_number;
    // get the posts
    // I use a direct SQL query here because the get_posts function sometimes does not function for a reason that is not clear.
    $posts = $wpdb->get_results("SELECT * FROM `{$wpdb->posts}` WHERE `post_type` IN('wpsc-product')");
    $posts = get_posts(array('post_type' => 'wpsc-product', 'post_status' => 'all', 'numberposts' => -1));
    foreach ((array) $posts as $post) {
        $base_product_terms = array();
        //create a post template
        $child_product_template = array('post_author' => $user_ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_title' => $post->post_title, 'post_status' => 'inherit', 'post_type' => "wpsc-product", 'post_name' => sanitize_title($post->post_title), 'post_parent' => $post->ID);
        // select the original product ID
        $original_id = get_post_meta($post->ID, '_wpsc_original_id', true);
        $parent_stock = get_post_meta($post->ID, '_wpsc_stock', true);
        // select the variation set associations
        $variation_set_associations = $wpdb->get_col("SELECT `variation_id` FROM " . WPSC_TABLE_VARIATION_ASSOC . " WHERE `associated_id` = '{$original_id}'");
        // select the variation associations if the count of variation sets is greater than zero
        if ($original_id > 0 && count($variation_set_associations) > 0) {
            $variation_associations = $wpdb->get_col("SELECT `value_id` FROM " . WPSC_TABLE_VARIATION_VALUES_ASSOC . " WHERE `product_id` = '{$original_id}' AND `variation_id` IN(" . implode(", ", $variation_set_associations) . ") AND `visible` IN ('1')");
        } else {
            // otherwise, we have no active variations, skip to the next product
            continue;
        }
        foreach ($variation_set_associations as $variation_set_id) {
            $base_product_terms[] = wpsc_get_meta($variation_set_id, 'variation_set_id', 'wpsc_variation_set');
        }
        foreach ($variation_associations as $variation_association_id) {
            $base_product_terms[] = wpsc_get_meta($variation_association_id, 'variation_id', 'wpsc_variation');
        }
        // Now that we have the term IDs, we need to retrieve the slugs, as wp_set_object_terms will not use IDs in the way we want
        // If we pass IDs into wp_set_object_terms, it creates terms using the ID as the name.
        $parent_product_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $base_product_terms), 'orderby' => 'parent'));
        $base_product_term_slugs = array();
        foreach ($parent_product_terms as $parent_product_term) {
            $base_product_term_slugs[] = $parent_product_term->slug;
        }
        wp_set_object_terms($post->ID, $base_product_term_slugs, 'wpsc-variation');
        // select all variation "products"
        $variation_items = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_VARIATION_PROPERTIES . " WHERE `product_id` = '{$original_id}'");
        foreach ((array) $variation_items as $variation_item) {
            // initialize the requisite arrays to empty
            $variation_ids = array();
            $term_data = array();
            // make a temporary copy of the product teplate
            $product_values = $child_product_template;
            // select all values this "product" is associated with, then loop through them, getting the term id of the variation using the value ID
            $variation_associations_combinations = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_VARIATION_COMBINATIONS . " WHERE `priceandstock_id` = '{$variation_item->id}'");
            foreach ((array) $variation_associations_combinations as $association) {
                $variation_id = (int) wpsc_get_meta($association->value_id, 'variation_id', 'wpsc_variation');
                // discard any values that are null, as they break the selecting of the terms
                if ($variation_id > 0 && in_array($association->value_id, $variation_associations)) {
                    $variation_ids[] = $variation_id;
                }
            }
            // if we have more than zero remaining terms, get the term data, then loop through it to convert it to a more useful set of arrays.
            if (count($variation_ids) > 0 && count($variation_set_associations) == count($variation_ids)) {
                $combination_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $variation_ids), 'orderby' => 'parent'));
                foreach ($combination_terms as $term) {
                    $term_data['ids'][] = $term->term_id;
                    $term_data['slugs'][] = $term->slug;
                    $term_data['names'][] = $term->name;
                }
                $product_values['post_title'] .= " (" . implode(", ", $term_data['names']) . ")";
                $product_values['post_name'] = sanitize_title($product_values['post_title']);
                $selected_post = get_posts(array('name' => $product_values['post_name'], 'post_parent' => $post->ID, 'post_type' => "wpsc-product", 'post_status' => 'all', 'suppress_filters' => true));
                $selected_post = array_shift($selected_post);
                $child_product_id = wpsc_get_child_object_in_terms($post->ID, $term_data['ids'], 'wpsc-variation');
                $post_data = array();
                $post_data['_wpsc_price'] = (double) $variation_item->price;
                $post_data['_wpsc_stock'] = (double) $variation_item->stock;
                if (!is_numeric($parent_stock)) {
                    $post_data['_wpsc_stock'] = false;
                }
                $post_data['_wpsc_original_variation_id'] = (double) $variation_item->id;
                // Product Weight
                $post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($variation_item->weight, $variation_item->weight_unit, "pound", true);
                $post_data['_wpsc_product_metadata']['display_weight_as'] = $variation_item->weight_unit;
                $post_data['_wpsc_product_metadata']['weight_unit'] = $variation_item->weight_unit;
                //file
                if ($child_product_id == false) {
                    if ($selected_post != null) {
                        $child_product_id = $selected_post->ID;
                    } else {
                        $child_product_id = wp_update_post($product_values);
                    }
                } else {
                    // sometimes there have been problems saving the variations, this gets the correct product ID
                    if ($selected_post != null && $selected_post->ID != $child_product_id) {
                        $child_product_id = $selected_post->ID;
                    }
                }
                if ($child_product_id > 0) {
                    foreach ($post_data as $meta_key => $meta_value) {
                        // prefix all meta keys with _wpsc_
                        update_post_meta($child_product_id, $meta_key, $meta_value);
                    }
                    wp_set_object_terms($child_product_id, $term_data['slugs'], 'wpsc-variation');
                }
                unset($term_data);
            }
//.........这里部分代码省略.........
开发者ID:hornet9,项目名称:Morato,代码行数:101,代码来源:updating-functions.php

示例13: wpsc_sanitise_product_forms

/**
* wpsc_sanitise_product_forms function 
* 
* @return array - Sanitised product details
*/
function wpsc_sanitise_product_forms($post_data = null)
{
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    $product = get_post(absint($post_data['post_ID']));
    $post_data['name'] = isset($post_data['post_title']) ? $post_data['post_title'] : '';
    $post_data['title'] = $post_data['name'];
    $post_data['description'] = isset($post_data['content']) ? $post_data['content'] : '';
    $post_data['additional_description'] = isset($post_data['additional_description']) ? $post_data['additional_description'] : '';
    if ($product != null) {
        $post_data['post_status'] = $product->post_status;
    } else {
        $post_data['post_status'] = 'draft';
    }
    if (isset($post_data['save']) && $product->post_status == 'inherit' && ($product->post_parent == 0 || $product->post_parent == $product->ID)) {
        $post_data['post_status'] = 'draft';
    } else {
        if (isset($post_data['publish'])) {
            $post_data['post_status'] = 'publish';
        } else {
            if (isset($post_data['unpublish'])) {
                $post_data['post_status'] = 'draft';
            }
        }
    }
    $post_meta['meta'] = (array) $_POST['meta'];
    $post_data['meta']['_wpsc_price'] = (double) str_replace(',', '', $post_data['meta']['_wpsc_price']);
    $post_data['meta']['_wpsc_special_price'] = (double) str_replace(',', '', $post_data['meta']['_wpsc_special_price']);
    $post_data['meta']['_wpsc_sku'] = $post_data['meta']['_wpsc_sku'];
    if (!isset($post_data['meta']['_wpsc_is_donation'])) {
        $post_data['meta']['_wpsc_is_donation'] = '';
    }
    $post_data['meta']['_wpsc_is_donation'] = (int) (bool) $post_data['meta']['_wpsc_is_donation'];
    $post_data['meta']['_wpsc_stock'] = (int) $post_data['meta']['_wpsc_stock'];
    if (!isset($post_data['meta']['_wpsc_limited_stock'])) {
        $post_data['meta']['_wpsc_limited_stock'] = '';
    }
    if ((bool) $post_data['meta']['_wpsc_limited_stock'] != true) {
        $post_data['meta']['_wpsc_stock'] = false;
    }
    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'] = $post_data['table_rate_price'];
    // if table_rate_price is unticked, wipe the table rate prices
    if (!isset($post_data['table_rate_price']['state'])) {
        $post_data['table_rate_price']['state'] = '';
    }
    if ($post_data['table_rate_price']['state'] != 1) {
        $post_data['meta']['_wpsc_product_metadata']['table_rate_price']['quantity'] = null;
        $post_data['meta']['_wpsc_product_metadata']['table_rate_price']['table_price'] = null;
    }
    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']['external_link'] = (string) $post_data['meta']['_wpsc_product_metadata']['external_link'];
    $post_data['meta']['_wpsc_product_metadata']['external_link_text'] = (string) $post_data['meta']['_wpsc_product_metadata']['external_link_text'];
//.........这里部分代码省略.........
开发者ID:hornet9,项目名称:Morato,代码行数:101,代码来源:product-functions.php

示例14: update_record_metadata

function update_record_metadata($update_column, &$wpsc_product_metadata, $params, $action_name)
{
    foreach ($wpsc_product_metadata as $key => $value) {
        switch ($update_column) {
            case 'weight':
                if (isset($params['unit']) && !empty($params['unit'])) {
                    $wpsc_product_metadata[$key]['weight_unit'] = $params['unit'];
                }
                $wpsc_product_metadata[$key]['display_weight_as'] = $params['unit'];
                eval('$wpsc_product_metadata[$key][weight] = perform_action($action_name,$wpsc_product_metadata[$key][weight], $params);');
                // insert the product weight in pound unit since wp-e-commerce does the same.
                $wpsc_product_metadata[$key][weight] = wpsc_convert_weight($wpsc_product_metadata[$key][weight], $wpsc_product_metadata[$key]['weight_unit'], "pound", true);
                break;
            case 'height':
                if (isset($params['unit']) && !empty($params['unit'])) {
                    $wpsc_product_metadata[$key]['dimensions']['height_unit'] = $params['unit'];
                }
                eval('$wpsc_product_metadata[$key][dimensions][height] = perform_action($action_name,$wpsc_product_metadata[$key][dimensions][height], $params);');
                break;
            case 'width':
                if (isset($params['unit']) && !empty($params['unit'])) {
                    $wpsc_product_metadata[$key]['dimensions']['width_unit'] = $params['unit'];
                }
                eval('$wpsc_product_metadata[$key][dimensions][width] = perform_action($action_name,$wpsc_product_metadata[$key][dimensions][width], $params);');
                break;
            case 'length':
                if (isset($params['unit']) && !empty($params['unit'])) {
                    $wpsc_product_metadata[$key]['dimensions']['length_unit'] = $params['unit'];
                }
                eval('$wpsc_product_metadata[$key][dimensions][length] = perform_action($action_name,$wpsc_product_metadata[$key][dimensions][length], $params);');
                break;
            case 'local':
                eval('$wpsc_product_metadata[$key][shipping][local] = perform_action($action_name,$wpsc_product_metadata[$key][shipping][local], $params);');
                break;
            case 'international':
                eval('$wpsc_product_metadata[$key][shipping][international] = perform_action($action_name,$wpsc_product_metadata[$key][shipping][international], $params);');
                break;
            case 'no_shipping':
                eval('$wpsc_product_metadata[$key][no_shipping] = perform_action($action_name,$wpsc_product_metadata[$key][no_shipping], $params);');
                break;
            case 'quantity_limited':
                eval('$wpsc_product_metadata[$key][quantity_limited] = perform_action($action_name,$wpsc_product_metadata[$key][quantity_limited], $params);');
                break;
            case 'unpublish_when_none_left':
                eval('$wpsc_product_metadata[$key][unpublish_when_none_left] = perform_action($action_name,$wpsc_product_metadata[$key][unpublish_when_none_left], $params);');
                break;
        }
    }
}
开发者ID:bulats,项目名称:chef,代码行数:49,代码来源:sm38.php

示例15: data_for_insert_update

function data_for_insert_update($post)
{
    global $result, $wpdb, $user_ID;
    require_once WP_PLUGIN_DIR . '/wp-e-commerce/wpsc-admin/includes/product-functions.php';
    $_POST = $post;
    // Fix: PHP 5.4
    $selected_object = json_decode($_POST['selected']);
    $edited_object = json_decode($_POST['edited']);
    $objectArray = array();
    if (is_array($edited_object)) {
        foreach ($edited_object as $obj) {
            array_push($objectArray, $obj);
        }
    }
    if (is_array($selected_object)) {
        foreach ($selected_object as $obj) {
            if (!in_array($obj, $objectArray)) {
                array_push($objectArray, $obj);
            }
        }
    }
    $insertCnt = 1;
    $updateCnt = 1;
    $result['updated'] = 0;
    $result['inserted'] = 0;
    $result['productId'] = array();
    if (is_array($objectArray)) {
        foreach ($objectArray as $obj) {
            if (isset($obj->id) && $obj->id != '') {
                $post = get_post($obj->id);
            }
            // Default $post Array used only to INSERT new post & get postId which will be used as productId.
            // FOR wp_insert_post FUNCTION
            $post = array('ID' => $obj->id, 'menu_order' => isset($post->menu_order) ? $post->menu_order : 0, 'comment_status' => isset($post->comment_status) ? $post->comment_status : 'closed', 'ping_status' => isset($post->ping_status) ? $post->ping_status : 'closed', 'pinged' => isset($post->pinged) ? $post->pinged : '', 'post_author' => isset($post->post_author) ? $post->post_author : $user_ID, 'post_category' => '', 'post_content' => $obj->post_content, 'post_date' => isset($post->post_date) ? $post->post_date : '', 'post_date_gmt' => isset($post->post_date_gmt) ? $post->post_date_gmt : '', 'post_excerpt' => $obj->post_excerpt, 'post_name' => isset($post->post_name) ? $post->post_name : '', 'post_parent' => $obj->post_parent, 'post_password' => isset($post->post_password) ? $post->post_password : '', 'post_title' => $obj->post_title, 'post_status' => $obj->post_status, 'post_type' => 'wpsc-product', 'to_ping' => isset($post->to_ping) ? $post->to_ping : '', 'post_content_filtered' => isset($post->post_content_filtered) ? $post->post_content_filtered : '');
            //Default $data Array
            //FOR wpsc_pre_update FUNCTION & FOR wpsc_admin_submit_product FUNCTION
            $data = array('post_author' => $user_ID, 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => gmdate('Y-m-d H:i:s'), 'post_content' => $obj->post_content, 'post_title' => $obj->post_title, 'post_excerpt' => $obj->post_excerpt, 'post_status' => $obj->post_status, 'post_type' => 'wpsc-product', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_password' => '', 'post_name' => '', 'to_ping' => '', 'pinged' => '', 'post_modified' => date('Y-m-d H:i:s'), 'post_modified_gmt' => gmdate('Y-m-d H:i:s'), 'post_parent' => $obj->post_parent, 'menu_order' => 0, 'guid' => '', 'post_content_filtered' => '');
            // 'tax_input' 	   => Array (
            // 												'product_tag' 			=> 1, 						  // product_tag
            // 												'wpsc_product_category' => Array (0 => $obj->category ), // product category
            // 												'wpsc-variation' 		=> Array (0 => 0 ) 			  // product variation
            // 											),
            //FOR wpsc_pre_update FUNCTION & FOR wpsc_admin_submit_product FUNCTION
            //(not passed as an argument but used in the function)
            $wpsc_product_metadeta = array('wpec_taxes_taxable_amount' => '', 'external_link' => '', 'external_link_text' => '', 'external_link_target' => '', 'weight' => $obj->weight, 'weight_unit' => $obj->weight_unit, 'display_weight_as' => $obj->weight_unit, 'dimensions' => array('height' => $obj->height, 'height_unit' => $obj->height_unit, 'width' => $obj->width, 'width_unit' => $obj->width_unit, 'length' => $obj->length, 'length_unit' => $obj->length_unit), 'shipping' => array('local' => $obj->local, 'international' => $obj->international), 'no_shipping' => $obj->no_shipping, 'merchant_notes' => '', 'engraved' => 0, 'can_have_uploaded_image' => 0, 'enable_comments' => '');
            if (!empty($_POST['isWPSC3814']) && $_POST['isWPSC3814'] == '1') {
                $wpsc_product_metadeta['dimensions'] = array('height' => $obj->height, 'width' => $obj->width, 'length' => $obj->length);
                $wpsc_product_metadeta['dimension_unit'] = $obj->dimension_unit;
            } else {
                $wpsc_product_metadeta['dimensions'] = array('height' => $obj->height, 'height_unit' => $obj->height_unit, 'width' => $obj->width, 'width_unit' => $obj->width_unit, 'length' => $obj->length, 'length_unit' => $obj->length_unit);
            }
            $_POST = array('original_publish' => $obj->post_status, 'publish' => $obj->post_status, 'meta' => array('_wpsc_price' => $obj->_wpsc_price, '_wpsc_special_price' => $obj->_wpsc_special_price, '_wpsc_sku' => $obj->_wpsc_sku, '_wpsc_stock' => $obj->_wpsc_stock, '_wpsc_product_metadata' => $wpsc_product_metadeta), 'table_rate_price' => array('quantity' => array(0 => ''), 'table_price' => array(0 => '')), 'ID' => '', 'product_id' => '', 'post_title' => $obj->post_title, 'content' => $obj->post_content, 'additional_description' => $obj->post_excerpt);
            if ($obj->id == '') {
                $result['inserted'] = 1;
                $product_id = wp_insert_post($post);
                $guid = site_url() . '/?post_type=wpsc-product&p=' . $product_id;
                $data['guid'] = $guid;
                $_POST['product_id'] = $product_id;
                $_POST['ID'] = $product_id;
                $data_value = wpsc_pre_update($data, $_POST);
                $inserted_product_id = wpsc_admin_submit_product($product_id, $data);
                $product_meta = $_POST['meta'];
                if ($product_meta != null) {
                    foreach ((array) $product_meta as $key => $value) {
                        $bool = update_post_meta($inserted_product_id, $key, $value, $prev_value = '');
                        if ($bool == true) {
                            $success = true;
                        }
                    }
                }
                if (isset($inserted_product_id) && $inserted_product_id != 0 || $success == true) {
                    $result['result'] = true;
                }
                array_push($result['productId'], $inserted_product_id);
                if ($result['result']) {
                    $result['insertCnt'] = $insertCnt++;
                }
            } else {
                if (in_array($obj, $edited_object)) {
                    $result['updated'] = 1;
                    // setting a flag to check on whether updated or inserted.
                    //this will update the current product since we are already
                    //passing the id while forming the $post array
                    $product_id = wp_insert_post($post);
                    $_POST['product_id'] = $product_id;
                    $_POST['ID'] = $product_id;
                    // insert the product weight in pound unit since wp-e-commerce does the same.
                    $_POST['meta']['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($_POST['meta']['_wpsc_product_metadata']['weight'], $_POST['meta']['_wpsc_product_metadata']['weight_unit'], "pound", true);
                    // get the actual array of post meta from the database and overwrite it with the new values
                    // so that the keys of the array will be maintained and will get the proper serialized value.
                    // helpful files: processing.functions.php, display-items.page.php, display-items-functions.php
                    $product_meta_values = get_post_meta($product_id, '_wpsc_product_metadata', true);
                    $_POST['meta']['_wpsc_product_metadata'] = array_merge((array) $product_meta_values, $_POST['meta']['_wpsc_product_metadata']);
                    $product_meta = $_POST['meta'];
                    if ($product_meta != null) {
                        foreach ((array) $product_meta as $key => $value) {
                            $bool = update_post_meta($product_id, $key, $value, $prev_value = '');
                            if ($bool == true) {
                                $success = true;
                            }
//.........这里部分代码省略.........
开发者ID:JaneJieYing,项目名称:kiddoonline_dvlpment,代码行数:101,代码来源:json38.php


注:本文中的wpsc_convert_weight函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。