Skip to content

Commit

Permalink
Merge pull request #25 from pagantis/INT-653
Browse files Browse the repository at this point in the history
Int 653
  • Loading branch information
pgarcess authored Sep 11, 2019
2 parents f604f3f + 577167d commit 51997ef
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
53 changes: 35 additions & 18 deletions WC_Pagantis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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' => '<p>Finance this product <span class="pmt-no-interest">without interest!</span></p>'
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' => '<p>Finance this product <span class="pmt-no-interest">without interest!</span></p>',
'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR' => '.',
'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR' => ','
);

/** @var Array $extraConfig */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion controllers/paymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 23 additions & 8 deletions templates/product_simulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ function findPriceSelector()

}

function findPositionSelector()
{
var positionSelector = '<?php echo $positionSelector;?>';
if (positionSelector === 'default') {
positionSelector = '.pagantisSimulator';
}

return positionSelector;
}

function findQuantitySelector()
{
var quantitySelectors = <?php echo json_encode($quantitySelector);?>;
Expand All @@ -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;
Expand Down Expand Up @@ -60,11 +71,7 @@ function loadSimulatorPagantis()
var sdk = pgSDK;
}

var positionSelector = '<?php echo $positionSelector;?>';
if (positionSelector === 'default') {
positionSelector = '.pagantisSimulator';
}

var positionSelector = findPositionSelector();
var priceSelector = findPriceSelector();
var promotedProduct = '<?php echo $promoted;?>';
var quantitySelector = findQuantitySelector();
Expand All @@ -75,14 +82,22 @@ function loadSimulatorPagantis()
selector: positionSelector,
itemQuantitySelector: quantitySelector,
locale: locale,
itemAmountSelector: priceSelector
itemAmountSelector: priceSelector,
amountParserConfig : {
thousandSeparator: '<?php echo $thousandSeparator;?>',
decimalSeparator: '<?php echo $decimalSeparator;?>'
},
numInstalments : '<?php echo $pagantisQuotesStart;?>',
skin : <?php echo $pagantisSimulatorSkin;?>,
position: <?php echo $pagantisSimulatorPosition;?>
};

if (promotedProduct == 'true') {
simulator_options.itemPromotedAmountSelector = priceSelector;
}

if (typeof sdk != 'undefined') {
console.log(window.WCSimulatorId);
window.WCSimulatorId = sdk.simulator.init(simulator_options);
return false;
}
Expand Down

0 comments on commit 51997ef

Please sign in to comment.