コード例 #1
0
ファイル: common.php プロジェクト: ashik968/digiplot
/**
 * Format a price amount.
 *
 * The available options that you can specify in the $args argument include:
 *     'display_currency_symbol' - Whether to attach the currency symbol to the figure.
 *                                 Defaults to true.
 *     'display_decimal_point'   - Whether to display the decimal point.
 *                                 Defaults to true.
 *     'display_currency_code'   - Whether to attach the currency code to the figure.
 *                                 Defaults to fault.
 *     'isocode'                 - Specify the isocode of the base country that you want to use for
 *                                 this price.
 *                                 Defaults to the settings in Settings->Store->General.
 *
 * @since 4.0
 * @uses  apply_filters() Applies 'wpsc_format_currency'                     filter
 * @uses  apply_filters() Applies 'wpsc_format_currency_currency_code'       filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_currency_symbol'     filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_decimal_separator'   filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_thousands_separator' filter.
 * @uses  apply_filters() Applies 'wpsc_modify_decimals' filter.
 * @uses  get_option()    Gets the value of 'currency_sign_location' in Settings->Store->General.
 * @uses  get_option()    Gets the value of 'currency_type' in Settings->Store->General.
 * @uses  WPSC_Country::__construct()
 * @uses  WPSC_Country::get()
 * @uses  wp_parse_args()
 *
 * @param  float|int|string $amt  The price you want to format.
 * @param  string|array     $args A query string or array containing the options. Defaults to ''.
 * @return string                 The formatted price.
 */
function wpsc_format_currency($amt, $args = '')
{
    $defaults = array('display_currency_symbol' => true, 'display_decimal_point' => true, 'display_currency_code' => false, 'isocode' => false, 'currency_code' => false);
    $args = wp_parse_args($args);
    // Either display symbol or code, not both
    if (array_key_exists('display_currency_symbol', $args)) {
        $args['display_currency_code'] = !$args['display_currency_symbol'];
    } elseif (array_key_exists('display_currency_code', $args)) {
        $args['display_currency_symbol'] = !$args['display_currency_code'];
    }
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $currencies_without_fractions = WPSC_Payment_Gateways::currencies_without_fractions();
    if ($isocode) {
        $currency = new WPSC_Country($isocode);
    } else {
        $currency = new WPSC_Country(get_option('currency_type'));
    }
    $currency_code = $currency->get_currency_code();
    // No decimal point, no decimals
    if (!$display_decimal_point || in_array($currency_code, $currencies_without_fractions)) {
        $decimals = 0;
    } else {
        $decimals = 2;
        // default is 2
    }
    $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode);
    $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode);
    $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode);
    // Format the price for output
    $formatted = number_format($amt, $decimals, $decimal_separator, $thousands_separator);
    if (!$display_currency_code) {
        $currency_code = '';
    }
    $symbol = $display_currency_symbol ? $currency->get_currency_symbol() : '';
    $symbol = esc_html($symbol);
    $symbol = apply_filters('wpsc_format_currency_currency_symbol', $symbol, $isocode);
    $currency_sign_location = get_option('currency_sign_location');
    // Rejig the currency sign location
    switch ($currency_sign_location) {
        case 1:
            $format_string = '%3$s%1$s%2$s';
            break;
        case 2:
            $format_string = '%3$s %1$s%2$s';
            break;
        case 4:
            $format_string = '%1$s%2$s  %3$s';
            break;
        case 3:
        default:
            $format_string = '%1$s %2$s%3$s';
            break;
    }
    $currency_code = apply_filters('wpsc_format_currency_currency_code', $currency_code, $isocode);
    // Compile the output
    $output = trim(sprintf($format_string, $currency_code, $symbol, $formatted));
    return $output;
}
コード例 #2
0
 function test_get_currency_code()
 {
     $country = new WPSC_Country(self::COUNTRY_ID_WITHOUT_REGIONS);
     $currency_code = $country->get_currency_code();
     $this->assertEquals(self::COUNTRY_NAME_WITHOUT_REGIONS_CURRENCY_CODE, $currency_code);
 }
