Files
redline.com.pl/modules/dualpricedisplaypro/dualpricedisplaypro.php
2024-11-11 18:46:54 +01:00

1133 lines
39 KiB
PHP

<?php
/**
* PRO Module to show VAT-free price with the price tax incl.
*
* @author Singleton software <info@singleton-software.com>
* @copyright 2018 Singleton software
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_'))
exit;
class DualPriceDisplayPro extends Module
{
public function __construct() {
$this->name = 'dualpricedisplaypro';
$this->tab = 'pricing_promotion';
$this->version = '1.2.0';
$this->author = 'Singleton software';
$this->module_key = '28cf9dfa8a80fb28a06301e07d13986b';
$this->author_address = '0x82BBBf54B369bf4dB2704ed3b97c85294950231C';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6.0.0', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Dual Price Display Pro');
$this->description = $this->l('Advanced module to show VAT-free price with the price tax incl.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get($this->name))
$this->warning = $this->l('No name provided');
}
public function install() {
return (parent::install() &&
Configuration::updateGlobalValue($this->name, Tools::jsonEncode($this->initDualPriceConfigData())) &&
$this->registerHook('displayHeader') &&
$this->registerHook('displayProductPriceBlock') &&
$this->registerHook('actionAjaxDieProductControllerdisplayAjaxRefreshBefore') &&
$this->createProductCombinationsFrontController());
}
public function uninstall() {
return (parent::uninstall() &&
Configuration::deleteByName($this->name) &&
$this->unregisterHook('displayHeader') &&
$this->unregisterHook('displayProductPriceBlock') &&
$this->unregisterHook('actionAjaxDieProductControllerdisplayAjaxRefreshBefore') &&
$this->removeProductCombinationsFrontController());
}
public function hookDisplayHeader($params) {
if ($this->displayProductDetailCheck(false) && version_compare(_PS_VERSION_, '1.7', '>')) {
$this->context->controller->registerJavascript('modules-dualpricepro-productjavascript', 'modules/'.$this->name.'/views/js/ps17/product.js', array('position' => 'bottom', 'priority' => 150));
}
if ($this->displayProductCatalogCheck() || $this->displayProductDetailCheck(true)) {
if (version_compare(_PS_VERSION_, '1.7', '>')) {
$this->context->controller->registerStylesheet('modules-dualpricepro-style', 'modules/'.$this->name.'/views/css/ps17/style.css', array('media' => 'all', 'priority' => 150));
$this->context->controller->registerJavascript('modules-dualpricepro-globajavascript', 'modules/'.$this->name.'/views/js/ps17/global.js', array('position' => 'bottom', 'priority' => 150));
} else {
$this->context->controller->addCss($this->_path.'views/css/ps16/style.css');
$this->context->controller->addJs($this->_path.'views/js/ps16/global.js');
}
$this->smarty->assign(
array(
'dualPriceConfigData' => Tools::jsonDecode(Configuration::get($this->name), true),
'dualPriceConfigDataJson' => Configuration::get($this->name),
'domElementPaths' => Tools::jsonEncode($this->getAdvancedFormFields()),
'productCombinationsControllerLink' => $this->context->link->getModuleLink($this->name, 'ProductCombinations'),
'idLang' => $this->context->language->id,
'ltPs1740' => version_compare(_PS_VERSION_, '1.7.4.0', '<')
)
);
return $this->display(__FILE__, 'views/templates/hook/'.(version_compare(_PS_VERSION_, '1.7', '>') ? 'ps17' : 'ps16').'/headerBlock.tpl');
}
}
public function hookDisplayProductPriceBlock($params) {
// prvy if je ze to je volane z katalogu
if ($params['type'] == 'weight' && (is_array($params['product']) || version_compare(_PS_VERSION_, '1.7.5', '>=')) && (!isset($params['hook_origin']) || !version_compare(_PS_VERSION_, '1.7', '>'))) {
if ($this->displayProductCatalogCheck()) {
return $this->renderProductCatalog($params, 'catalog');
}
return;
}
// druhy if je ze to je volane z detailu produktu (klasika alebo modal)
if ($params['type'] == 'weight' && ((is_array($params['product']) || version_compare(_PS_VERSION_, '1.7.5', '>=')) && version_compare(_PS_VERSION_, '1.7', '>') || (!version_compare(_PS_VERSION_, '1.7', '>') && $params['product'] instanceof Product))) {
if ($this->displayProductDetailCheck(true)) {
return $this->renderProductDetail($params);
}
return;
}
// pokial ide o ceny v zmensenych produktoch napr v lavom stlpci v preste 1.6
if ($params['type'] == 'price' && isset($params['product']) && !isset($params['from']) && !version_compare(_PS_VERSION_, '1.7', '>')) {
if ($this->displayProductCatalogCheck()) {
return $this->renderProductCatalog($params, 'minithumbs');
}
return;
}
}
public function hookActionAjaxDieProductControllerdisplayAjaxRefreshBefore($params) {
$ajaxReturn = Tools::jsonDecode($params['value']);
$ajaxReturn->id_product = (int)Tools::getValue('id_product');
die(Tools::jsonEncode($ajaxReturn));
}
public function getContent() {
$settingsUpdated = '';
if (Tools::isSubmit('submit'.$this->name)) {
$dualPriceConfigData = array();
foreach($this->getFormFields() as $key => $value) {
if (isset($value['lang']) && $value['lang'] === true) {
foreach (Language::getLanguages() as $langKey => $langValue) {
$dualPriceConfigData[$value['name']][$langValue['id_lang']] = Tools::getValue($value['name'].'_'.$langValue['id_lang']);
}
} else if ($value['type'] == 'checkbox') {
foreach($value['values']['query'] as $query) {
if (Tools::getIsset($value['name'].'_'.$query['id'])) {
$dualPriceConfigData[$value['name'].'_'.$query['id']] = true;
}
}
} else {
$dualPriceConfigData[$value['name']] = Tools::getValue($value['name']);
}
}
Configuration::updateValue($this->name, Tools::jsonEncode($dualPriceConfigData));
$settingsUpdated .= $this->displayConfirmation($this->l('Settings updated'));
}
$this->smarty->assign(
array(
'moduleDir' => _MODULE_DIR_,
'translate' => Tools::jsonEncode($this->getTranslates()),
'isPs17' => version_compare(_PS_VERSION_, '1.7', '>')
)
);
$this->context->controller->addJqueryPlugin('colorpicker');
return $settingsUpdated.$this->display(__FILE__,'BOconfig.tpl').$this->displayForm();
}
public function displayForm() {
$fields_form = array();
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Module Settings'),
),
'input' => $this->getFormFields(),
'submit' => array(
'title' => $this->l('Save'),
'name' => 'submit'.$this->name,
)
);
$helper = new HelperForm();
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
$helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
$helper->allow_employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$helper->title = $this->displayName;
$helper->show_toolbar = false;
$helper->toolbar_scroll = false;
$helper->submit_action = 'submit'.$this->name;
$helper->tpl_vars = array(
'fields_value' => Tools::jsonDecode(Configuration::get($this->name), true),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm($fields_form);
}
private function renderProductDetail($params) {
$productPrice = array();
if (version_compare(_PS_VERSION_, '1.7', '>')) {
$productPrice['hasDiscount'] = ($params['product']['reduction'] != 0);
} else {
$productPrice['hasDiscount'] = ($params['product']->specificPrice && $params['product']->specificPrice['reduction']);
}
$product = new Product((int)Tools::getValue('id_product'));
$productPrice['taxInclPrice'] = Tools::displayPrice($product->getPrice(true, (((int)Tools::getValue('id_product_attribute') > 0) ? (int)Tools::getValue('id_product_attribute') : null)), $this->context->currency);
$productPrice['taxExclPrice'] = Tools::displayPrice($product->getPrice(false, (((int)Tools::getValue('id_product_attribute') > 0) ? (int)Tools::getValue('id_product_attribute') : null)), $this->context->currency);
$productPrice['originalTaxInclPrice'] = Tools::displayPrice($product->getPrice(true, (((int)Tools::getValue('id_product_attribute') > 0) ? (int)Tools::getValue('id_product_attribute') : null), 6, null, false, false), $this->context->currency);
$productPrice['originalTaxExclPrice'] = Tools::displayPrice($product->getPrice(false, (((int)Tools::getValue('id_product_attribute') > 0) ? (int)Tools::getValue('id_product_attribute') : null), 6, null, false, false), $this->context->currency);
$productPrice['price'] = Tools::displayPrice( Product::getPriceStatic( (int)Tools::getValue('id_product'), true, null, 2, null, false, false, 1, false, null, null, null, $product -> specificPrice, true, false ), $this->context->currency);
$this->smarty->assign(
array(
'productPriceInDetail' => $productPrice,
'productID' => (int)Tools::getValue('id_product'),
'isModal' => (Tools::getValue('action') === 'quickview')
)
);
return $this->display(__FILE__, 'views/templates/hook/'.(version_compare(_PS_VERSION_, '1.7', '>') ? 'ps17' : 'ps16').'/productDetailBlock.tpl');
}
private function renderProductCatalog($params, $type) {
if (is_array($params['product'])) {
//pokial ide o porovnanie produktu tak pride pole
$product = new Product((int)$params['product']['id_product']);
$hasDiscount = ($params['product']['reduction'] != 0);
} else {
//pokial ide o porovnanie produktu tak pride objekt
$product = new Product((int)$params['product']->id);
$hasDiscount = ($params['product']->specificPrice && $params['product']->specificPrice['reduction']);
}
$this->smarty->assign(
array(
'dualPriceConfigData' => Tools::jsonDecode(Configuration::get($this->name), true),
'priceWithTax' => Tools::displayPrice($product->getPrice(true), $this->context->currency),
'priceWithoutTax' => Tools::displayPrice($product->getPrice(false), $this->context->currency),
'originalPriceWithTax' => Tools::displayPrice($product->getPrice(true, null, 6, null, false, false), $this->context->currency),
'originalPriceWithoutTax' => Tools::displayPrice($product->getPrice(false, null, 6, null, false, false), $this->context->currency),
'hasDiscount' => $hasDiscount,
'idLang' => $this->context->language->id,
'type' => $type
)
);
return $this->display(__FILE__, 'views/templates/hook/'.(version_compare(_PS_VERSION_, '1.7', '>') ? 'ps17' : 'ps16').'/catalogPriceBlock.tpl');
}
private function displayAdvancedCheck() {
$dualPriceConfigData = Tools::jsonDecode(Configuration::get($this->name), true);
if ((int)$dualPriceConfigData['show_price_if'] == 0) {
// ak je aspon jedno splnene
if ($this->checkCustomerGroupPermission() || $this->checkLanguagePermission() || $this->checkCurrencyPermission()) {
return true;
}
} else {
// ak su vsetky splnene
if ($this->checkCustomerGroupPermission() && $this->checkLanguagePermission() && $this->checkCurrencyPermission()) {
return true;
}
}
return false;
}
private function checkCustomerGroupPermission() {
$currentGroup = Group::getCurrent();
$dualPriceConfigData = Tools::jsonDecode(Configuration::get($this->name), true);
foreach(Group::getGroups($this->context->language->id) as $key => $value) {
if (isset($dualPriceConfigData['customer_groups_group_'.$value['id_group']]) &&
(int)$dualPriceConfigData['customer_groups_group_'.$value['id_group']] == 1 &&
(int)$currentGroup->id == (int)$value['id_group']) {
return true;
}
}
return false;
}
private function checkLanguagePermission() {
$dualPriceConfigData = Tools::jsonDecode(Configuration::get($this->name), true);
foreach(Language::getLanguages() as $key => $value) {
if (isset($dualPriceConfigData['languages_lang_'.$value['id_lang']]) &&
(int)$dualPriceConfigData['languages_lang_'.$value['id_lang']] == 1 &&
(int)$this->context->language->id == (int)$value['id_lang']) {
return true;
}
}
return false;
}
private function checkCurrencyPermission() {
$dualPriceConfigData = Tools::jsonDecode(Configuration::get($this->name), true);
foreach(Currency::getCurrencies() as $key => $value) {
if (isset($dualPriceConfigData['currencies_currency_'.$value['id_currency']]) &&
(int)$dualPriceConfigData['currencies_currency_'.$value['id_currency']] == 1 &&
(int)$this->context->currency->id == (int)$value['id_currency']) {
return true;
}
}
return false;
}
private function displayProductCatalogCheck() {
$pageName = $this->getCurrentPageName();
$dualPriceConfigData = Tools::jsonDecode(Configuration::get($this->name), true);
if ((((bool)$dualPriceConfigData['show_on_home_page'] && $pageName == 'index') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'category') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'manufacturer') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'supplier') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'new-products') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'prices-drop') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'best-sales') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'products-comparison') ||
((bool)$dualPriceConfigData['show_in_categories'] && $pageName == 'search') ||
((bool)$dualPriceConfigData['show_in_asociative_products'] && $pageName == 'product'))) {
return $this->displayAdvancedCheck();
}
return false;
}
private function displayProductDetailCheck($canBeModal) {
$pageName = $this->getCurrentPageName();
$dualPriceConfigData = Tools::jsonDecode(Configuration::get($this->name), true);
if (($pageName == 'product' && (bool)$dualPriceConfigData['show_in_product_detail'] && !$canBeModal) ||
((bool)$dualPriceConfigData['show_in_product_detail'] && $canBeModal)) {
return $this->displayAdvancedCheck();
}
return false;
}
private function getFormFields() {
$mainFormFields = array(
array(
'type' => 'switch',
'label' => $this->l('Show on home page:'),
'desc' => $this->l('If this feature is turned on, Tax included prices and Tax excluded prices will be displayed on home page'),
'name' => 'show_on_home_page',
'required' => false,
'class' => 'showOnHomePage',
'is_bool' => true,
'values' => array(
array(
'id' => 'show_on_home_page_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_on_home_page_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'switch',
'label' => $this->l('Show in product detail:'),
'desc' => $this->l('If this feature is turned on, Tax included prices and Tax excluded prices will be displayed in product detail'),
'name' => 'show_in_product_detail',
'required' => false,
'class' => 'showInProductDetail',
'is_bool' => true,
'values' => array(
array(
'id' => 'show_in_product_detail_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_in_product_detail_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'switch',
'label' => $this->l('Show in products catalogs:'),
'desc' => $this->l('If this feature is turned on, Tax included prices and Tax excluded prices will be displayed in categories of products, or search results'),
'name' => 'show_in_categories',
'required' => false,
'class' => 'showInCategories',
'is_bool' => true,
'values' => array(
array(
'id' => 'show_in_categories_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_in_categories_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' =>'switch',
'label' => $this->l('Show in "add to cart" popup block:'),
'desc' => $this->l('If this feature is turned on, Tax included prices and Tax excluded prices will be displayed in popup window, which is displayed after customer add some product to cart'),
'name' => 'show_in_add_to_cart_popup',
'required' => false,
'class' => 'showInAddToCartPopup',
'is_bool' => true,
'values' => array(
array(
'id' => 'show_in_add_to_cart_popup_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_in_add_to_cart_popup_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'switch',
'label' => $this->l('Show in related products block:'),
'desc' => $this->l('If this feature is turned on, Tax included prices and Tax excluded prices will be displayed in related products (accessories), which are displayed in product detail page under the main product'),
'name' => 'show_in_asociative_products',
'required' => false,
'class' => 'showInAsociativeProducts',
'is_bool' => true,
'values' => array(
array(
'id' => 'show_in_asociative_products_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_in_asociative_products_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'checkbox',
'label' => $this->l('Show for these customers groups:'),
'desc' => $this->l('You can choose, for which customers group in front office is allowed to see Tax included prices and Tax excluded prices. Thats mean, for which customers group is allowed to use functionality of this module.'),
'name' => 'customer_groups',
'class' => 'customerGroups',
'values' => array(
'query' => $this->getCustomersGroups(),
'id' => 'id',
'name' => 'name',
'value' => '0'
),
'init_value' => '0'
),
array(
'type' => 'checkbox',
'label' => $this->l('Show for these languages:'),
'desc' => $this->l('You can choose, for which selected language by user in front office is allowed to see Tax included prices and Tax excluded prices. Thats mean, for which language is allowed to use functionality of this module.'),
'name' => 'languages',
'class' => 'languages',
'values' => array(
'query' => $this->getFOLanguages(),
'id' => 'id',
'name' => 'name',
'value' => '0'
),
'init_value' => '0'
),
array(
'type' => 'checkbox',
'label' => $this->l('Show for these currencies:'),
'desc' => $this->l('You can choose, for which selected currency by user in front office is allowed to see Tax included prices and Tax excluded prices. Thats mean, for which currency is allowed to use functionality of this module.'),
'name' => 'currencies',
'class' => 'currencies',
'values' => array(
'query' => $this->getFOCurrencies(),
'id' => 'id',
'name' => 'name',
'value' => '0'
),
'init_value' => '0'
),
array(
'type' => 'radio',
'label' => $this->l('Show dual prices only if:'),
'desc' => $this->l('You can choose if at least one of the criteria (from above) has to be met to to use functionality of this module. Or all of the criterias (from above) has to be met to show Tax included prices and Tax excluded prices in front office to user.'),
'name' => 'show_price_if',
'required' => false,
'class' => 'showPriceIf',
'values' => array(
array(
'id' => 'show_price_if_at_least_one',
'value' => 0,
'label' => $this->l('At least one of the criteria is met')
),
array(
'id' => 'show_price_if_all_of_them',
'value' => 1,
'label' => $this->l('All of the criterias are met')
)
),
'init_value' => '0'
),
array(
'type' => 'radio',
'label' => $this->l('Which prices to show:'),
'desc' => $this->l('You can choose if both prices will be dispayed (Tax included prices and Tax excluded prices), or only one of them'),
'name' => 'prices_to_show',
'required' => false,
'class' => 'pricesToShow',
'values' => array(
array(
'id' => 'prices_to_show_both',
'value' => 0,
'label' => $this->l('Both')
),
array(
'id' => 'prices_to_show_included',
'value' => 1,
'label' => $this->l('Only Tax included prices')
),
array(
'id' => 'prices_to_show_excluded',
'value' => 2,
'label' => $this->l('Only Tax excluded prices')
)
),
'init_value' => '0'
),
array(
'type' => 'switch',
'label' => $this->l('Tax excluded price show first:'),
'desc' => $this->l('If this feature is turned on, Tax excluded prices will display above of Tax included prices'),
'name' => 'tax_excl_first',
'required' => false,
'class' => 'taxExclFirst',
'is_bool' => true,
'values' => array(
array(
'id' => 'tax_excl_first_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'tax_excl_first_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'select',
'label' => $this->l('Size ratio between both prices:'),
'desc' => $this->l('You can set the size ratio between both prices'),
'name' => 'size_ratio_between_prices',
'required' => false,
'options' => array(
'query' => $this->getSizeRatio(),
'id' => 'id_option',
'name' => 'name'
),
'init_value' => '2'
),
array(
'type' => 'text',
'label' => $this->l('Color of Tax included price:'),
'name' => 'tax_incl_color',
'class' => 'taxInclColor',
'required' => false,
'desc' => $this->l('You can set the color of Tax included prices'),
'init_value' => 'rgb(0, 0, 0)'
),
array(
'type' => 'text',
'label' => $this->l('Color of Tax excluded price:'),
'name' => 'tax_excl_color',
'class' => 'taxExclColor',
'required' => false,
'desc' => $this->l('You can set the color of Tax excluded prices'),
'init_value' => 'rgb(0, 0, 0)'
),
array(
'type' => 'switch',
'label' => $this->l('Show tax included label:'),
'desc' => $this->l('If this feature is turned on, Tax included label will be displayed'),
'name' => 'show_tax_incl_label',
'required' => false,
'class' => 'showTaxInclLabel',
'is_bool' => true,
'values' => array(
array(
'id' => 'show_tax_incl_label_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_tax_incl_label_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'text',
'label' => $this->l('Tax included label:'),
'name' => 'tax_incl_label_name',
'class' => 'taxInclLabelName',
'lang' => true,
'required' => false,
'desc' => $this->l('You can set Tax included label title for each language'),
'init_value' => $this->l('Tax incl.')
),
array(
'type' => 'switch',
'label' => $this->l('Show tax excluded label:'),
'desc' => $this->l('If this feature is turned on, Tax excluded label will be displayed'),
'name' => 'show_tax_excl_label',
'required' => false,
'class' => 'showTaxExclLabel',
'values' => array(
array(
'id' => 'show_tax_excl_label_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_tax_excl_label_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'text',
'label' => $this->l('Tax excluded label:'),
'name' => 'tax_excl_label_name',
'class' => 'taxExclLabelName',
'lang' => true,
'required' => false,
'desc' => $this->l('You can set Tax excluded label title for each language'),
'init_value' => $this->l('Tax excl.')
),
array(
'type' => 'switch',
'label' => $this->l('Show old prices:'),
'desc' => $this->l('You can show also old (non discount) prices and set the rules of their display in this section'),
'name' => 'show_old_prices',
'required' => false,
'class' => 'showOldPrices',
'values' => array(
array(
'id' => 'show_old_prices_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_old_prices_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'radio',
'label' => $this->l('Which old prices to show:'),
'desc' => $this->l('You can choose if both old prices will be dispayed (Tax included prices and Tax excluded prices), or only one of them'),
'name' => 'old_prices_to_show',
'required' => false,
'class' => 'oldPricesToShow',
'values' => array(
array(
'id' => 'old_prices_to_show_both',
'value' => 0,
'label' => $this->l('Both')
),
array(
'id' => 'old_prices_to_show_included',
'value' => 1,
'label' => $this->l('Only Tax included prices')
),
array(
'id' => 'old_prices_to_show_excluded',
'value' => 2,
'label' => $this->l('Only Tax excluded prices')
)
),
'init_value' => '1'
),
array(
'type' => 'switch',
'label' => $this->l('Tax excluded price show first:'),
'desc' => $this->l('If this feature is turned on, Tax excluded prices will display above of Tax included prices'),
'name' => 'old_price_tax_excl_first',
'required' => false,
'class' => 'taxExclFirst',
'is_bool' => true,
'values' => array(
array(
'id' => 'old_price_tax_excl_first_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'old_price_tax_excl_first_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'select',
'label' => $this->l('Size ratio between standard and old prices:'),
'desc' => $this->l('You can set the size ratio between standard and old (non discount) prices'),
'name' => 'size_ratio_old_prices',
'required' => false,
'options' => array(
'query' => $this->getSizeRatio(),
'id' => 'id_option',
'name' => 'name'
),
'init_value' => '2'
),
array(
'type' => 'text',
'label' => $this->l('Color of old price:'),
'name' => 'old_prices_color',
'class' => 'oldPricesColor',
'required' => false,
'desc' => $this->l('You can set the color of old (non discount) prices'),
'init_value' => 'rgb(241, 51, 64)'
),
array(
'type' => 'switch',
'label' => $this->l('Show line through old price:'),
'desc' => $this->l('You can display strikethrough old prices'),
'name' => 'show_line_through_old_prices',
'required' => false,
'class' => 'showLineThroughOldPrices',
'values' => array(
array(
'id' => 'show_line_through_old_prices_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_line_through_old_prices_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '1'
),
array(
'type' => 'switch',
'label' => $this->l('Show old price before standard price:'),
'desc' => $this->l('If this feature is turned on, old (non discount) prices will be displayed above of standard prices'),
'name' => 'old_price_before_standard_price',
'required' => false,
'class' => 'oldPriceBeforeStandardPrice',
'is_bool' => true,
'values' => array(
array(
'id' => 'old_price_before_standard_price_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'old_price_before_standard_price_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'switch',
'label' => $this->l('Show advanced settings:'),
'desc' => $this->l('In advanced options, you can modify paths of DOM elements. Please do not modify it, if you are not skilled in it'),
'name' => 'show_advanced_settings',
'required' => false,
'class' => 'showAdvancedSettings',
'values' => array(
array(
'id' => 'show_advanced_settings_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'show_advanced_settings_off',
'value' => 0,
'label' => $this->l('No')
)
),
'init_value' => '0'
),
array(
'type' => 'hidden',
'label' => $this->l('Opened Tab'),
'name' => 'opened_tab',
'required' => false,
'class' => 'openedTab',
'values' => array(
array(
'id' => 'places_of_display',
'value' => 'places_of_display',
'label' => $this->l('places_of_display')
),
array(
'id' => 'advanced_settings_of_display',
'value' => 'advanced_settings_of_display',
'label' => $this->l('Opened Tab')
),
array(
'id' => 'standard_prices',
'value' => 'standard_prices',
'label' => $this->l('Opened Tab')
),
array(
'id' => 'old_prices',
'value' => 'old_prices',
'label' => $this->l('Opened Tab')
),
array(
'id' => 'dom_elements_paths',
'value' => 'dom_elements_paths',
'label' => $this->l('Opened Tab')
)
),
'init_value' => 'places_of_display'
),
);
return array_merge($mainFormFields, $this->getAdvancedFormFields());
}
private function getAdvancedFormFields() {
if (version_compare(_PS_VERSION_, '1.7', '>')) {
return array(
array(
'type' => 'text',
'label' => $this->l('Parent path of product catalog miniature:'),
'name' => 'miniature_root_path',
'class' => 'miniatureRootPath',
'required' => false,
'lang' => false,
'init_value' => '.product-miniature'
),
array(
'type' => 'text',
'label' => $this->l('Price path of product catalog miniature:'),
'name' => 'miniature_price_path',
'class' => 'miniaturePricePath',
'required' => false,
'lang' => false,
'init_value' => '.price'
),
array(
'type' => 'text',
'label' => $this->l('Old price path of product catalog miniature:'),
'name' => 'miniature_old_price_path',
'class' => 'miniatureOldPricePath',
'required' => false,
'lang' => false,
'init_value' => '.regular-price'
),
array(
'type' => 'text',
'label' => $this->l('Price path of product detail:'),
'name' => 'detail_price_path',
'class' => 'detailPricePath',
'required' => false,
'lang' => false,
'init_value' => '.product-prices'
),
array(
'type' => 'text',
'label' => $this->l('Quantity field path of product detail:'),
'name' => 'detail_quantity_path',
'class' => 'detailQuantityPath',
'required' => false,
'lang' => false,
'init_value' => '#quantity_wanted'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of product detail:'),
'name' => 'detail_parent_path',
'class' => 'detailParentPath',
'required' => false,
'lang' => false,
'init_value' => '#main'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of product quickview:'),
'name' => 'quickview_parent_path',
'class' => 'quickviewParentPath',
'required' => false,
'lang' => false,
'init_value' => '.modal'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of "add to cart" summary pop-up:'),
'name' => 'summary_popup_parent_path',
'class' => 'summaryPopupParentPath',
'required' => false,
'lang' => false,
'init_value' => '#blockcart-modal.in'
),
array(
'type' => 'text',
'label' => $this->l('Product price path of "add to cart" summary pop-up:'),
'name' => 'summary_popup_product_path',
'class' => 'summaryPopupProductPath',
'required' => false,
'lang' => false,
'init_value' => '#blockcart-modal.in .product-name ~ p:not(:has(strong))'
)
);
} else {
return array(
array(
'type' => 'text',
'label' => $this->l('Parent path of product catalog miniature:'),
'name' => 'miniature_root_path',
'class' => 'miniatureRootPath',
'required' => false,
'lang' => false,
'init_value' => '.product-container'
),
array(
'type' => 'text',
'label' => $this->l('Price path of product catalog miniature:'),
'name' => 'catalog_price_path',
'class' => 'catalogPricePath',
'required' => false,
'lang' => false,
'init_value' => '.content_price'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of product detail:'),
'name' => 'detail_parent_path',
'class' => 'detailParentPath',
'required' => false,
'lang' => false,
'init_value' => '#buy_block'
),
array(
'type' => 'text',
'label' => $this->l('Price path of product detail:'),
'name' => 'detail_price_path',
'class' => 'detailPricePath',
'required' => false,
'lang' => false,
'init_value' => '.content_prices'
),
array(
'type' => 'text',
'label' => $this->l('Quantity field path of product detail:'),
'name' => 'detail_quantity_path',
'class' => 'detailQuantityPath',
'required' => false,
'lang' => false,
'init_value' => '#quantity_wanted'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of side product miniature:'),
'name' => 'side_product_miniature_parent_path',
'class' => 'sideProductMiniatureParentPath',
'required' => false,
'lang' => false,
'init_value' => 'li'
),
array(
'type' => 'text',
'label' => $this->l('Price path of side product miniature:'),
'name' => 'side_product_miniature_price_path',
'class' => 'sideProductMiniaturePricePath',
'required' => false,
'lang' => false,
'init_value' => '.price-box'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of accessories miniature:'),
'name' => 'accessories_miniature_parent_path',
'class' => 'accessoriesMiniatureParentPath',
'required' => false,
'lang' => false,
'init_value' => 'li'
),
array(
'type' => 'text',
'label' => $this->l('Price path of accessories miniature:'),
'name' => 'accessories_miniature_price_path',
'class' => 'accessoriesMiniaturePricePath',
'required' => false,
'lang' => false,
'init_value' => '.price'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of compared product miniature:'),
'name' => 'compared_product_miniature_parent_path',
'class' => 'comparedProductMiniatureParentPath',
'required' => false,
'lang' => false,
'init_value' => 'td'
),
array(
'type' => 'text',
'label' => $this->l('Price path of compared product miniature:'),
'name' => 'compared_product_miniature_price_path',
'class' => 'comparedProductMiniaturePricePath',
'required' => false,
'lang' => false,
'init_value' => '.prices-container'
),
array(
'type' => 'text',
'label' => $this->l('Parent path of "add to cart" summary pop-up:'),
'name' => 'summary_popup_parent_path',
'class' => 'summaryPopupParentPath',
'required' => false,
'lang' => false,
'init_value' => '#layer_cart'
),
array(
'type' => 'text',
'label' => $this->l('Product price path of "add to cart" summary pop-up:'),
'name' => 'summary_popup_product_path',
'class' => 'summaryPopupProductPath',
'required' => false,
'lang' => false,
'init_value' => '#layer_cart_product_price'
)
);
}
}
private function initDualPriceConfigData() {
$dualPriceConfigData = array();
foreach($this->getFormFields() as $key => $value) {
if (isset($value['lang']) && $value['lang'] === true) {
foreach (Language::getLanguages() as $langKey => $langValue) {
$dualPriceConfigData[$value['name']][$langValue['id_lang']] = $value['init_value'];
}
} else if ($value['type'] == 'checkbox') {
foreach($value['values']['query'] as $query) {
$dualPriceConfigData[$value['name'].'_'.$query['id']] = true;
}
} else {
$dualPriceConfigData[$value['name']] = $value['init_value'];
}
}
return $dualPriceConfigData;
}
private function createProductCombinationsFrontController() {
$tab = new Tab();
$tab->active = 1;
$tab->class_name = 'ProductCombinations';
$tab->module = $this->name;
$tab->id_parent = -1;
foreach (Language::getLanguages(false) as $lang) {
$tab->name[$lang['id_lang']] = $this->l('Product Combinations');
}
return $tab->add();
}
private function removeProductCombinationsFrontController() {
$id_tab = (int)Tab::getIdFromClassName('ProductCombinations');
if ($id_tab) {
$tab = new Tab($id_tab);
return $tab->delete();
}
return true;
}
private function getFOCurrencies() {
$currencies = array();
foreach (Currency::getCurrencies() as $key => $value) {
$currencies[] = array(
'id'=> 'currency_'.$value['id_currency'],
'name' => $value['name'].' ('.$value['iso_code'].')',
'val' => $value['id_currency']
);
}
return $currencies;
}
private function getFOLanguages() {
$languages = array();
foreach (Language::getLanguages() as $key => $value) {
$languages[] = array(
'id'=> 'lang_'.$value['id_lang'],
'name' => $value['name'],
'val' => $value['id_lang']
);
}
return $languages;
}
private function getCustomersGroups() {
$customersGroups = array();
foreach(Group::getGroups($this->context->language->id) as $key => $value) {
$customersGroups[] = array(
'id'=> 'group_'.$value['id_group'],
'name' => $value['name'],
'val' => $value['id_group']
);
}
return $customersGroups;
}
private function getSizeRatio() {
return array(
array(
'id_option' => '1',
'name' => '1:1'
),
array(
'id_option' => '2',
'name' => '1:2'
),
array(
'id_option' => '3',
'name' => '1:3'
),
array(
'id_option' => '4',
'name' => '1:4'
)
);
}
private function getCurrentPageName() {
if (version_compare(_PS_VERSION_, '1.7', '>')) {
return $this->context->controller->getPageName();
} else {
return $this->smarty->getTemplateVars('page_name');
}
}
private function getTranslates() {
return array(
'placesOfDisplay' => $this->l('Places of display'),
'advancedSettingsOfDisplay' => $this->l('Advanced settings of display'),
'standardPrices' => $this->l('Standard Prices'),
'oldPrices' => $this->l('Old Prices'),
'domElementsPaths' => $this->l('DOM Elements Paths'),
);
}
}