本文整理汇总了PHP中wpsc_convert_weight函数的典型用法代码示例。如果您正苦于以下问题:PHP wpsc_convert_weight函数的具体用法?PHP wpsc_convert_weight怎么用?PHP wpsc_convert_weight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpsc_convert_weight函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
|
请发表评论