コード例 #3
0
 private function get_shipping_method_js_vars()
 {
     global $wpsc_cart;
     $js_var = array('subtotal' => (double) $wpsc_cart->calculate_subtotal(), 'shipping' => array(), 'tax' => wpsc_is_tax_enabled() && !wpsc_is_tax_included() ? (double) wpsc_cart_tax(false) : 0, 'discount' => wpsc_coupon_amount(false) > 0 ? wpsc_coupon_amount(false) : 0);
     foreach ($this->shipping_calculator->sorted_quotes as $module_name => $quotes) {
         foreach ($quotes as $option => $cost) {
             $id = $this->shipping_calculator->ids[$module_name][$option];
             $js_var['shipping'][$id] = $cost;
         }
     }
     $currency = new WPSC_Country(get_option('currency_type'));
     $currency_code = $currency->get_currency_code();
     $isocode = $currency->get_isocode();
     $without_fractions = in_array($currency_code, WPSC_Payment_Gateways::currencies_without_fractions());
     $decimals = $without_fractions ? 0 : 2;
     $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode);
     $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode);
     $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode);
     $symbol = apply_filters('wpsc_format_currency_currency_symbol', $currency->get_currency_symbol());
     $sign_location = get_option('currency_sign_location');
     $js_var['formatter'] = array('currency_code' => $currency_code, 'without_fractions' => $without_fractions, 'decimals' => $decimals, 'decimal_separator' => $decimal_separator, 'thousands_separator' => $thousands_separator, 'symbol' => $symbol, 'sign_location' => $sign_location);
     return $js_var;
 }
コード例 #4
0
ファイル: product.php プロジェクト: RJHanson292/WP-e-Commerce
/**
 * Template tag for base country currency code.
 *
 * Helpful for templates using structured data, likely other use cases.
 * Temporarily located here, until #1865 lands.
 *
 * @since  4.0
 *
 * @return  string Base country currency code.
 */
function wpsc_base_country_code()
{
    $base = new WPSC_Country(wpsc_get_base_country());
    echo esc_attr($base->get_currency_code());
}
コード例 #5
0
function wpsc_price_control_forms()
{
    global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
    $product_data = get_post_custom($post->ID);
    $product_data['meta'] = maybe_unserialize($product_data);
    foreach ($product_data['meta'] as $meta_key => $meta_value) {
        $product_data['meta'][$meta_key] = $meta_value[0];
    }
    $product_meta = array();
    if (!empty($product_data['_wpsc_product_metadata'])) {
        $product_meta = maybe_unserialize($product_data['_wpsc_product_metadata'][0]);
    }
    if (isset($product_data['meta']['_wpsc_currency'])) {
        $product_alt_currency = maybe_unserialize($product_data['meta']['_wpsc_currency']);
    }
    if (!isset($product_data['meta']['_wpsc_table_rate_price'])) {
        $product_data['meta']['_wpsc_table_rate_price'] = $wpsc_product_defaults['meta']['table_rate_price'];
    }
    if (isset($product_meta['_wpsc_table_rate_price'])) {
        $product_meta['table_rate_price']['state'] = 1;
        $product_meta['table_rate_price'] += $product_meta['_wpsc_table_rate_price'];
        $product_data['meta']['_wpsc_table_rate_price'] = $product_meta['_wpsc_table_rate_price'];
    }
    if (!isset($product_data['meta']['_wpsc_is_donation'])) {
        $product_data['meta']['_wpsc_is_donation'] = $wpsc_product_defaults['donation'];
    }
    if (!isset($product_meta['table_rate_price']['state'])) {
        $product_meta['table_rate_price']['state'] = null;
    }
    if (!isset($product_meta['table_rate_price']['quantity'])) {
        $product_meta['table_rate_price']['quantity'] = $wpsc_product_defaults['meta']['table_rate_price']['quantity'][0];
    }
    if (!isset($product_data['meta']['_wpsc_price'])) {
        $product_data['meta']['_wpsc_price'] = $wpsc_product_defaults['price'];
    }
    if (!isset($product_data['special'])) {
        $product_data['special'] = $wpsc_product_defaults['special'];
    }
    if (!isset($product_data['meta']['_wpsc_special_price'])) {
        $product_data['meta']['_wpsc_special_price'] = $wpsc_product_defaults['special_price'];
    }
    $product_data['meta']['_wpsc_special_price'] = wpsc_format_number($product_data['meta']['_wpsc_special_price']);
    if (!isset($product_data['meta']['_wpsc_price'])) {
        $product_data['meta']['_wpsc_price'] = 0;
    }
    $product_data['meta']['_wpsc_price'] = wpsc_format_number($product_data['meta']['_wpsc_price']);
    $currency_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A);
    /* Get country name and symbol */
    $currency_type = get_option('currency_type');
    $country = new WPSC_Country($currency_type);
    $ct_code = $country->get_currency_code();
    // Country currency code
    $ct_symb = $country->get_currency_symbol();
    // Country symbol
    $price = $product_data['meta']['_wpsc_price'];
    $sale_price = $product_data['meta']['_wpsc_special_price'];
    $wp_38 = version_compare($GLOBALS['wp_version'], '3.8', '>=');
    $currency_delete_class = $wp_38 ? ' dashicons dashicons-dismiss' : '';
    $currency_delete_text = $wp_38 ? '' : 'x';
    ?>
		<em id="wpsc_product_price_metabox_live_title" class="wpsc_metabox_live_title">
			<p>&nbsp;<?php 
    echo esc_html($ct_symb);
    ?>
