From eaaa5feff8e83e3cdad80f7606c5e1a743082976 Mon Sep 17 00:00:00 2001 From: Davod Saraei Date: Wed, 15 Feb 2023 14:49:49 +0330 Subject: [PATCH] rm accountId --- affili.php | 199 ++++++++++++++---------------------- config.xml | 4 +- views/templates/snippet.tpl | 3 +- 3 files changed, 78 insertions(+), 128 deletions(-) diff --git a/affili.php b/affili.php index 13cf7b0..a61dd4e 100644 --- a/affili.php +++ b/affili.php @@ -1,18 +1,17 @@ name = 'affili'; - $this->tab = 'advertising_marketing'; - $this->version = '1.0.0'; - $this->author = 'Affili'; + public function __construct() + { + $this->name = 'affili'; + $this->tab = 'advertising_marketing'; + $this->version = '1.0.0'; + $this->author = 'Affili'; $this->need_instance = 1; - $this->is_configurable = 1; $this->ps_versions_compliancy = [ 'min' => '1.6', @@ -20,120 +19,72 @@ public function __construct() ]; $this->bootstrap = true; - parent::__construct(); - - $this->displayName = $this->l('Affili'); - $this->description = $this->l('Integrate the Affili tracking script in your shop'); - - $this->confirmUninstall = $this->l('Are you sure you want to delete Affili from your shop?'); - - if ($this->id && !Configuration::get('ACCOUNT_ID')) { - $this->warning = $this->l('You have not yet set your Affili Account ID'); - } - } - - public function install() - { - return (parent::install() && $this->registerHook('displayHeader') && $this->registerHook('displayOrderConfirmation')); - } - - public function uninstall() - { - return ( - parent::uninstall() - && Configuration::deleteByName('ACCOUNT_ID') - && Configuration::deleteByName('AFFILI_SETTINGS') - ); - } - - public function getContent() - { - $output = '

'.$this->l('Affili').'

'; - - // check if is subnit save data - if (Tools::isSubmit('submitAff')) { - Configuration::updateValue('ACCOUNT_ID', Tools::getValue('accountId')); - $output .= ' -
- '.$this->l('Settings updated').' -
'; - } - - return $output.$this->displayForm(); - } - - public function displayForm() - { - $output = ' -
- -
- - - '.$this->l('Copy the Account Id from the affili panel.').' -
- - -
'; - - $output = '
'.$output.'
'; - - return $output; - } - - public function hookDisplayHeader() - { - if (!$this->context->smarty->getTemplateVars('is_order')) { - $this->context->smarty->assign('account_id', Configuration::get('ACCOUNT_ID')); - $this->context->smarty->assign('is_order', false); - - return $this->display(__FILE__, 'views/templates/snippet.tpl'); - } - } - - public function hookDisplayOrderConfirmation($params) - { - // Setting parameters - $order = isset($params['order']) ? $params['order'] : ( - isset($params['objOrder']) ? $params['objOrder'] : null - ); - - if ($order) { - $currency = Currency::getCurrencyInstance((int)$order->id_currency); - $multiplier = $currency->iso_code === 'IRR' ? 1 : 10; - - $id_cart_rule = current($order->getCartRules())['id_cart_rule'] ?? 0; - $code = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `code` FROM `'._DB_PREFIX_.'cart_rule` WHERE `id_cart_rule` = \''.$id_cart_rule.'\''); - - $amount = (isset($order->total_paid_tax_excl)) ? $order->total_paid_tax_excl : 0; - $shipping = (isset($order->total_shipping_tax_incl)) ? $order->total_shipping_tax_incl : 0; - $conversion_amount = ($amount - $shipping) * $multiplier; - - $products = []; - foreach ($order->getProducts() as $product) { - $products[] = [ - 'sku' => $product['product_name'], - 'unit_price' => $product['product_price'] * $multiplier, - 'quantity' => $product['product_quantity'], - 'total_price' => $product['product_price'] * $product['product_quantity'] * $multiplier, - ]; - } - - $options = [ - 'coupon' => $code, - 'products' => $products, - ]; - $options = count($options) ? json_encode($options) : json_encode($options, JSON_FORCE_OBJECT); - - $account_id = Configuration::get('ACCOUNT_ID'); - - $this->context->smarty->assign('external_id', $order->id); - $this->context->smarty->assign('conversion_amount', $conversion_amount); - $this->context->smarty->assign('account_id', $account_id); - $this->context->smarty->assign('is_order', true); - $this->context->smarty->assign('options', $options); - - return $this->display(__FILE__, 'views/templates/confirmed.tpl'); - } - } + parent::__construct(); + + $this->displayName = $this->l('Affili'); + $this->description = $this->l('Integrate the Affili tracking script in your shop'); + + $this->confirmUninstall = $this->l('Are you sure you want to delete Affili from your shop?'); + } + + public function install() + { + return (parent::install() && $this->registerHook('displayHeader') && $this->registerHook('displayOrderConfirmation')); + } + + public function uninstall() + { + return ( + parent::uninstall() && Configuration::deleteByName('AFFILI_SETTINGS') + ); + } + + public function hookDisplayHeader() + { + if (!$this->context->smarty->getTemplateVars('is_order')) { + $this->context->smarty->assign('is_order', false); + + return $this->display(__FILE__, 'views/templates/snippet.tpl'); + } + } + + public function hookDisplayOrderConfirmation($params) + { + // Setting parameters + $order = isset($params['order']) ? $params['order'] : ( + isset($params['objOrder']) ? $params['objOrder'] : null + ); + + if ($order) { + $id_cart_rule = current($order->getCartRules())['id_cart_rule'] ?? 0; + $code = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `code` FROM `'._DB_PREFIX_.'cart_rule` WHERE `id_cart_rule` = \''.$id_cart_rule.'\''); + + $amount = (isset($order->total_paid_tax_excl)) ? $order->total_paid_tax_excl : 0; + $shipping = (isset($order->total_shipping_tax_incl)) ? $order->total_shipping_tax_incl : 0; + $conversion_amount = $amount - $shipping; + + $products = []; + foreach ($order->getProducts() as $product) { + $products[] = [ + 'name' => $product['product_name'], + 'unit_price' => $product['product_price'], + 'quantity' => $product['product_quantity'], + 'total_price' => $product['product_price'] * $product['product_quantity'], + ]; + } + + $options = [ + 'coupon' => $code, + 'products' => $products, + ]; + $options = count($options) ? json_encode($options) : json_encode($options, JSON_FORCE_OBJECT); + + $this->context->smarty->assign('external_id', $order->id); + $this->context->smarty->assign('conversion_amount', $conversion_amount); + $this->context->smarty->assign('is_order', true); + $this->context->smarty->assign('options', $options); + + return $this->display(__FILE__, 'views/templates/confirmed.tpl'); + } + } } \ No newline at end of file diff --git a/config.xml b/config.xml index 6f97864..75b8863 100644 --- a/config.xml +++ b/config.xml @@ -6,8 +6,8 @@ - + 1 1 - + \ No newline at end of file diff --git a/views/templates/snippet.tpl b/views/templates/snippet.tpl index bcc77ff..e782403 100644 --- a/views/templates/snippet.tpl +++ b/views/templates/snippet.tpl @@ -3,6 +3,5 @@ {literal} window.affiliData = window.affiliData || [];function affili(){affiliData.push(arguments);} {/literal} - affili('create', '{$account_id|escape:'htmlall':'UTF-8'}'); - affili('detect'); + affili('create'); \ No newline at end of file