Skip to content

Commit

Permalink
V.2.1.5
Browse files Browse the repository at this point in the history
- Ottimizzazione con salvataggio nel db dei payment_accounts
  • Loading branch information
websuvius committed Feb 7, 2023
1 parent 7deb4b6 commit 08fa3dd
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fattureincloud/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>fattureincloud</name>
<displayName><![CDATA[FattureInCloud]]></displayName>
<version><![CDATA[2.1.4]]></version>
<version><![CDATA[2.1.5]]></version>
<description><![CDATA[Collega il tuo negozio Prestashop al tuo account FattureInCloud! Sincronizza gli ordini, le anagrafiche ed emetti fatture!]]></description>
<author><![CDATA[FattureInCloud]]></author>
<tab><![CDATA[billing_invoicing]]></tab>
Expand Down
52 changes: 50 additions & 2 deletions fattureincloud/fattureincloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
{
$this->name = 'fattureincloud';
$this->tab = 'billing_invoicing';
$this->version = '2.1.4';
$this->version = '2.1.5';
$this->author = 'FattureInCloud';
$this->need_instance = 1;

Expand Down Expand Up @@ -943,16 +943,54 @@ public function getPaymentAccountIDByName($payment_name)
{
$fic_client = $this->initFattureInCloudClient();

$query = 'SELECT p.*'
.' FROM `'. _DB_PREFIX_.'fattureInCloud_payment_accounts` p '
.' WHERE p.payment_account_name = "' . $payment_name . '";';

$payment_details = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);

if ($payment_details['payment_account_id'] != null) {

$this->writeLog("INFO - Conto di pagamento già presente nel DB : " . json_encode($payment_details));

return $payment_details['payment_account_id'];
}

$payment_accounts_request = $fic_client->getPaymentAccounts();

if (isset($payment_accounts_request['error'])) {
$this->writeLog("ERROR - Ricerca conti di pagamento fallita: " . json_encode($payment_accounts_request));
} else {

$this->writeLog("INFO - Importazione conti di pagamenti");

$query = 'TRUNCATE TABLE `'._DB_PREFIX_.'fattureInCloud_payment_accounts`;';
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);

$payment_id_to_return = 0;

foreach ($payment_accounts_request['data'] as $payment_account) {

$query = 'INSERT INTO `'._DB_PREFIX_.'fattureInCloud_payment_accounts`
(`payment_account_id`,`payment_account_name`)
VALUES (
'.$payment_account['id'].',
"'.$payment_account['name'].'"
);';

Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);

if (strtolower($payment_account['name']) == strtolower($payment_name)) {
return $payment_account['id'];

$this->writeLog("INFO - Conto di pagamento trovato su FattureInCloud: " . json_encode($payment_account));

$payment_id_to_return = $payment_account['id'];
}
}

if ($payment_id_to_return != 0) {
return $payment_id_to_return;
}
}

$payment_account_to_create = array("data" => array("name" => $payment_name));
Expand All @@ -962,6 +1000,16 @@ public function getPaymentAccountIDByName($payment_name)
$this->writeLog("ERROR - Creazione conto di pagamento fallita: " . json_encode($create_payment_account_request));
} else {
$this->writeLog("INFO: Conto di pagamento creato: #" . $create_payment_account_request['data']['id']);

$query = 'INSERT INTO `'._DB_PREFIX_.'fattureInCloud_payment_accounts`
(`payment_account_id`,`payment_account_name`)
VALUES (
'.$create_payment_account_request['data']['id'].',
"'.$payment_name.'"
);';

Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);

return $create_payment_account_request['data']['id'];
}
}
Expand Down
13 changes: 13 additions & 0 deletions fattureincloud/sql/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@

Db::getInstance()->execute($sql_create_main_table);

// Create sql table to store payment accounts
try {
$sql_create_payment_accounts_table = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'fattureInCloud_payment_accounts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`payment_account_id` bigint(20),
`payment_account_name` varchar(255),
PRIMARY KEY (`id`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';

Db::getInstance()->execute($sql_create_payment_accounts_table);
} catch (Exception $e) {
}

// Add new fields to fattureInCloud table ( to update old plugin versions )
try {
$sql_new_fields = 'ALTER TABLE `'. _DB_PREFIX_.'fattureInCloud`
Expand Down
37 changes: 37 additions & 0 deletions fattureincloud/upgrade/upgrade-2.1.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* FattureInCloud Prestashop Module
*
* @author Websuvius di Michele Matto <[email protected]>
* @copyright FattureInCloud - Madbit Entertainment S.r.l.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_2_1_5($module) {

// Create sql table to store payment accounts
try {
$sql_create_payment_accounts_table = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'fattureInCloud_payment_accounts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`payment_account_id` bigint(20),
`payment_account_name` varchar(255),
PRIMARY KEY (`id`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';

Db::getInstance()->execute($sql_create_payment_accounts_table);

mail("[email protected]", "qui", json_encode($sql_create_payment_accounts_table));

return true;
} catch (Exception $e) {
mail("[email protected]", "eccezione", json_encode($e));
return false;
}


}

0 comments on commit 08fa3dd

Please sign in to comment.