From 83d3523000a137d25841739c764684d786d57016 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Mon, 21 Nov 2016 10:11:27 +0100 Subject: [PATCH] addition of module for privatesales shipping --- .../AdminPrivateSalesShipping.php | 170 +++++++++++++ modules/privatesales_shipping/add.png | Bin 0 -> 570 bytes modules/privatesales_shipping/logo.gif | Bin 0 -> 573 bytes modules/privatesales_shipping/prefs.gif | Bin 0 -> 351 bytes modules/privatesales_shipping/privatesale.js | 10 + .../privatesales_shipping.php | 224 ++++++++++++++++++ modules/privatesales_shipping/table.png | Bin 0 -> 566 bytes 7 files changed, 404 insertions(+) create mode 100755 modules/privatesales_shipping/AdminPrivateSalesShipping.php create mode 100755 modules/privatesales_shipping/add.png create mode 100755 modules/privatesales_shipping/logo.gif create mode 100755 modules/privatesales_shipping/prefs.gif create mode 100755 modules/privatesales_shipping/privatesale.js create mode 100755 modules/privatesales_shipping/privatesales_shipping.php create mode 100755 modules/privatesales_shipping/table.png diff --git a/modules/privatesales_shipping/AdminPrivateSalesShipping.php b/modules/privatesales_shipping/AdminPrivateSalesShipping.php new file mode 100755 index 00000000..64aa3368 --- /dev/null +++ b/modules/privatesales_shipping/AdminPrivateSalesShipping.php @@ -0,0 +1,170 @@ +lang = TRUE; + parent::__construct(); + } + + public function displayForm($isMainTab=TRUE) { + global $currentIndex, $cookie; + parent::displayForm(); + + $iso = Language::getIsoById((int)($cookie->id_lang)); + $divLangName = 'name¤legend¤description'; + + echo ' + +
+
+ '.$this->l('Edit a shipping method').''; + + echo ' +
'; + foreach($this->_languages as $language) { + echo '
+ +
'; + } + $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'name'); + echo '
+
'; + + echo '
+
+ + + curshipping !== NULL? '': ' disabled="disabled"').' id="submitShippingUpdate" /> +
'; + + echo '
+
'; + } + + public function display() { + global $cookie, $currentIndex; + $this->curshipping = null; + if($id = Tools::getValue('id')) { + $shipping = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'privatesale_shipping_lang` WHERE `id_shipping` = '.(int) $id); + if(count($shipping) > 0) { + $this->curshipping = array('id' => $id, 'name' => array()); + foreach($shipping as $t) { + $this->curshipping['name'][$t['id_lang']] = $t['value']; + $this->curshipping['legend'][$t['id_lang']] = $t['legend']; + $this->curshipping['description'][$t['id_lang']] = $t['description']; + } + } else { + Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping')); + } + } + + $this->displayForm(); + + echo '
+ '.$this->l('Shipping methods list').' + + + + + + '; + foreach(Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'privatesale_shipping_lang` + WHERE `id_lang` = '.$cookie->id_lang + ) as $shipping) { + echo ' + + + + '; + } + echo '
'.$this->l('ID').''.$this->l('Name').''.$this->l('Actions').'
'.$shipping['id_shipping'].''.$shipping['value'].' + + +
+
'; + } + + function postProcess() { + global $cookie, $currentIndex; + + if(Tools::isSubmit('submitShippingAdd')) { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_shipping` VALUES ( + DEFAULT + ) + '); + $id_shipping = Db::getInstance()->Insert_ID(); + foreach(Language::getLanguages(FALSE) as $language) { + if($name = Tools::getValue('name_'.$language['id_lang'])) { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES ( + '.$id_shipping.', + '.$language['id_lang'].', + "'.pSQL($name).'" + ) + '); + } else { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES ( + '.$id_shipping.', + '.$language['id_lang'].', + "" + ) + '); + } + } + } elseif(Tools::isSubmit('submitShippingUpdate') && $id_shipping = (int) Tools::getValue('id_shipping')) { + if(count(Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'privatesale_shipping` + WHERE `id_shipping` = '.$id_shipping) + ) > 0) { + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_lang` + WHERE `id_shipping` = '.$id_shipping.' + '); + foreach(Language::getLanguages(FALSE) as $language) { + if($name = Tools::getValue('name_'.$language['id_lang'])) { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES ( + '.$id_shipping.', + '.$language['id_lang'].', + "'.pSQL($name).'" + ) + '); + } else { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES ( + '.$id_shipping.', + '.$language['id_lang'].', + "" + ) + '); + } + } + } + } elseif(isset($_GET['delete']) && $id_shipping = Tools::getValue('id')) { + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_lang` + WHERE `id_shipping` = '.(int) $id_shipping.' + '); + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_sale` + WHERE `id_shipping` = '.(int) $id_shipping.' + '); + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'privatesale_shipping` + WHERE `id_shipping` = '.(int) $id_shipping.' + '); + Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping')); + } + } +} diff --git a/modules/privatesales_shipping/add.png b/modules/privatesales_shipping/add.png new file mode 100755 index 0000000000000000000000000000000000000000..00be352c5783c0f009db7286bb4ac86f306634db GIT binary patch literal 570 zcmV-A0>%A_P)O?!~#Vdl*A~_RMaJeHZc^62(la$ zXNk(f!J;Kx`k;bWQJvnEklKv4E*yUMoqNvtUEX^F0D`|j@Q(r{5=p1oY+msBe7DJD z5^lHq%4)R^@aW?E8gVou4QYP_h{fV|l}fb|4u?^%*HNq0P$(4O@pvv=E?2Qytv(Z1 zDwRMQ(vqhcAQFj2>~{NorBb;y7z}$#rSi>WG9eO)!0B{?dg5r7N~NwyOP=o=ta!a% zE*g!p8jYqyDwRIw^LdoZWfY4=WHK2LM>EopmORY>hGAw|mc5I|PN#3O*(?%?1Z*}N91cgL4{iEji;aEEtZ88I z%HD_Pm~b;dC=|BwEA}fCic6!>_++tII36#0y?%nn(Cp&Gi)U*JyQeW6UFQ%wFhd_= zFktBpwDhgV{lnb$$vU>rBA^N!nh-iRQgVr8yH8%}^ zZn9za?@#`2175f^8t6qZXKdU|Cq1|P4!%N`c|6eCU*|IMpHVxOJgs;lasU7T07*qo IM6N<$g1LbM(&V7@p5HJfEk3A-kG9ue?rLK`HuHzWIdWM_iT39vqjP`R|&u0DENM@)7R}>FL#N5 z+7bG7KiAiT9Pf|vzdtJYX-~?h!~gq>{(NBme}D1+4-EewulxUv;s5hp zpR66|fE0hSFmf@}Gw6U~0u(02Bc`U5jds_seVdW>fKUHg?b8dlwCX-rtjG}_f3_QZ3-Z%3^glh6~I2b%s cQVL|(QWWCp5?Ji2#3v%8d1He^fC7Ux0GZkVAOHXW literal 0 HcmV?d00001 diff --git a/modules/privatesales_shipping/prefs.gif b/modules/privatesales_shipping/prefs.gif new file mode 100755 index 0000000000000000000000000000000000000000..1a1f43562f26ba1c172ff8f19febdf520f899ea1 GIT binary patch literal 351 zcmZ?wbhEHb6krfwxXQrL*4FmFMq&T{{r~s$EMLC-|LXkf*RQ{u8TWfZ;{WLZ|IaR) zJbCi-=gM(N{|`;yvSrK6nKSR+y?f@&neSVh-@SYHe@;+$clYYmt3NHv z`@cNv|NhDUkIeetpz(ih#Q$?^|1V4ZzqRTA`m+E3|1(eTa9MO|;p9n*iTiFIJ>sa4!o%<~C9#0xUXw~-V5Egc z-yVhsGrC=**aR6`%8L29xLDaG#Dcgwn3-icIQl2@^UKP!dUGjrF)J$x$V&%_FI+4j fzC4ImwqAf!F;YcQQDF1dZ7Q5{jMMfyGFSruy83zV literal 0 HcmV?d00001 diff --git a/modules/privatesales_shipping/privatesale.js b/modules/privatesales_shipping/privatesale.js new file mode 100755 index 00000000..3d3a6c75 --- /dev/null +++ b/modules/privatesales_shipping/privatesale.js @@ -0,0 +1,10 @@ +function itemEdition(linkId) { + document.location.href = current_location + "&edit&id=" + linkId; +} + +function itemDeletion(linkId) { + var ok = confirm(i18n_delete) + if(ok == true) { + document.location.href = current_location + "&id=" + linkId + "&delete=1"; + } +} diff --git a/modules/privatesales_shipping/privatesales_shipping.php b/modules/privatesales_shipping/privatesales_shipping.php new file mode 100755 index 00000000..9800a1d5 --- /dev/null +++ b/modules/privatesales_shipping/privatesales_shipping.php @@ -0,0 +1,224 @@ +name = 'privatesales_shipping'; + $this->tab = 'pricing_promotion'; + $this->author = 'Antadis'; + $this->version = '1.0'; + parent::__construct(); + + $this->displayName = $this->l('Private Sales Shipping'); + $this->description = $this->l('Adds a shipping method to private sales'); + } + + public function install() { + if(!Module::isInstalled('privatesales')) { + return FALSE; + } + + # Install admin tab + $id_mod = Db::getInstance()->ExecuteS(' + SELECT `id_tab` + FROM `'._DB_PREFIX_.'tab` + WHERE `class_name` = "AdminPrivateSales" + '); + if(count($id_mod) == 0) { + return FALSE; + } + $id_mod = $id_mod[0]['id_tab']; + $posmax = Db::getInstance()->ExecuteS('SELECT MAX(`position`) + 1 AS `max` FROM `'._DB_PREFIX_.'tab` WHERE `id_parent` = '.$id_mod); + $posmax = $posmax[0]['max']; + + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'tab` + VALUES ( + DEFAULT, + '.$id_mod.', + "AdminPrivateSalesShipping", + "privatesales_shipping", + '.$posmax.' + ) + '); + $tab_id = Db::getInstance()->Insert_ID(); + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'access` + VALUES (1, '.$tab_id.', 1, 1, 1, 1) + '); + + $tabs_i18n = array( + 'fr' => 'Transport', + 'en' => 'Shipping', + ); + $langs = Db::getInstance()->ExecuteS(' + SELECT `id_lang`, `iso_code` + FROM `'._DB_PREFIX_.'lang` + '); + foreach($langs as $lang) { + if(isset($tabs_i18n[$lang['iso_code']])) { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'tab_lang` + VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n[$lang['iso_code']].'") + '); + } else { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'tab_lang` + VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n['en'].'") + '); + } + } + + # Add tags tables + $query = ' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_shipping` ( + `id_shipping` INTEGER NOT NULL AUTO_INCREMENT, + PRIMARY KEY(`id_shipping`) + ) ENGINE=MyIsam DEFAULT CHARSET=utf8 + '; + if(!Db::getInstance()->Execute($query)) { + return FALSE; + } + $query = ' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_shipping_lang` ( + `id_shipping` INTEGER NOT NULL, + `id_lang` INTEGER NOT NULL, + `value` TEXT, + PRIMARY KEY(`id_shipping`, `id_lang`) + ) ENGINE=MyIsam DEFAULT CHARSET=utf8 + '; + if(!Db::getInstance()->Execute($query)) { + return FALSE; + } + $query = ' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_shipping_sale` ( + `id_shipping` INTEGER NOT NULL, + `id_sale` INTEGER NOT NULL, + PRIMARY KEY(`id_shipping`, `id_sale`) + ) ENGINE=MyIsam DEFAULT CHARSET=utf8 + '; + if(!Db::getInstance()->Execute($query)) { + return FALSE; + } + + # Register hooks + if(!parent::install() + OR !$this->registerHook('privatesales_create') + OR !$this->registerHook('privatesales_update') + OR !$this->registerHook('privatesales_delete') + OR !$this->registerHook('privatesales_edit')) { + return FALSE; + } + + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_module` + VALUES ( + (SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "privatesales_shipping"), + "privatesales_shipping" + ) + '); + + return TRUE; + } + + function uninstall() { + $tab = Db::getInstance()->Execute(' + SELECT `id_tab` + FROM `'._DB_PREFIX_.'tab` + WHERE `module` = "privatesales_shipping" + '); + if(count($tab) == 0) { + return FALSE; + } + $tab = $tab[0]; + + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'tab_lang` + WHERE `id_tab` = '.$tab['id_tab'] + ); + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'access` + WHERE `id_tab` = '.$tab['id_tab'] + ); + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'tab` + WHERE `module` = "privatesales_shipping" + '); + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'tab` + SET `position` = `position` - 1 + WHERE `id_parent` = '.$tab['id_parent'].' AND `position` > '.$tab['position'] + ); + + if(parent::uninstall() == FALSE) { + return FALSE; + } + + Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_shipping`'); + Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_shipping_lang`'); + Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_shipping_sale`'); + Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'privatesale_module` WHERE `modulename` = "privatesales_shipping"'); + + return TRUE; + } + + public function hookPrivateSales_Edit($params) { + global $cookie; + $shipping = Db::getInstance()->ExecuteS(' + SELECT l.`id_shipping`, l.`value`'.($params['sale'] !== NULL? ', ( + SELECT IFNULL(s.`id_shipping`, NULL) + FROM `'._DB_PREFIX_.'privatesale_shipping_sale` s + WHERE l.`id_shipping` = s.`id_shipping` AND s.`id_sale` = '.$params['sale']->id.' + ) AS `id_sale`': '').' + FROM `'._DB_PREFIX_.'privatesale_shipping_lang` l + WHERE l.`id_lang` = '.$cookie->id_lang + ); + if(count($shipping) == 0) { + echo ' +
+
'.$this->l('No shipping method available').'
+
+
'; + } else { + echo ' + +
+
+ +
+
+
'; + } + } + + public function hookPrivateSales_Delete($params) { + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_sale` + WHERE `id_sale` = '.$params['sale']->id + ); + } + + public function hookPrivateSales_Create($params) { + if($shipping = Tools::getValue('s_shipping')) { + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_sale` VALUES ( + '.(int) $shipping.', '.$params['sale']->id.' + ) + '); + } + } + + public function hookPrivateSales_Update($params) { + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_sale` + WHERE `id_sale` = '.$params['sale']->id + ); + $this->hookPrivateSales_Create($params); + } +} diff --git a/modules/privatesales_shipping/table.png b/modules/privatesales_shipping/table.png new file mode 100755 index 0000000000000000000000000000000000000000..abcd93689a08ec9bdbf0984927e8da06c043c7cd GIT binary patch literal 566 zcmV-60?GY}P)>q?GuNnCdgP^*Bj5V_b?dAq2Ppn9^MBB^YUM zad0N-T{Ujg*A6d~mYV4na=hT4Nz+_}SGTgW|Iir!%$ z;@OGkWI6+j0H}~K4RYR%!7y|zM`O@*K>rL{*&}x3lR**HrMXC1->#slU>X|w!U1xQ zqc