Files
newwalls.pl/modules/squaremeter_bckp/squaremeter.php
2024-12-17 13:43:22 +01:00

1336 lines
76 KiB
PHP

<?php
/**
* Module Name: Perimeter / Length / Surface (Area) / Volume / Weight Calculator for Prestashop
*
* Module URI: Please contact with info@megventure.com
* Description: A tool to calculate quantity in linear, perimeter, surface (area), volume or weight units.
* Version: 5.5.0
*
* @author MEG Venture <info@megventure.com>
* @copyright 2007-2021 MEG Venture
* @license For Prestashop--> http://opensource.org/licenses/osl-3.2.1.php Open Software License (OSL 3.2.1)
*
* This program is not a free software: you can't redistribute it and/or modify
* it. All rights reserved to MEG Venture.
*
* This copyright notice and licence should be retained in all modules based on this framework.
* This does not affect your rights to assert copyright over your own original work.
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class Squaremeter extends Module
{
private $_html = '';
private $post_errors = array();
public $context;
public $shop_designtype;
public $shop_unittype;
public $shop_decimaltype;
public $shop_dimensiondisplaytype;
public $shop_cartupdate;
public function __construct()
{
$this->name = 'squaremeter';
$this->tab = 'front_office_features';
$this->version = '5.5.0';
$this->bootstrap = true;
$this->author = 'MEG Venture';
$this->need_instance = 0;
$this->module_key = '0cc8078ba5105cf0b6a0a5626aaf134d';
$this->secure_key = Tools::encrypt($this->name);
$config = Configuration::getMultiple(array(
$this->name . '_designtype',
$this->name . '_unittype',
$this->name . '_decimaltype',
$this->name . '_dimensiondisplaytype',
$this->name . '_cartupdate',
));
if (isset($config[$this->name . '_designtype'])) {
$this->designtype = $config[$this->name . '_designtype'];
}
if (isset($config[$this->name . '_unittype'])) {
$this->unittype = $config[$this->name . '_unittype'];
}
if (isset($config[$this->name . '_decimaltype'])) {
$this->decimaltype = $config[$this->name . '_decimaltype'];
}
if (isset($config[$this->name . '_dimensiondisplaytype'])) {
$this->dimensiondisplaytype = $config[$this->name . '_dimensiondisplaytype'];
}
if (isset($config[$this->name . '_cartupdate'])) {
$this->cartupdate = $config[$this->name . '_cartupdate'];
}
parent::__construct();
$this->displayName = $this->l('Linear / Perimeter / Surface (Area) / Volume / Weight Calculation Module');
$this->description = $this->l('A tool to calculate quantity in linear, perimeter, surface (area), volume or weight units.');
if (!isset($this->designtype)) {
$this->warning = $this->l('Design type must be configured in order to use this module correctly.');
}
if (!isset($this->unittype)) {
$this->warning = $this->l('Measurement unit type must be configured in order to use this module correctly.');
}
if (!isset($this->decimaltype)) {
$this->warning = $this->l('Decimal separator type must be configured in order to use this module correctly.');
}
if (!isset($this->dimensiondisplaytype)) {
$this->warning = $this->l('Dimesion display type must be configured in order to use this module correctly.');
}
if (!isset($this->cartupdate)) {
$this->warning = $this->l('Cart update option must be configured in order to use this module correctly.');
}
$path = dirname(__FILE__);
if (strpos(__FILE__, 'Module.php') !== false) {
$path .= '/../modules/' . $this->name;
}
require_once dirname(__FILE__) . '/classes/SquaremeterAdmin.php';
}
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
include dirname(__FILE__) . '/sql/install.php';
if (!parent::install()
|| !$this->registerHook('displayHeader')
|| !$this->registerHook('displayFooterProduct')
|| !$this->registerHook('displayProductListReviews')
|| !$this->registerHook('backOfficeHeader')
|| !$this->registerHook('displayAdminProductsExtra')
|| !$this->registerHook('actionProductUpdate')
|| !$this->registerHook('actionProductAdd')
|| !$this->runSql($sql)
|| !$this->registerHook('actionObjectCartUpdateBefore')) {
return false;
}
return true;
}
public function uninstall()
{
include dirname(__FILE__) . '/sql/uninstall.php';
return true;
}
public function runSql($sql)
{
foreach ($sql as $s) {
if (!Db::getInstance()->Execute($s)) {
return false;
}
}
return true;
}
private function _postValidation()
{
if (Tools::isSubmit('submit' . $this->name)) {
if (!Tools::getValue('designtypeA')) {
$this->post_errors[] = $this->l('Changes are not saved. Design type is required.');
}
if (!Tools::getValue('unittypeA')) {
$this->post_errors[] = $this->l('Changes are not saved. Unit measurement type is required.');
}
if (!Tools::getValue('decimaltypeA')) {
$this->post_errors[] = $this->l('Changes are not saved. Decimal separator type is required.');
}
if (!Tools::getValue('dimensiondisplaytypeA')) {
$this->post_errors[] = $this->l('Changes are not saved. Dimension display type is required.');
}
if (!Tools::getValue('cartupdateA')) {
$this->post_errors[] = $this->l('Changes are not saved. Cart update option is required.');
}
}
}
public function getContent()
{
$this->_html = null;
if (Tools::isSubmit('submit' . $this->name)) {
$this->_postValidation();
if (!count($this->post_errors)) {
$this->postProcess();
} else {
foreach ($this->post_errors as $err) {
$this->_html .= $this->displayError($err);
}
}
}
$this->context->smarty->assign('path', Context::getContext()->shop->getBaseURL(true));
$_html_export_import = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/exportimport.tpl');
return $this->_html . $_html_export_import . $this->_displayForm0();
}
private function postProcess()
{
$available_languages = LanguageCore::getLanguages();
$index = Configuration::get('WD_CUSTOMIZATION_INDEX');
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
Configuration::updateValue($this->name . '_designtype', Tools::getValue('designtypeA'), false, $idShopGroup, $idShop);
Configuration::updateValue($this->name . '_unittype', Tools::getValue('unittypeA'), false, $idShopGroup, $idShop);
Configuration::updateValue($this->name . '_decimaltype', Tools::getValue('decimaltypeA'), false, $idShopGroup, $idShop);
Configuration::updateValue($this->name . '_dimensiondisplaytype', Tools::getValue('dimensiondisplaytypeA'), false, $idShopGroup, $idShop);
Configuration::updateValue($this->name . '_cartupdate', Tools::getValue('cartupdateA'), false, $idShopGroup, $idShop);
Configuration::updateValue($this->name . '_referenceProduct', Tools::getValue('referenceProductA'), false, $idShopGroup, $idShop);
} else {
$idShop = 1;
Configuration::updateValue($this->name . '_designtype', Tools::getValue('designtypeA'));
Configuration::updateValue($this->name . '_unittype', Tools::getValue('unittypeA'));
Configuration::updateValue($this->name . '_decimaltype', Tools::getValue('decimaltypeA'));
Configuration::updateValue($this->name . '_dimensiondisplaytype', Tools::getValue('dimensiondisplaytypeA'));
Configuration::updateValue($this->name . '_cartupdate', Tools::getValue('cartupdateA'));
Configuration::updateValue($this->name . '_referenceProduct', Tools::getValue('referenceProductA'));
}
foreach ($available_languages as $a_language) {
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'customization_field_lang WHERE id_customization_field = ' . (int) $index . ' AND ' . 'id_lang = ' . (int) $a_language['id_lang'] . ' AND ' . 'id_shop = ' . (int) $idShop;
if ($results = Db::getInstance()->ExecuteS($sql)) {
Db::getInstance()->update('customization_field_lang', array(
'name' => pSQL(Tools::getValue($a_language['id_lang'])),
), 'id_customization_field = ' . (int) $index . ' AND ' . 'id_lang = ' . (int) $a_language['id_lang'] . ' AND ' . 'id_shop = ' . (int) $idShop);
} else {
Db::getInstance()->insert('customization_field_lang', array(
'name' => pSQL(Tools::getValue($a_language['id_lang'])),
'id_customization_field' => (int) $index,
'id_lang' => (int) $a_language['id_lang'],
'id_shop' => (int) $idShop,
));
}
}
$this->_html .= $this->displayConfirmation($this->l('Settings updated'));
}
public function _displayForm0()
{
/* Get default language */
$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$products = Product::getSimpleProducts($this->context->language->id);
$options = array();
foreach ($products as $key => $item) {
$options[] = array('id_product' => $item['id_product'], 'name' => $item['name']);
}
/* Init Fields form array */
$fields_form = [];
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Module Settings'),
'icon' => 'icon-cogs',
),
'description' => $this->l('The module allows two types of measurement unit system: English (standard) and Metric unit systems. One of them should be selected in order to use the module correctly. Note that calculator settings are adjusted through each product\'s edit page. Once you go to the regarding product editing page, you need to use the bottom tab for those settings. You can also change the invoice description on the invoice.'),
'input' => array(
array(
'type' => 'radio',
'label' => $this->l('Design Type'),
'desc' => $this->l('The module allows two types of designs for the applet: Stacked Input Fields View or Multiplication Input Fields View. One of them should be selected in order to use the module correctly.'),
'name' => 'designtypeA',
'required' => true,
'class' => 't',
'is_bool' => false,
'values' => array(
array(
'id' => 'active_on',
'value' => 'design1',
'label' => $this->l('Stacked Input Fields View'),
),
array(
'id' => 'active_off',
'value' => 'design2',
'label' => $this->l('Multiplication Input Fields View'),
),
),
),
array(
'type' => 'radio',
'label' => $this->l('Measurement Unit Type'),
'desc' => $this->l('The module allows two types of measurement unit system: English (standard) and Metric unit systems. One of them should be selected in order to use the module correctly.'),
'name' => 'unittypeA',
'required' => true,
'class' => 't',
'is_bool' => false,
'values' => array(
array(
'id' => 'active_on0',
'value' => 'english',
'label' => $this->l('English'),
),
array(
'id' => 'active_off0',
'value' => 'metric',
'label' => $this->l('Metric'),
),
),
),
array(
'type' => 'radio',
'label' => $this->l('Decimal Separator Type'),
'desc' => $this->l('The module allows two types of decimal separator: Comma Separator and Point Separator. Point separator is the default value. One of them should be selected in order to use the module correctly. You cannot use comma separator in currency and point separator in the module at the same time. They are to be synchronized. (Valid for Prestashop 1.7 and upper)'),
'name' => 'decimaltypeA',
'required' => true,
'class' => 't',
'is_bool' => false,
'values' => array(
array(
'id' => 'active_on1',
'value' => 'point',
'label' => $this->l('Point Separator'),
),
array(
'id' => 'active_off1',
'value' => 'comma',
'label' => $this->l('Comma Separator'),
),
),
),
array(
'type' => 'radio',
'label' => $this->l('Dimension Display Type'),
'desc' => $this->l('The module allows two types of dimension display: Calculated total display enabled or calculated total display disabled. One of them should be selected in order to use the module correctly.'),
'name' => 'dimensiondisplaytypeA',
'required' => true,
'class' => 't',
'is_bool' => false,
'values' => array(
array(
'id' => 'active_on2',
'value' => 'on',
'label' => $this->l('Calculated Total Display Enabled'),
),
array(
'id' => 'active_off2',
'value' => 'off',
'label' => $this->l('Calculated Total Display Disabled'),
),
),
),
array(
'type' => 'radio',
'label' => $this->l('Cart Update Option'),
'desc' => $this->l('If you enable the cart update option, then the dimension entered from the product page can be updated in the cart. May require custom coding if you are not using the default theme of Prestashop. If the option is disabled, customers are not allowed to update the dimension in the cart and will have a notification message.'),
'name' => 'cartupdateA',
'required' => true,
'class' => 't',
'is_bool' => false,
'values' => array(
array(
'id' => 'active_on3',
'value' => 'on',
'label' => $this->l('Enabled'),
),
array(
'id' => 'active_off3',
'value' => 'off',
'label' => $this->l('Disabled'),
),
),
),
array(
'type' => 'select',
'label' => $this->l('Reference Product'),
'hint' => $this->l('Reference product for newly created products'),
'name' => 'referenceProductA',
'class' => 't',
'options' => array(
'query' => $options,
'id' => 'id_product',
'name' => 'name',
),
'desc' => $this->l('If a product is selected, the newly created products will automatically have the same module configurations based on this reference product.'),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
),
);
$available_languages = LanguageCore::getLanguages();
foreach ($available_languages as $a_language) {
array_push($fields_form[0]['form']['input'], array(
'type' => 'text',
'label' => $a_language['name'],
'name' => $a_language['id_lang'],
'class' => 'lg',
'required' => true,
'desc' => $this->l('Please enter the short text description of the generated dimension. This description will be displayed in the invoice under the regarding product line. For ex: Dimension'),
));
}
$helper = new HelperForm();
/* Module, token and currentIndex */
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
/* Language */
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
/* Title and toolbar */
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit' . $this->name;
$helper->toolbar_btn = array(
'save' => array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name .
'&token=' . Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list'),
),
);
/* Load current value */
$available_languages = LanguageCore::getLanguages();
$index = Configuration::get('WD_CUSTOMIZATION_INDEX');
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
$helper->fields_value['designtypeA'] = Configuration::get('squaremeter_designtype', null, $idShopGroup, $idShop);
$helper->fields_value['unittypeA'] = Configuration::get('squaremeter_unittype', null, $idShopGroup, $idShop);
$helper->fields_value['decimaltypeA'] = Configuration::get('squaremeter_decimaltype', null, $idShopGroup, $idShop);
$helper->fields_value['dimensiondisplaytypeA'] = Configuration::get('squaremeter_dimensiondisplaytype', null, $idShopGroup, $idShop);
$helper->fields_value['cartupdateA'] = Configuration::get('squaremeter_cartupdate', null, $idShopGroup, $idShop);
$helper->fields_value['referenceProductA'] = Configuration::get('squaremeter_referenceProduct', null, $idShopGroup, $idShop);
foreach ($available_languages as $a_language) {
$sql = 'SELECT `name` FROM `' . pSQL(_DB_PREFIX_) . 'customization_field_lang` WHERE `id_customization_field` = ' . $index . ' AND `id_lang` = ' . $a_language['id_lang'] . ' AND `id_shop`= ' . $idShop;
if (Db::getInstance()->ExecuteS($sql)) {
$helper->fields_value[$a_language['id_lang']] = Db::getInstance()->ExecuteS($sql)[0]['name']; //get the value for the shop id
}
}
} else {
$idShop = 1;
$helper->fields_value['designtypeA'] = Configuration::get('squaremeter_designtype');
$helper->fields_value['unittypeA'] = Configuration::get('squaremeter_unittype');
$helper->fields_value['decimaltypeA'] = Configuration::get('squaremeter_decimaltype');
$helper->fields_value['dimensiondisplaytypeA'] = Configuration::get('squaremeter_dimensiondisplaytype');
$helper->fields_value['cartupdateA'] = Configuration::get('squaremeter_cartupdate');
$helper->fields_value['referenceProductA'] = Configuration::get('squaremeter_referenceProduct');
foreach ($available_languages as $a_language) {
$sql = 'SELECT `name` FROM `' . pSQL(_DB_PREFIX_) . 'customization_field_lang` WHERE `id_customization_field` = ' . $index . ' AND `id_lang` = ' . $a_language['id_lang'] . ' AND `id_shop`= ' . $idShop;
if (Db::getInstance()->ExecuteS($sql)) {
$helper->fields_value[$a_language['id_lang']] = Db::getInstance()->ExecuteS($sql)[0]['name']; //get the value for the shop id
}
}
}
return $helper->generateForm($fields_form);
}
public function getImageSrc($id_product)
{
$path = dirname(__FILE__);
if (strpos(__FILE__, 'Module.php') !== false) {
$path .= '/../modules/' . $this->name;
}
$image_src = '';
if (file_exists($path . '/views/img/uploads/' . $id_product . '.jpg')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.jpg';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.jpeg')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.jpeg';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.JPG')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.JPG';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.JPEG')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.JPEG';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.gif')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.gif';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.tif')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.tif';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.png')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.png';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.PNG')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.PNG';
}
if (file_exists($path . '/views/img/uploads/' . $id_product . '.bmp')) {
$image_src = '/modules/squaremeter/views/img/uploads/' . $id_product . '.bmp';
}
return $image_src;
}
public function hookDisplayAdminProductsExtra($params)
{
$path = dirname(__FILE__);
if (strpos(__FILE__, 'Module.php') !== false) {
$path .= '/../modules/' . $this->name;
}
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
} else {
$idShop = 1;
}
$id_product = $params['id_product'];
$attributesListProduct = array();
$attributesListProduct = $this->getAttributesGroupsProduct($id_product);
foreach ($attributesListProduct as $key => $row) {
unset($attributesListProduct[$key]['id_product_attribute']);
}
$attributesListProduct = array_unique($attributesListProduct, SORT_REGULAR);
if (!Combination::isFeatureActive() || !$attributesListProduct) {
$attributesListProduct[0]['id_attribute_group'] = 0;
$attributesListProduct[0]['public_name'] = $this->l('No Attibutes Available');
}
$this->context->smarty->assign(array(
'admintab_attributesListProduct' => $attributesListProduct,
));
$sample_obj = SquaremeterAdmin::loadByIdProduct($id_product, $idShop);
if (!empty($sample_obj) && isset($sample_obj->id)) {
$this->context->smarty->assign(array(
'admintab_display' => $sample_obj->displaycalculator,
'admintab_picture' => $sample_obj->displaypicture,
'admintab_type' => $sample_obj->calculationtype,
'admintab_addquan' => $sample_obj->additionalquantity,
'admintab_directinput' => $sample_obj->directinput,
'admintab_dispquan' => $sample_obj->displayquantity,
'admintab_ratio' => $sample_obj->ratio,
'admintab_dispprice' => $sample_obj->displayprice,
'admintab_reserve' => $sample_obj->displayreserve,
'admintab_unit_baseprice' => $sample_obj->unit_baseprice,
'admintab_startingprice' => $sample_obj->displaystartingprice,
'admintab_extrafee' => $sample_obj->displayextrafee,
'admintab_extrafee_select' => $sample_obj->displayextrafeeselect,
'admintab_waste' => $sample_obj->displaywaste,
'admintab_waste_select' => $sample_obj->displaywasteselect,
'admintab_attselect' => $sample_obj->attselect,
'admintab_conversion' => $sample_obj->conversion,
'admintab_secconversionselect' => $sample_obj->secconversionselect,
'admintab_secconversion' => $sample_obj->secconversion,
'admintab_conversion_unit' => $sample_obj->conversionunit,
'admintab_attribute' => $sample_obj->attribute,
'admintab_attribute_unit' => $sample_obj->attributeunit,
'step' => $sample_obj->step,
'disableapplet' => $sample_obj->disableapplet,
'allow_ordering_from_listing' => $sample_obj->allow_ordering_from_listing,
'admintab_minheight' => $sample_obj->minheight,
'admintab_maxheight' => $sample_obj->maxheight,
'admintab_maxheight_unit' => $sample_obj->maxheightunit,
'admintab_heightcheck' => $sample_obj->heightcheck,
'step_height' => $sample_obj->step_height,
'admintab_minwidth' => $sample_obj->minwidth,
'admintab_maxwidth' => $sample_obj->maxwidth,
'admintab_maxwidth_unit' => $sample_obj->maxwidthunit,
'admintab_widthcheck' => $sample_obj->widthcheck,
'step_width' => $sample_obj->step_width,
'admintab_mindepth' => $sample_obj->mindepth,
'admintab_maxdepth' => $sample_obj->maxdepth,
'admintab_maxdepth_unit' => $sample_obj->maxdepthunit,
'admintab_depthcheck' => $sample_obj->depthcheck,
'step_depth' => $sample_obj->step_depth,
'admintab_minweight' => $sample_obj->minweight,
'admintab_maxweight' => $sample_obj->maxweight,
'admintab_maxweight_unit' => $sample_obj->maxweightunit,
'admintab_weightcheck' => $sample_obj->weightcheck,
'module_dir' => $path,
'psversion' => _PS_VERSION_,
'id_product' => $id_product,
'id_shop' => $idShop,
'image_src' => $this->getImageSrc($id_product),
));
}
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
if (Configuration::get('squaremeter_unittype', null, $idShopGroup, $idShop) == 'metric') {
return $this->display(__FILE__, 'views/templates/admin/admintab.tpl');
} else {
return $this->display(__FILE__, 'views/templates/admin/admintab_e.tpl');
}
} else {
$idShop = 1;
if (Configuration::get('squaremeter_unittype') == 'metric') {
return $this->display(__FILE__, 'views/templates/admin/admintab.tpl');
} else {
return $this->display(__FILE__, 'views/templates/admin/admintab_e.tpl');
}
}
}
public function getAttributesGroupsProduct($id_product, $id_lang = null)
{
if (!Combination::isFeatureActive()) {
return array();
}
if (null === $id_lang) {
$id_lang = Context::getContext()->language->id;
}
$sql = 'SELECT ag.`id_attribute_group`, agl.`name`, agl.`public_name`,
product_attribute_shop.`id_product_attribute`
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
' . Shop::addSqlAssociation('product_attribute', 'pa') . '
' . Product::sqlStock('pa', 'pa') . '
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute`)
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group`)
' . Shop::addSqlAssociation('attribute', 'a') . '
WHERE pa.`id_product` = ' . (int) $id_product . '
AND al.`id_lang` = ' . (int) $id_lang . '
AND agl.`id_lang` = ' . (int) $id_lang . '
GROUP BY id_attribute_group, id_product_attribute
ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC';
return Db::getInstance()->executeS($sql);
}
public function hookActionProductUpdate($params)
{
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
} else {
$idShop = 1;
}
$id_product = $params['id_product'];
$sample_obj = SquaremeterAdmin::loadByIdProduct($id_product, $idShop);
$sample_obj->displaycalculator = Tools::getValue('squaremeter_display');
$sample_obj->displaypicture = Tools::getValue('squaremeter_picture');
if ((Tools::getValue('calculation_type') != '')) {
$sample_obj->calculationtype = Tools::getValue('calculation_type');
}
$sample_obj->additionalquantity = Tools::getValue('additional_quantity');
$sample_obj->directinput = Tools::getValue('direct_input');
if ((Tools::getValue('display_quantity') != '')) {
$sample_obj->displayquantity = Tools::getValue('display_quantity');
}
$sample_obj->ratio = Tools::getValue('ratio');
if ((Tools::getValue('display_price') != '')) {
$sample_obj->displayprice = Tools::getValue('display_price');
}
$sample_obj->displayreserve = Tools::getValue('reserve');
$sample_obj->unit_baseprice = Tools::getValue('unit_baseprice');
$sample_obj->displaystartingprice = Tools::getValue('startingprice');
$sample_obj->displayextrafee = Tools::getValue('displayextrafee');
$sample_obj->displayextrafeeselect = Tools::getValue('extrafee_select');
$sample_obj->displaywaste = Tools::getValue('displaywaste');
$sample_obj->displaywasteselect = Tools::getValue('waste_select');
$sample_obj->attselect = Tools::getValue('attselect');
if ((Tools::getValue('conversion') != '')) {
$sample_obj->conversion = Tools::getValue('conversion');
}
$sample_obj->secconversionselect = Tools::getValue('secconversionselect');
if ($sample_obj->secconversionselect) {
if ((Tools::getValue('secconversion') != '')) {
$sample_obj->secconversion = Tools::getValue('secconversion');
}
} else {
$sample_obj->secconversion = '';
}
if ((Tools::getValue('conversion_unit') != '')) {
$sample_obj->conversionunit = Tools::getValue('conversion_unit');
}
if ((Tools::getValue('attribute') != '')) {
$sample_obj->attribute = Tools::getValue('attribute');
}
if ((Tools::getValue('attribute_unit') != '')) {
$sample_obj->attributeunit = Tools::getValue('attribute_unit');
}
$sample_obj->step = Tools::getValue('step');
$sample_obj->disableapplet = Tools::getValue('disableapplet');
$sample_obj->allow_ordering_from_listing = Tools::getValue('allow_ordering_from_listing');
if ((Tools::getValue('minimum_height') != '')) {
$sample_obj->minheight = Tools::getValue('minimum_height');
}
if ((Tools::getValue('maximum_height') != '')) {
$sample_obj->maxheight = Tools::getValue('maximum_height');
}
if ((Tools::getValue('maximum_height_unit') != '')) {
$sample_obj->maxheightunit = Tools::getValue('maximum_height_unit');
}
$sample_obj->heightcheck = Tools::getValue('heightcheck');
$sample_obj->step_height = Tools::getValue('step_height');
if ((Tools::getValue('minimum_width') != '')) {
$sample_obj->minwidth = Tools::getValue('minimum_width');
}
if ((Tools::getValue('maximum_width') != '')) {
$sample_obj->maxwidth = Tools::getValue('maximum_width');
}
if ((Tools::getValue('maximum_width_unit') != '')) {
$sample_obj->maxwidthunit = Tools::getValue('maximum_width_unit');
}
$sample_obj->widthcheck = Tools::getValue('widthcheck');
$sample_obj->step_width = Tools::getValue('step_width');
if ((Tools::getValue('minimum_depth') != '')) {
$sample_obj->mindepth = Tools::getValue('minimum_depth');
}
if ((Tools::getValue('maximum_depth') != '')) {
$sample_obj->maxdepth = Tools::getValue('maximum_depth');
}
if ((Tools::getValue('maximum_depth_unit') != '')) {
$sample_obj->maxdepthunit = Tools::getValue('maximum_depth_unit');
}
$sample_obj->depthcheck = Tools::getValue('depthcheck');
$sample_obj->step_depth = Tools::getValue('step_depth');
if ((Tools::getValue('minimum_weight') != '')) {
$sample_obj->minweight = Tools::getValue('minimum_weight');
}
if ((Tools::getValue('maximum_weight') != '')) {
$sample_obj->maxweight = Tools::getValue('maximum_weight');
}
if ((Tools::getValue('maximum_weight_unit') != '')) {
$sample_obj->maxweightunit = Tools::getValue('maximum_weight_unit');
}
$sample_obj->weightcheck = Tools::getValue('weightcheck');
//Keep this fix or unit inconsistency is created.
if ($sample_obj->attselect == '') {
$sample_obj->attributeunit = $sample_obj->conversionunit;
}
$sample_obj->id_product = $id_product;
$sample_obj->id_shop = $idShop;
$referenceProductId = Configuration::get('squaremeter_referenceProduct');
$referenceCreatedCheck = Configuration::get('squaremeter_lastcreatedwithref');
if (!empty($sample_obj) && isset($sample_obj->id) && ($referenceCreatedCheck != $id_product)) {
$sample_obj->update();
} else {
Configuration::updateValue($this->name . '_lastcreatedwithref', '');
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'squaremeteradmin WHERE id_shop = ' . $idShop . ' AND id_product = ' . $id_product;
$row = Db::getInstance()->getRow($sql);
if (!$row) {
if ($sample_obj->displaycalculator) {
$sample_obj->add();
} elseif ((!$sample_obj->displaycalculator) && ($referenceProductId)) {
$this->createProductFromReference($id_product);
Configuration::updateValue($this->name . '_lastcreatedwithref', $id_product);
}
}
}
}
public function hookActionProductAdd($params)
{
$id_product = $params['id_product'];
$this->createProductFromReference($id_product);
}
public function createProductFromReference($id_product)
{
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
} else {
$idShop = 1;
}
$referenceProductId = Configuration::get('squaremeter_referenceProduct');
$dimension_data = Db::getInstance()->executeS('SELECT *
FROM `' . _DB_PREFIX_ . 'squaremeteradmin` pa
WHERE pa.`id_product` = ' . (int) $referenceProductId . ' AND
pa.`id_shop` = ' . (int) $idShop);
$sample_obj = SquaremeterAdmin::loadByIdProduct($id_product, $idShop);
if (($referenceProductId) && (!$sample_obj->calculationtype)) {
Db::getInstance()->insert('squaremeteradmin', array(
'id_shop' => (int) $idShop,
'id_product' => (int) $id_product,
'displaycalculator' => pSQL($dimension_data[0]['displaycalculator']),
'displaypicture' => pSQL($dimension_data[0]['displaypicture']),
'calculationtype' => pSQL($dimension_data[0]['calculationtype']),
'additionalquantity' => pSQL($dimension_data[0]['additionalquantity']),
'directinput' => pSQL($dimension_data[0]['directinput']),
'displayquantity' => pSQL($dimension_data[0]['displayquantity']),
'ratio' => pSQL($dimension_data[0]['ratio']),
'displayprice' => pSQL($dimension_data[0]['displayprice']),
'displayreserve' => pSQL($dimension_data[0]['displayreserve']),
'unit_baseprice' => pSQL($dimension_data[0]['unit_baseprice']),
'displaystartingprice' => pSQL($dimension_data[0]['displaystartingprice']),
'displayextrafee' => pSQL($dimension_data[0]['displayextrafee']),
'displayextrafeeselect' => pSQL($dimension_data[0]['displayextrafeeselect']),
'displaywaste' => pSQL($dimension_data[0]['displaywaste']),
'displaywasteselect' => pSQL($dimension_data[0]['displaywasteselect']),
'conversion' => pSQL($dimension_data[0]['conversion']),
'secconversionselect' => pSQL($dimension_data[0]['secconversionselect']),
'secconversion' => pSQL($dimension_data[0]['secconversion']),
'conversionunit' => pSQL($dimension_data[0]['conversionunit']),
'attribute' => pSQL($dimension_data[0]['attribute']),
'attributeunit' => pSQL($dimension_data[0]['attributeunit']),
'step' => pSQL($dimension_data[0]['step']),
'disableapplet' => pSQL($dimension_data[0]['disableapplet']),
'allow_ordering_from_listing' => pSQL($dimension_data[0]['allow_ordering_from_listing']),
'attselect' => pSQL($dimension_data[0]['attselect']),
'minheight' => pSQL($dimension_data[0]['minheight']),
'maxheight' => pSQL($dimension_data[0]['maxheight']),
'maxheightunit' => pSQL($dimension_data[0]['maxheightunit']),
'heightcheck' => pSQL($dimension_data[0]['heightcheck']),
'step_height' => pSQL($dimension_data[0]['step_height']),
'minwidth' => pSQL($dimension_data[0]['minwidth']),
'maxwidth' => pSQL($dimension_data[0]['maxwidth']),
'maxwidthunit' => pSQL($dimension_data[0]['maxwidthunit']),
'widthcheck' => pSQL($dimension_data[0]['widthcheck']),
'step_width' => pSQL($dimension_data[0]['step_width']),
'mindepth' => pSQL($dimension_data[0]['mindepth']),
'maxdepth' => pSQL($dimension_data[0]['maxdepth']),
'maxdepthunit' => pSQL($dimension_data[0]['maxdepthunit']),
'depthcheck' => pSQL($dimension_data[0]['depthcheck']),
'step_depth' => pSQL($dimension_data[0]['step_depth']),
'minweight' => pSQL($dimension_data[0]['minweight']),
'maxweight' => pSQL($dimension_data[0]['maxweight']),
'maxweightunit' => pSQL($dimension_data[0]['maxweightunit']),
'weightcheck' => pSQL($dimension_data[0]['weightcheck']),
));
}
}
public function hookActionObjectCartUpdateBefore($object)
{
if (Tools::getValue('discretion') == 'on') {
if (Tools::getValue('cartsource')) {
$suffix = '_' . Tools::getValue('id_product');
} else {
$suffix = '';
}
$dimension = Tools::getValue('dim' . $suffix);
$quantity = Tools::getValue('qty' . $suffix);
$extrafee = Tools::getValue('extrafeevalue' . $suffix);
$waste = Tools::getValue('wastevalue' . $suffix);
$pricetotal = Tools::getValue('product_total_price_calc' . $suffix);
$id_product_attribute = Tools::getValue('id_product_attribute' . $suffix);
if ($id_product_attribute == null) {
$sql = 'select * from ' . pSQL(_DB_PREFIX_) . 'cart_product ORDER BY date_add desc LIMIT 1';
$query = Db::getInstance()->executeS($sql);
$last_id_product_attribute = $query[0]['id_product_attribute'];
if ($last_id_product_attribute != 0) {
$id_product_attribute = $last_id_product_attribute;
}
}
if ($id_product_attribute == null) {
$id_product_attribute = 0;
}
if (!empty($dimension)) {
$obj_cart = $object['object'];
$id_product = Tools::getValue('id_product');
$index = Configuration::get('WD_CUSTOMIZATION_INDEX');
$obj_cart->addTextFieldToProductOverride($id_product, $id_product_attribute, $index, 1, $dimension, 0, 0);
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
} else {
$idShop = 1;
}
$product_dimension_settings = Db::getInstance()->executeS('SELECT *
FROM `' . _DB_PREFIX_ . 'squaremeteradmin` pa
WHERE pa.`id_product` = ' . (int) $id_product . ' AND
pa.`id_shop` = ' . (int) $idShop);
$existing_customization = Db::getInstance()->executeS('
SELECT cu.`id_customization`, cd.`index`, cd.`value`, cd.`type` FROM `' . pSQL(_DB_PREFIX_) . 'customization` cu
LEFT JOIN `' . pSQL(_DB_PREFIX_) . 'customized_data` cd
ON cu.`id_customization` = cd.`id_customization`
WHERE cu.id_cart = ' . (int) $obj_cart->id . '
AND cu.id_product = ' . (int) $id_product . '
AND cd.index = ' . (int) $index . ' AND cd.type = 1 AND cd.value = "' . pSQL($dimension) . '"
AND in_cart = 0 order by cu.id_customization desc limit 1');
if (!empty($existing_customization)) {
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `calculationtype` = "' . pSQL($product_dimension_settings[0]['calculationtype']) . '" WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `extra_fee` = "' . (float) $extrafee . '" WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `waste` = "' . (float) $waste . '" WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `directinput` = ' . (float) Tools::getValue('directinput' . $suffix) . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `width_module` = ' . (float) Tools::getValue('qty_alt' . $suffix) . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `height_module` = ' . (float) Tools::getValue('qty_alth') . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `depth_module` = ' . (float) Tools::getValue('qty_altd') . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
if ($product_dimension_settings[0]['calculationtype'] == 'weight') {
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `weight_module` = ' . (float) Tools::getValue('qty_alt' . $suffix) . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
}
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `unittype_module` = "' . pSQL($product_dimension_settings[0]['conversionunit']) . '" WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `total_dimension` = ' . (float) Tools::getValue('calculated_total' . $suffix) . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `grand_total_dimension` = ' . (float) Tools::getValue('grand_calculated_total' . $suffix) . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `converted_ea` = ' . (float) Tools::getValue('converted_ea' . $suffix) . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'cart_product SET `id_customization` = ' . (int) $existing_customization[0]['id_customization'] . ' WHERE `id_cart` =' . (int) $obj_cart->id . ' AND `id_product` =' . (int) $id_product . ' ORDER BY date_add desc LIMIT 1');
Db::getInstance()->execute('UPDATE ' . pSQL(_DB_PREFIX_) . 'customized_data SET `price` = ' . (float) $pricetotal . ' WHERE `id_customization` =' . (int) $existing_customization[0]['id_customization'] . ' AND `index` =' . (int) $index);
}
$obj = new Product((int) $id_product, null);
$obj->customizable = true;
}
}
}
public function hookDisplayHeader()
{
include dirname(__FILE__) . '/controllers/front/frontcartdata.php';
$this->context->controller->addCSS($this->_path . 'views/css/front.css', 'all');
if (!$this->context->controller instanceof CartController && !$this->context->controller instanceof ProductController) {
$this->context->controller->addJS($this->_path . '/views/js/product_front_listing.js');
}
if ($this->context->controller instanceof CartController) {
$this->smarty->assign('page_name', 'cart');
}
if ($this->context->controller instanceof ProductController) {
$this->smarty->assign('page_name', 'product');
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
} else {
$idShop = 1;
}
$id_product = Tools::getValue('id_product');
$sample_obj = SquaremeterAdmin::loadByIdProduct($id_product, $idShop);
if ($sample_obj->displaycalculator) {
if (!empty($sample_obj) && isset($sample_obj->id)) {
$this->smarty->assign(array(
'default_lang' => (int) $this->context->language->id,
'id_lang' => $this->context->language->id,
'admintab_display' => $sample_obj->displaycalculator,
'admintab_picture' => $sample_obj->displaypicture,
'admintab_type' => $sample_obj->calculationtype,
'admintab_addquan' => $sample_obj->additionalquantity,
'admintab_directinput' => $sample_obj->directinput,
'admintab_dispquan' => $sample_obj->displayquantity,
'admintab_ratio' => $sample_obj->ratio,
'admintab_dispprice' => $sample_obj->displayprice,
'admintab_reserve' => $sample_obj->displayreserve,
'admintab_unit_baseprice' => $sample_obj->unit_baseprice,
'admintab_startingprice' => $sample_obj->displaystartingprice,
'admintab_extrafee' => $sample_obj->displayextrafee,
'admintab_extrafee_select' => $sample_obj->displayextrafeeselect,
'admintab_waste' => $sample_obj->displaywaste,
'admintab_waste_select' => $sample_obj->displaywasteselect,
'admintab_attselect' => $sample_obj->attselect,
'admintab_secconversionselect' => $sample_obj->secconversionselect,
'admintab_conversion' => $sample_obj->conversion ? $sample_obj->conversion : '1',
'admintab_secconversion' => $sample_obj->secconversion ? $sample_obj->secconversion : '1',
'admintab_conversion_unit' => $sample_obj->conversionunit,
'admintab_attribute' => $sample_obj->attribute,
'admintab_attribute_unit' => $sample_obj->attributeunit,
'step' => $sample_obj->step ? $sample_obj->step : '0.1',
'disableapplet' => $sample_obj->disableapplet,
'allow_ordering_from_listing' => $sample_obj->allow_ordering_from_listing,
'admintab_minheight' => $sample_obj->minheight ? $sample_obj->minheight : '0',
'admintab_maxheight' => $sample_obj->maxheight ? $sample_obj->maxheight : '99999999999999',
'admintab_maxheight_unit' => $sample_obj->maxheightunit ? $sample_obj->maxheightunit : 'm',
'admintab_heightcheck' => $sample_obj->heightcheck,
'step_height' => $sample_obj->step_height ? $sample_obj->step_height : $sample_obj->step,
'admintab_minwidth' => $sample_obj->minwidth ? $sample_obj->minwidth : '0',
'admintab_maxwidth' => $sample_obj->maxwidth ? $sample_obj->maxwidth : '99999999999999',
'admintab_maxwidth_unit' => $sample_obj->maxwidthunit ? $sample_obj->maxwidthunit : 'm',
'admintab_widthcheck' => $sample_obj->widthcheck,
'step_width' => $sample_obj->step_width ? $sample_obj->step_width : $sample_obj->step,
'admintab_mindepth' => $sample_obj->mindepth ? $sample_obj->mindepth : '0',
'admintab_maxdepth' => $sample_obj->maxdepth ? $sample_obj->maxdepth : '99999999999999',
'admintab_maxdepth_unit' => $sample_obj->maxdepthunit ? $sample_obj->maxdepthunit : 'm',
'admintab_depthcheck' => $sample_obj->depthcheck,
'step_depth' => $sample_obj->step_depth ? $sample_obj->step_depth : $sample_obj->step,
'admintab_minweight' => $sample_obj->minweight ? $sample_obj->minweight : '0',
'admintab_maxweight' => $sample_obj->maxweight ? $sample_obj->maxweight : '99999999999999',
'admintab_maxweight_unit' => $sample_obj->maxweightunit ? $sample_obj->maxweightunit : 'kg',
'admintab_weightcheck' => $sample_obj->weightcheck,
'psversion' => _PS_VERSION_,
'image_src' => $this->getImageSrc($id_product),
));
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
$this->smarty->assign(array(
'design_type' => Configuration::get('squaremeter_designtype', null, $idShopGroup, $idShop),
'unittype' => Configuration::get('squaremeter_unittype', null, $idShopGroup, $idShop),
'decimaltype' => Configuration::get('squaremeter_decimaltype', null, $idShopGroup, $idShop),
'dimensiondisplaytype' => Configuration::get('squaremeter_dimensiondisplaytype', null, $idShopGroup, $idShop),
'cartupdate' => Configuration::get('squaremeter_cartupdate', null, $idShopGroup, $idShop),
));
$shop_designtype = Configuration::get('squaremeter_designtype', null, $idShopGroup, $idShop);
$shop_unittype = Configuration::get('squaremeter_unittype', null, $idShopGroup, $idShop);
$shop_decimaltype = Configuration::get('squaremeter_decimaltype', null, $idShopGroup, $idShop);
$shop_dimensiondisplaytype = Configuration::get('squaremeter_dimensiondisplaytype', null, $idShopGroup, $idShop);
$shop_cartupdate = Configuration::get('squaremeter_cartupdate', null, $idShopGroup, $idShop);
} else {
$idShop = 1;
$this->smarty->assign(array(
'design_type' => Configuration::get('squaremeter_designtype'),
'unittype' => Configuration::get('squaremeter_unittype'),
'decimaltype' => Configuration::get('squaremeter_decimaltype'),
'dimensiondisplaytype' => Configuration::get('squaremeter_dimensiondisplaytype'),
'cartupdate' => Configuration::get('squaremeter_cartupdate'),
));
$shop_designtype = Configuration::get('squaremeter_designtype');
$shop_unittype = Configuration::get('squaremeter_unittype');
$shop_decimaltype = Configuration::get('squaremeter_decimaltype');
$shop_dimensiondisplaytype = Configuration::get('squaremeter_dimensiondisplaytype');
$shop_cartupdate = Configuration::get('squaremeter_cartupdate');
}
}
Media::addJsDef(array(
'step_width' => $sample_obj->step_width ? $sample_obj->step_width : $sample_obj->step,
'step_height' => $sample_obj->step_height ? $sample_obj->step_height : $sample_obj->step,
'step' => $sample_obj->step ? $sample_obj->step : '0.1',
));
$this->context->controller->registerJavascript('modules-squaremeter1', 'modules/' . $this->name . '/views/js/jquery-1.12.4.js', array('position' => 'head', 'priority' => 150));
$this->context->controller->registerJavascript('modules-squaremeter2', 'modules/' . $this->name . '/views/js/jquery-ui.js', array('position' => 'head', 'priority' => 151));
$this->context->controller->registerJavascript('modules-squaremeter3', 'modules/' . $this->name . '/views/js/product_front.js', array('position' => 'bottom', 'priority' => 152));
$this->context->controller->registerJavascript('modules-squaremeter4', 'modules/' . $this->name . '/views/js/format.min.js', array('position' => 'head', 'priority' => 153));
$this->context->controller->addCSS(($this->_path) . 'views/css/jquery-ui.css', 'all');
if ($sample_obj->calculationtype == 'surface') {
$this->context->controller->addCSS(($this->_path) . 'views/css/' . $shop_designtype . '/squaremeter_surface.css', 'all');
$header_applet = $this->display(__FILE__, 'views/templates/front/header_surface.tpl');
} else if ($sample_obj->calculationtype == 'volume') {
$this->context->controller->addCSS(($this->_path) . 'views/css/' . $shop_designtype . '/squaremeter_volume.css', 'all');
$header_applet = $this->display(__FILE__, 'views/templates/front/header_volume.tpl');
} else if ($sample_obj->calculationtype == 'linear') {
$this->context->controller->addCSS(($this->_path) . 'views/css/' . $shop_designtype . '/squaremeter_linear.css', 'all');
$header_applet = $this->display(__FILE__, 'views/templates/front/header_linear.tpl');
} else if ($sample_obj->calculationtype == 'perimeter') {
$this->context->controller->addCSS(($this->_path) . 'views/css/' . $shop_designtype . '/squaremeter_perimeter.css', 'all');
$header_applet = $this->display(__FILE__, 'views/templates/front/header_perimeter.tpl');
} else if ($sample_obj->calculationtype == 'weight') {
$this->context->controller->addCSS(($this->_path) . 'views/css/' . $shop_designtype . '/squaremeter_weight.css', 'all');
$header_applet = $this->display(__FILE__, 'views/templates/front/header_weight.tpl');
}
$header_global = $this->display(__FILE__, 'views/templates/front/header.tpl');
return $header_applet . $header_global;
}
}
}
public function hookproductActions($params)
{
$path = dirname(__FILE__);
if (strpos(__FILE__, 'Module.php') !== false) {
$path .= '/../modules/' . $this->name;
}
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
$this->smarty->assign(array(
'design_type' => Configuration::get('squaremeter_designtype', null, $idShopGroup, $idShop),
));
} else {
$idShop = 1;
$this->smarty->assign(array(
'design_type' => Configuration::get('squaremeter_designtype'),
));
}
$id_product = Tools::getValue('id_product');
$sample_obj = SquaremeterAdmin::loadByIdProduct($id_product, $idShop);
if (!empty($sample_obj) && isset($sample_obj->id)) {
$this->smarty->assign(array(
'default_lang' => (int) $this->context->language->id,
'id_lang' => $this->context->language->id,
'admintab_display' => $sample_obj->displaycalculator,
'admintab_picture' => $sample_obj->displaypicture,
'admintab_type' => $sample_obj->calculationtype,
'admintab_addquan' => $sample_obj->additionalquantity,
'admintab_directinput' => $sample_obj->directinput,
'admintab_dispquan' => $sample_obj->displayquantity,
'admintab_ratio' => $sample_obj->ratio,
'admintab_dispprice' => $sample_obj->displayprice,
'admintab_reserve' => $sample_obj->displayreserve,
'admintab_unit_baseprice' => $sample_obj->unit_baseprice,
'admintab_startingprice' => $sample_obj->displaystartingprice,
'admintab_extrafee' => $sample_obj->displayextrafee,
'admintab_extrafee_select' => $sample_obj->displayextrafeeselect,
'admintab_waste' => $sample_obj->displaywaste,
'admintab_waste_select' => $sample_obj->displaywasteselect,
'admintab_attselect' => $sample_obj->attselect,
'admintab_secconversionselect' => $sample_obj->secconversionselect,
'admintab_conversion' => $sample_obj->conversion,
'admintab_secconversion' => $sample_obj->secconversion,
'admintab_conversion_unit' => $sample_obj->conversionunit,
'admintab_attribute' => $sample_obj->attribute,
'admintab_attribute_unit' => $sample_obj->attributeunit,
'step' => $sample_obj->step ? $sample_obj->step : '0.1',
'disableapplet' => $sample_obj->disableapplet,
'allow_ordering_from_listing' => $sample_obj->allow_ordering_from_listing,
'admintab_minheight' => $sample_obj->minheight ? $sample_obj->minheight : '0',
'admintab_maxheight' => $sample_obj->maxheight ? $sample_obj->maxheight : '99999999999999',
'admintab_maxheight_unit' => $sample_obj->maxheightunit ? $sample_obj->maxheightunit : 'm',
'admintab_heightcheck' => $sample_obj->heightcheck,
'step_height' => $sample_obj->step_height ? $sample_obj->step_height : $sample_obj->step,
'admintab_minwidth' => $sample_obj->minwidth ? $sample_obj->minwidth : '0',
'admintab_maxwidth' => $sample_obj->maxwidth ? $sample_obj->maxwidth : '99999999999999',
'admintab_maxwidth_unit' => $sample_obj->maxwidthunit ? $sample_obj->maxwidthunit : 'm',
'admintab_widthcheck' => $sample_obj->widthcheck,
'step_width' => $sample_obj->step_width ? $sample_obj->step_width : $sample_obj->step,
'admintab_mindepth' => $sample_obj->mindepth ? $sample_obj->mindepth : '0',
'admintab_maxdepth' => $sample_obj->maxdepth ? $sample_obj->maxdepth : '99999999999999',
'admintab_maxdepth_unit' => $sample_obj->maxdepthunit ? $sample_obj->maxdepthunit : 'm',
'admintab_depthcheck' => $sample_obj->depthcheck,
'step_depth' => $sample_obj->step_depth ? $sample_obj->step_depth : $sample_obj->step,
'admintab_minweight' => $sample_obj->minweight ? $sample_obj->minweight : '0',
'admintab_maxweight' => $sample_obj->maxweight ? $sample_obj->maxweight : '99999999999999',
'admintab_maxweight_unit' => $sample_obj->maxweightunit ? $sample_obj->maxweightunit : 'kg',
'admintab_weightcheck' => $sample_obj->weightcheck,
'module_dir' => $path,
'psversion' => _PS_VERSION_,
'image_src' => $this->getImageSrc($id_product),
));
}
if (Configuration::get('PS_CATALOG_MODE')) {
return;
}
if (($sample_obj->displaycalculator) && ($sample_obj->calculationtype == 'perimeter')) {
return $this->display(__FILE__, 'views/templates/front/product_page_perimeter.tpl');
}
if (($sample_obj->displaycalculator) && ($sample_obj->calculationtype == 'linear')) {
return $this->display(__FILE__, 'views/templates/front/product_page_linear.tpl');
}
if (($sample_obj->displaycalculator) && ($sample_obj->calculationtype == 'surface')) {
return $this->display(__FILE__, 'views/templates/front/product_page_surface.tpl');
}
if (($sample_obj->displaycalculator) && ($sample_obj->calculationtype == 'volume')) {
return $this->display(__FILE__, 'views/templates/front/product_page_volume.tpl');
}
if (($sample_obj->displaycalculator) && ($sample_obj->calculationtype == 'weight')) {
return $this->display(__FILE__, 'views/templates/front/product_page_weight.tpl');
} else {
}
}
public function hookdisplayFooterProduct($params)
{
return $this->hookproductActions($params);
}
public function hookBackOfficeHeader()
{
if (Tools::getValue('configure') == $this->name) {
$this->context->controller->addJS($this->_path . '/views/js/popup.js');
$this->context->controller->addCSS(($this->_path) . 'views/css/exportimport.css', 'all');
}
/* product_admin.js translations*/
Media::addJsDef(array(
'errort2' => $this->l('Width values should be number and/or decimals should be separated with dot.'),
'errort1' => $this->l('Height values should be number and/or decimals should be separated with dot.'),
'errort4' => $this->l('Depth values should be number and/or decimals should be separated with dot.'),
'errort8' => $this->l('Weight values should be number and/or decimals should be separated with dot.'),
'errort7' => $this->l('Either the combination feature is not active, attribute group is not selected or the product does not have any combinations.'),
'errort' => $this->l('Conversion value should be number and/or decimals should be separated with dot.'),
'error_height' => $this->l('Height unit must be set.'),
'error_width' => $this->l('Width unit must be set.'),
'error_depth' => $this->l('Depth unit must be set.'),
'error_weight' => $this->l('Weight unit must be set.'),
'errort4_' => $this->l('If calculator type is surface, then conversion units can only be mm2, cm2, dm2 or m2.'),
'errort3_' => $this->l('If calculator type is volume, then conversion units can only be mm3, cm3, dm3 or m3.'),
'errort6_' => $this->l('If calculator type is linear or perimeter, then conversion units can only be mm, cm, dm or m.'),
'errort9_' => $this->l('If calculator type is weight, then conversion units can only be cg, dg, g, dag, hg, kg or ton.'),
'errort4__' => $this->l('If calculator type is surface, then attribute units can only be mm2, cm2, dm2 or m2.'),
'errort3__' => $this->l('If calculator type is volume, then attribute units can only be mm3, cm3, dm3 or m3.'),
'errort6__' => $this->l('If calculator type is linear or perimeter, then attribute units can only be mm, cm, dm or m.'),
'errort7__' => $this->l('If calculator type is weight, then attribute units can only be be cg, dg, g, dag, hg, kg or ton.'),
'error_step' => $this->l('Step value should be number and/or decimals should be separated with dot.'),
'error_step_height' => $this->l('Step value should be number and/or decimals should be separated with dot.'),
'error_step_width' => $this->l('Step value should be number and/or decimals should be separated with dot.'),
'error_step_depth' => $this->l('Step value should be number and/or decimals should be separated with dot.'),
'allowed_images' => $this->l('Allowed image types'),
'H_W' => $this->l('Input format must be H:W'),
'H_W_D' => $this->l('Input format must be H:W:D'),
'error' => $this->l('Error'),
'quick_tip' => $this->l('Quick Tip'),
'volume_tip_message' => $this->l('Recommended volume applet settings are set!'),
'surface_tip_message' => $this->l('Recommended surface(area) applet settings are set!'),
'linear_tip_message' => $this->l('Recommended linear applet settings are set!'),
'perimeter_tip_message' => $this->l('Recommended perimeter applet settings are set!'),
'weight_tip_message' => $this->l('Recommended weight applet settings are set!'),
'dropdown_warning_message' => $this->l('options will be generated on page load [(max - min) / (step size)]. If you want to use dropdown box, less than 100 options are recommended to prevent 500 type server error.'),
));
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
$shop_unittype = Configuration::get('squaremeter_unittype', null, $idShopGroup, $idShop);
} else {
$idShop = 1;
$shop_unittype = Configuration::get('squaremeter_unittype');
}
if ($shop_unittype == 'metric') {
Media::addJsDef(array(
'errort4_' => $this->l('If calculator type is surface, then conversion units can only be mm2, cm2, dm2 or m2.'),
'errort3_' => $this->l('If calculator type is volume, then conversion units can only be mm3, cm3, dm3 or m3.'),
'errort6_' => $this->l('If calculator type is linear or perimeter, then conversion units can only be mm, cm, dm or m.'),
'errort9_' => $this->l('If calculator type is weight, then conversion units can only be cg, dg, g, dag, hg, kg or ton.'),
'errort4__' => $this->l('If calculator type is surface, then attribute units can only be mm2, cm2, dm2 or m2.'),
'errort3__' => $this->l('If calculator type is volume, then attribute units can only be mm3, cm3, dm3 or m3.'),
'errort6__' => $this->l('If calculator type is linear or perimeter, then attribute units can only be mm, cm, dm or m.'),
'errort7__' => $this->l('If calculator type is weight, then attribute units can only be cg, dg, g, dag, hg, kg or ton.'),
));
} else {
Media::addJsDef(array(
'errort4_' => $this->l('If calculator type is surface, then conversion units can only be in2, ft2, yd2 or acre.'),
'errort3_' => $this->l('If calculator type is volume, then conversion units can only be in3, ft3, yd3 or acre-feet.'),
'errort6_' => $this->l('If calculator type is linear or perimeter, then conversion units can only be in, ft, yd or acre.'),
'errort9_' => $this->l('If calculator type is weight, then conversion units can only be oz, lbs or tn.'),
'errort4__' => $this->l('If calculator type is surface, then attribute units can only be in2, ft2, yd2 or acre.'),
'errort3__' => $this->l('If calculator type is volume, then attribute units can only be in3, ft3, yd3 or acre-feet.'),
'errort6__' => $this->l('If calculator type is linear or perimeter, then attribute units can only be in, ft, yd or acre.'),
'errort7__' => $this->l('If calculator type is weight, then attribute units can only be oz, lbs or tn.'),
));
}
}
public function hookDisplayProductListReviews($params)
{
$path = dirname(__FILE__);
if (strpos(__FILE__, 'Module.php') !== false) {
$path .= '/../modules/' . $this->name;
}
if (Shop::isFeatureActive()) {
$idShop = (int) Context::getContext()->shop->id;
$idShopGroup = Shop::getContextShopGroupID(true);
$this->smarty->assign(array(
'design_type' => Configuration::get('squaremeter_designtype', null, $idShopGroup, $idShop),
));
} else {
$idShop = 1;
$this->smarty->assign(array(
'design_type' => Configuration::get('squaremeter_designtype'),
));
}
$id_product = $params['product']['id_product'];
$id_product_attribute = isset($params['product']['id_product_attribute']) ? $params['product']['id_product_attribute'] : '0';
$sample_obj = SquaremeterAdmin::loadByIdProduct($id_product, $idShop);
if ($sample_obj->minweight) {
$this->smarty->assign('min', $sample_obj->minweight);
} elseif ($sample_obj->minwidth) {
$this->smarty->assign('min', $sample_obj->minwidth);
} else {
$this->smarty->assign('min', 0);
}
if ($sample_obj->maxweight) {
$this->smarty->assign('max', $sample_obj->maxweight);
} elseif ($sample_obj->maxwidth) {
$this->smarty->assign('max', $sample_obj->maxwidth);
} else {
$this->smarty->assign('max', 9999);
}
$this->smarty->assign(array(
'default_lang' => (int) $this->context->language->id,
'id_lang' => $this->context->language->id,
'price' => $params['product']['price_amount'],
'admintab_display' => $sample_obj->displaycalculator,
'admintab_picture' => $sample_obj->displaypicture,
'admintab_type' => $sample_obj->calculationtype,
'admintab_addquan' => $sample_obj->additionalquantity,
'admintab_directinput' => $sample_obj->directinput,
'admintab_dispquan' => $sample_obj->displayquantity,
'admintab_ratio' => $sample_obj->ratio,
'admintab_dispprice' => $sample_obj->displayprice,
'admintab_reserve' => $sample_obj->displayreserve,
'admintab_unit_baseprice' => $sample_obj->unit_baseprice,
'admintab_startingprice' => $sample_obj->displaystartingprice,
'admintab_extrafee' => $sample_obj->displayextrafee,
'admintab_extrafee_select' => $sample_obj->displayextrafeeselect,
'admintab_waste' => $sample_obj->displaywaste,
'admintab_waste_select' => $sample_obj->displaywasteselect,
'admintab_attselect' => $sample_obj->attselect,
'admintab_secconversionselect' => $sample_obj->secconversionselect,
'admintab_conversion' => $sample_obj->conversion,
'admintab_secconversion' => $sample_obj->secconversion,
'admintab_conversion_unit' => $sample_obj->conversionunit,
'admintab_attribute' => $sample_obj->attribute,
'admintab_attribute_unit' => $sample_obj->attributeunit,
'step' => $sample_obj->step ? $sample_obj->step : '0.1',
'disableapplet' => $sample_obj->disableapplet,
'allow_ordering_from_listing' => $sample_obj->allow_ordering_from_listing,
'admintab_maxheight_unit' => $sample_obj->maxheightunit ? $sample_obj->maxheightunit : 'm',
'admintab_heightcheck' => $sample_obj->heightcheck,
'step_height' => $sample_obj->step_height ? $sample_obj->step_height : $sample_obj->step,
'admintab_maxwidth_unit' => $sample_obj->maxwidthunit ? $sample_obj->maxwidthunit : 'm',
'admintab_widthcheck' => $sample_obj->widthcheck,
'step_width' => $sample_obj->step_width ? $sample_obj->step_width : $sample_obj->step,
'admintab_maxdepth_unit' => $sample_obj->maxdepthunit ? $sample_obj->maxdepthunit : 'm',
'admintab_depthcheck' => $sample_obj->depthcheck,
'step_depth' => $sample_obj->step_depth ? $sample_obj->step_depth : $sample_obj->step,
'admintab_maxweight_unit' => $sample_obj->maxweightunit ? $sample_obj->maxweightunit : 'kg',
'admintab_weightcheck' => $sample_obj->weightcheck,
'module_dir' => $path,
'psversion' => _PS_VERSION_,
'image_src' => $this->getImageSrc($id_product),
'token' => Tools::getToken(false),
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute,
'minimal_qty' => isset($params['product']['minimal_quantity']) ? $params['product']['minimal_quantity'] : '',
'availability' => isset($params['product']['availability']) ? $params['product']['availability'] : false,
));
return $this->display(__FILE__, 'addtocartbutton.tpl');
}
}