Plugin Directory

Changeset 1707995


Ignore:
Timestamp:
08/03/2017 06:00:52 PM (9 years ago)
Author:
hyyan
Message:

Deploy version 1.0.3

Location:
woo-poly-integration
Files:
86 added
5 edited

Legend:

Unmodified
Added
Removed
  • woo-poly-integration/trunk/CHANGELOG.md

    r1705116 r1707995  
     1# Changelog
     2
     3### 1.0.3
     4
     5* Fix PHP Fatal error: Class 'NumberFormatter' not found
     6
    17### 1.0.2
    28* Fixes #200 Polylang version check fails to detect Polylang PRO
  • woo-poly-integration/trunk/__init__.php

    r1705116 r1707995  
    1111 * GitHub Plugin URI: hyyan/woo-poly-integration
    1212 * License: MIT License
    13  * Version: 1.0.2
     13 * Version: 1.0.3
    1414 */
    1515
  • woo-poly-integration/trunk/readme.txt

    r1705116 r1707995  
    44Requires at least: 3.8
    55Tested up to: 4.8
    6 Stable tag: 1.0.2
     6Stable tag: 1.0.3
    77License: MIT
    88License URI: https://github.com/hyyan/woo-poly-integration/blob/master/LICENSE
     
    121121
    122122== Changelog ==
     123
     124== 1.0.3 ==
     125* Fix PHP Fatal error: Class 'NumberFormatter' not found
     126
    123127
    124128== 1.0.2 ==
  • woo-poly-integration/trunk/src/Hyyan/WPI/LocaleNumbers.php

    r1705116 r1707995  
    11<?php
     2
    23/**
    34 * LocaleNumbers.
     
    56 * @author Jonathan Moore <jonathan.moore@bcs.org>
    67 */
     8
    79namespace Hyyan\WPI;
    810
    9 class LocaleNumbers
    10 {
     11use Hyyan\WPI\Admin\Settings;
     12use Hyyan\WPI\Admin\Features;
     13
     14class LocaleNumbers {
    1115
    1216    /**
    1317     * Hook relevant WooCommerce filters to apply localisation according to Polylang locale.
    1418     */
    15     public function __construct()
    16     {
    17         //localise standard price formatting arguments
    18         add_filter('wc_get_price_decimal_separator', array($this, 'getLocaleDecimalSeparator'), 10, 1);
    19         add_filter('wc_get_price_thousand_separator', array($this, 'getLocaleThousandSeparator'), 10, 1);
    20         add_filter('wc_price_args', array($this, 'filterPriceArgs'), 10, 1);
     19    public function __construct() {
    2120
    22         //WooCommerce 3.1 unreleased checkin https://github.com/woocommerce/woocommerce/pull/15628
    23         add_filter('woocommerce_format_localized_decimal', array($this, 'getLocalizedDecimal'), 10, 2);
    24         //no additional override on finished price format as no currency paramber available
    25         //add_filter('woocommerce_format_localized_price', array($this, 'getLocalizedPrice'), 10, 2);
     21        if (
     22                class_exists('\NumberFormatter') &&
     23                'on' === Settings::getOption('localenumbers', Features::getID(), 'on')
     24        ) {
     25
     26            //localise standard price formatting arguments
     27            add_filter('wc_get_price_decimal_separator', array($this, 'getLocaleDecimalSeparator'), 10, 1);
     28            add_filter('wc_get_price_thousand_separator', array($this, 'getLocaleThousandSeparator'), 10, 1);
     29            add_filter('wc_price_args', array($this, 'filterPriceArgs'), 10, 1);
     30
     31            //WooCommerce 3.1 unreleased checkin https://github.com/woocommerce/woocommerce/pull/15628
     32            add_filter('woocommerce_format_localized_decimal', array($this, 'getLocalizedDecimal'), 10, 2);
     33            //no additional override on finished price format as no currency paramber available
     34            //add_filter('woocommerce_format_localized_price', array($this, 'getLocalizedPrice'), 10, 2);
     35        }
    2636    }
    27 
    2837
    2938    /*
     
    3544     *      'currency'           => '',
    3645     *      'decimal_separator'  => wc_get_price_decimal_separator(),
    37        *      'thousand_separator' => wc_get_price_thousand_separator(),
    38        *      'decimals'           => wc_get_price_decimals(),
    39        *      'price_format'       => get_woocommerce_price_format(),
     46     *      'thousand_separator' => wc_get_price_thousand_separator(),
     47     *      'decimals'           => wc_get_price_decimals(),
     48     *      'price_format'       => get_woocommerce_price_format(),
    4049     *
    4150     * @return Array the arguments
    4251     */
    43     public function filterPriceArgs($args)
    44     {
    45        
     52
     53    public function filterPriceArgs($args) {
     54
    4655        //if there is a currency provided, attempt a full reset of formatting parameters
    47         if ((isset($args['currency'])) && ($args['currency']!='')) {
     56        if ((isset($args['currency'])) && ($args['currency'] != '')) {
    4857            $currency = $args['currency'];
    4958            $locale = pll_current_language('locale');
    50             $formatter = new \NumberFormatter($locale.'@currency='.$currency, \NumberFormatter::CURRENCY);
     59            $formatter = new \NumberFormatter($locale . '@currency=' . $currency, \NumberFormatter::CURRENCY);
    5160            $args['decimal_separator'] = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
    5261            $args['thousand_separator'] = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
    5362            $args['decimals'] = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
    54             $prefix=$formatter->getTextAttribute(\NumberFormatter::POSITIVE_PREFIX);
     63            $prefix = $formatter->getTextAttribute(\NumberFormatter::POSITIVE_PREFIX);
    5564            if (strlen($prefix)) {
    5665                $args['price_format'] = '%1$s%2$s';
     
    6574        return $args;
    6675    }
    67    
     76
    6877    /*
    6978     * get localized getLocalizedDecimal
     
    7483     * @return string  formatted number
    7584     */
    76     public function getLocalizedDecimal($wooFormattedValue, $input)
    77     {
     85
     86    public function getLocalizedDecimal($wooFormattedValue, $input) {
    7887        //default to return unmodified wooCommerce value
    7988        $retval = $wooFormattedValue;
    80        
     89
    8190        //don't touch values on admin screens, save as plain number using woo defaults
    82         if ((! is_admin()) || isset($_REQUEST['get_product_price_by_ajax'])) {
     91        if ((!is_admin()) || isset($_REQUEST['get_product_price_by_ajax'])) {
    8392            $a = new \NumberFormatter(pll_current_language('locale'), \NumberFormatter::DECIMAL);
    8493            if ($a) {
     
    8897        return $retval;
    8998    }
    90    
    9199
    92100    /*
     
    97105     * @return string  formatted number
    98106     */
    99     public function getLocaleDecimalSeparator($separator)
    100     {
     107
     108    public function getLocaleDecimalSeparator($separator) {
    101109        $retval = $separator;
    102110        //don't touch values on admin screens, save as plain number using woo defaults
    103         if ((! is_admin()) || isset($_REQUEST['get_product_price_by_ajax'])) {
     111        if ((!is_admin()) || isset($_REQUEST['get_product_price_by_ajax'])) {
    104112            $locale = pll_current_language('locale');
    105113            $a = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
     
    113121        return $retval;
    114122    }
    115  
     123
    116124    /*
    117125     * get localized thousand separator
     
    121129     * @return string  formatted number
    122130     */
    123     public function getLocaleThousandSeparator($separator)
    124     {
     131
     132    public function getLocaleThousandSeparator($separator) {
    125133        $retval = $separator;
    126134        //don't touch values on admin screens, save as plain number using woo defaults
    127         if (! is_admin()) {
     135        if (!is_admin()) {
    128136            $a = new \NumberFormatter(pll_current_language('locale'), \NumberFormatter::DECIMAL);
    129137            if ($a) {
     
    133141        return $retval;
    134142    }
     143
    135144}
  • woo-poly-integration/trunk/src/Hyyan/WPI/Plugin.php

    r1705116 r1707995  
    1212
    1313use Hyyan\WPI\Tools\FlashMessages;
    14 use Hyyan\WPI\Admin\Settings;
    15 use Hyyan\WPI\Admin\Features;
    1614
    1715/**
     
    193191        new Breadcrumb();
    194192        new Tax();
    195        
    196         if ('on' === Settings::getOption('localenumbers', Features::getID(), 'on')) {
    197             new LocaleNumbers();
    198         }
     193        new LocaleNumbers();
    199194    }
    200195
Note: See TracChangeset for help on using the changeset viewer.