diff --git a/WC_Pagantis.php b/WC_Pagantis.php index 7f1f665..47d4880 100644 --- a/WC_Pagantis.php +++ b/WC_Pagantis.php @@ -3,7 +3,7 @@ * Plugin Name: Pagantis * Plugin URI: http://www.pagantis.com/ * Description: Financiar con Pagantis - * Version: 8.2.1 + * Version: 8.2.2 * Author: Pagantis */ @@ -32,22 +32,25 @@ class WcPagantis /** Config tablename */ const ORDERS_TABLE = 'posts'; - public $defaultConfigs = array('PAGANTIS_TITLE'=>'Instant Financing', - 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pgSDK.simulator.types.SIMPLE', - 'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pgSDK.simulator.skins.BLUE', - 'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', - 'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3, - 'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12, - 'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', - 'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pgSDK.simulator.positions.INNER', - 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'a:3:{i:0;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:1;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:2;s:36:"*:not(del)>.woocommerce-Price-amount";}', - 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}', - 'PAGANTIS_FORM_DISPLAY_TYPE'=>0, - 'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1, - 'PAGANTIS_URL_OK'=>'', - 'PAGANTIS_URL_KO'=>'', - 'PAGANTIS_ALLOWED_COUNTRIES' => 'a:2:{i:0;s:2:"es";i:1;s:2:"it";}', - 'PAGANTIS_PROMOTION_EXTRA' => '
Finance this product without interest!
' + public $defaultConfigs = array( + 'PAGANTIS_TITLE'=>'Instant Financing', + 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'sdk.simulator.types.SIMPLE', + 'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'sdk.simulator.skins.BLUE', + 'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', + 'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3, + 'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12, + 'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', + 'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'sdk.simulator.positions.INNER', + 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'a:3:{i:0;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:1;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:2;s:36:"*:not(del)>.woocommerce-Price-amount";}', + 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}', + 'PAGANTIS_FORM_DISPLAY_TYPE'=>0, + 'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1, + 'PAGANTIS_URL_OK'=>'', + 'PAGANTIS_URL_KO'=>'', + 'PAGANTIS_ALLOWED_COUNTRIES' => 'a:2:{i:0;s:2:"es";i:1;s:2:"it";}', + 'PAGANTIS_PROMOTION_EXTRA' => 'Finance this product without interest!
', + 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR' => '.', + 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR' => ',' ); /** @var Array $extraConfig */ @@ -226,6 +229,15 @@ public function pagantisActivation() } } + //Adapting selector to array < v8.2.2 + $tableName = $wpdb->prefix.self::CONFIG_TABLE; + $query = "select * from $tableName where config='PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'"; + $results = $wpdb->get_results($query, ARRAY_A); + if (count($results) == 0) { + $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR', 'value' => '.'), array('%s', '%s')); + $wpdb->insert($tableName, array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR', 'value' => ','), array('%s', '%s')); + } + $dbConfigs = $wpdb->get_results("select * from $tableName", ARRAY_A); // Convert a multimple dimension array for SQL insert statements into a simple key/value @@ -284,7 +296,12 @@ public function pagantisAddProductSimulator() 'totalAmount' => is_numeric($product->price) ? $product->price : 0, 'locale' => $locale, 'promoted' => $this->isPromoted($post_id), - 'promotedMessage' => $this->extraConfig['PAGANTIS_PROMOTION_EXTRA'] + 'promotedMessage' => $this->extraConfig['PAGANTIS_PROMOTION_EXTRA'], + 'thousandSeparator' => $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'], + 'decimalSeparator' => $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'], + 'pagantisQuotesStart' => $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'], + 'pagantisSimulatorSkin' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'], + 'pagantisSimulatorPosition' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] ); wc_get_template('product_simulator.php', $template_fields, '', $this->template_path); } diff --git a/controllers/paymentController.php b/controllers/paymentController.php index 8ee0c8e..5ecc41e 100755 --- a/controllers/paymentController.php +++ b/controllers/paymentController.php @@ -494,7 +494,9 @@ public function payment_fields() 'locale' => $locale, 'allowedCountry' => $allowedCountry, 'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'], - 'promoted_amount' => $promotedAmount + 'promoted_amount' => $promotedAmount, + 'thousandSeparator' => $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'], + 'decimalSeparator' => $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'] ); wc_get_template('checkout_description.php', $template_fields, '', $this->template_path); } diff --git a/templates/product_simulator.php b/templates/product_simulator.php index 067b438..d4dd73e 100644 --- a/templates/product_simulator.php +++ b/templates/product_simulator.php @@ -9,6 +9,16 @@ function findPriceSelector() } + function findPositionSelector() + { + var positionSelector = ''; + if (positionSelector === 'default') { + positionSelector = '.pagantisSimulator'; + } + + return positionSelector; + } + function findQuantitySelector() { var quantitySelectors = ; @@ -23,8 +33,9 @@ function finishInterval() { } function checkSimulatorContent() { var simulatorLoaded = false; - var pmtDiv = document.getElementsByClassName("pagantisSimulator"); - if (pmtDiv.length > 0) { + var positionSelector = findPositionSelector(); + var pmtDiv = document.querySelectorAll(positionSelector); + if (pmtDiv.length > 0 && typeof window.WCSimulatorId!='undefined') { var pmtElement = pmtDiv[0]; if (pmtElement.innerHTML != '') { simulatorLoaded = true; @@ -60,11 +71,7 @@ function loadSimulatorPagantis() var sdk = pgSDK; } - var positionSelector = ''; - if (positionSelector === 'default') { - positionSelector = '.pagantisSimulator'; - } - + var positionSelector = findPositionSelector(); var priceSelector = findPriceSelector(); var promotedProduct = ''; var quantitySelector = findQuantitySelector(); @@ -75,7 +82,14 @@ function loadSimulatorPagantis() selector: positionSelector, itemQuantitySelector: quantitySelector, locale: locale, - itemAmountSelector: priceSelector + itemAmountSelector: priceSelector, + amountParserConfig : { + thousandSeparator: '', + decimalSeparator: '' + }, + numInstalments : '', + skin : , + position: }; if (promotedProduct == 'true') { @@ -83,6 +97,7 @@ function loadSimulatorPagantis() } if (typeof sdk != 'undefined') { + console.log(window.WCSimulatorId); window.WCSimulatorId = sdk.simulator.init(simulator_options); return false; }