<span><?php 
    echo esc_html($sale_price);
    ?>
</span></p>
			<del><?php 
    echo esc_html($ct_symb);
    ?>
<span><?php 
    echo esc_html($price);
    ?>
</span></del>
		</em>
		<input type="hidden" id="parent_post" name="parent_post" value="<?php 
    echo $post->post_parent;
    ?>
" />
		<?php 
    /* Lots of tedious work is avoided with this little line. */
    ?>
		<input type="hidden" id="product_id" name="product_id" value="<?php 
    echo $post->ID;
    ?>
" />

		<?php 
    /* Check product if a product has variations */
    ?>
		<?php 
    if (wpsc_product_has_children($post->ID)) {
        ?>
			<?php 
        $price = wpsc_product_variation_price_from($post->ID);
        ?>
			<p style="margin-top: 6px;"><?php 
        echo sprintf(__('This product has variations. To edit the price, please use the <a href="%s">Variation Controls</a>.', 'wp-e-commerce'), '#wpsc_product_variation_forms');
        ?>
</p>
			<p><?php 
        printf(__('Price: %s and above.', 'wp-e-commerce'), $price);
        ?>
</p>
		<?php 
    } else {
        ?>

		<div class='wpsc_floatleft' style="width:100px;">
			<label for="wpsc_price"><?php 
        _e('Price', 'wp-e-commerce');
        ?>
</label>
			<?php 
        echo esc_html($ct_symb);
        ?>
 <input id="wpsc_price"
					type="text"
					style="width: 70px;"
					name="meta[_wpsc_price]"
					value="<?php 
        echo esc_attr($price);
        ?>
" />
		</div>

		<div class='wpsc_floatleft' style='width:95px; margin-left:30px;'>
			<label for='wpsc_sale_price'><?php 
        _e('Sale Price', 'wp-e-commerce');
        ?>
</label>
			<?php 
        echo esc_html($ct_symb);
        ?>
 <input id = "wpsc_sale_price"
					type="text"
					style="width: 70px;"
					value="<?php 
        echo esc_attr($sale_price);
        ?>
"
					name='meta[_wpsc_special_price]' />
		</div>

		<div class="wpsc-currency-layers">
			<table>
				<thead>
					<tr>
						<th class="type" colspan="2"><?php 
        esc_html_e('Alternative Currencies:', 'wp-e-commerce');
        ?>
</th>
						<th class="price"><?php 
        esc_html_e('Price:', 'wp-e-commerce');
        ?>
</th>
					<tr>
				</thead>
				<tbody>
					<?php 
        if (isset($product_alt_currency) && is_array($product_alt_currency)) {
            $i = 0;
            foreach ($product_alt_currency as $iso => $alt_price) {
                $i++;
                ?>
							<tr class="wpsc_additional_currency">
								<td class="remove"><a href="#" class="wpsc_delete_currency_layer<?php 
                echo $currency_delete_class;
                ?>
" rel="<?php 
                echo $iso;
                ?>
"><?php 
                echo $currency_delete_text;
                ?>
</a></td>
								<td>
									<select name="newCurrency[]" class="newCurrency">
										<?php 
                foreach ($currency_data as $currency) {
                    ?>
											<option value="<?php 
                    echo absint($currency['id']);
                    ?>
" <?php 
                    selected($iso, $currency['isocode']);
                    ?>
>
												<?php 
                    echo esc_html($currency['country']);
                    ?>
 (<?php 
                    echo esc_html($currency['currency']);
                    ?>
)
											</option>
										<?php 
                }
                ?>
									</select>
								</td>
								<td><input class="newCurrPrice text" size="8" name="newCurrPrice[]" value="<?php 
                echo esc_attr($alt_price);
                ?>
" /></td>
							</tr>
							<?php 
            }
        }
        ?>
					<tr id="wpsc_currency_row_template" class="template hidden">
						<td class="remove"><a href="#" class="wpsc_delete_currency_layer<?php 
        echo $currency_delete_class;
        ?>
"><?php 
        echo $currency_delete_text;
        ?>
</a></td>
						<td>
							<select name="newCurrency[]" class="newCurrency">
								<?php 
        foreach ((array) $currency_data as $currency) {
            ?>
									<option value="<?php 
            echo absint($currency['id']);
            ?>
">
										<?php 
            echo esc_html($currency['country']);
            ?>
									</option>
								<?php 
        }
        ?>
							</select>
						</td>
						<td><input class="newCurrPrice text" size="8" name="newCurrPrice[]" value="0.00" /></td>
					</tr>
				</tbody>
			</table>
			<a href="#wpsc_currency_row_template" class="button button-small wpsc_add_new_currency"><?php 
        esc_html_e('Add a Currency Option', 'wp-e-commerce');
        ?>
</a>
			<?php 
        wp_nonce_field('update-options', 'wpsc-update-currency-layers', false);
        ?>
		</div>

		<div class="wpsc-quantity-discounts">
			<table>
				<thead>
					<tr>
						<th class="qty" colspan="2"><?php 
        esc_html_e('Quantity:', 'wp-e-commerce');
        ?>
</th>
						<th class="curr"><span class="hidden"><?php 
        esc_html_e('Currency:', 'wp-e-commerce');
        ?>
<span></th>
						<th class="price"><?php 
        esc_html_e('Price:', 'wp-e-commerce');
        ?>
</th>
					</tr>
				</thead>
				<tbody>
					<?php 
        if (count($product_meta['table_rate_price']['quantity']) > 0) {
            foreach ((array) $product_meta['table_rate_price']['quantity'] as $key => $quantity) {
                if ($quantity != '') {
                    $table_price = number_format($product_meta['table_rate_price']['table_price'][$key], 2, '.', '');
                    ?>
								<tr>
									<td class="remove"><a href="#" class="remove_line<?php 
                    echo $currency_delete_class;
                    ?>
"><?php 
                    echo $currency_delete_text;
                    ?>
</a></td>
									<td class="qty">
										<input type="text" size="5" value="<?php 
                    echo absint($quantity);
                    ?>
" name="table_rate_price[quantity][]" />
										<?php 
                    esc_html_e('+', 'wp-e-commerce');
                    ?>
									</td>
									<td class="curr"><?php 
                    echo $ct_code . ' ' . $ct_symb;
                    ?>
</td>
									<td><input class="newCurrPrice text" value="<?php 
                    echo $table_price;
                    ?>
" name="table_rate_price[table_price][]" /></td>
								</tr>
								<?php 
                }
            }
        }
        ?>
					<tr id="wpsc_quantity_discount_row_template" class="template hidden">
						<td class="remove"><a href="#" class="remove_line<?php 
        echo $currency_delete_class;
        ?>
"><?php 
        echo $currency_delete_text;
        ?>
</a></td>
						<td class="qty">
							<input size="5" value="0" name="table_rate_price[quantity][]" />
							<?php 
        esc_html_e('+', 'wp-e-commerce');
        ?>
						</td>
						<td class="curr"><?php 
        echo $ct_code . ' ' . $ct_symb;
        ?>
</td>
						<td><input size="10"class="newCurrPrice text" value="0" name="table_rate_price[table_price][]" /></td>
					</tr>
				</tbody>
			</table>
			<a href="#wpsc_quantity_discount_row_template" class="add_level button button-small"><?php 
        esc_html_e('Add a Quantity Discount', 'wp-e-commerce');
        ?>
</a>
			<?php 
        wp_nonce_field('update-options', 'wpsc-update-quantity-discounts', false);
        ?>
		</div>

		<input id="add_form_donation" type="checkbox" name="meta[_wpsc_is_donation]" value="yes" <?php 
        checked($product_data['meta']['_wpsc_is_donation'], 1);
        ?>
 />
		<label for="add_form_donation"><?php 
        _e('Purchase is a donation.', 'wp-e-commerce');
        ?>
</label>
		<?php 
        wp_nonce_field('update', 'wpsc_product_pricing_nonce');
        ?>

<?php 
    }
}