Merge branch 'ticket-10657-PhileaMulti' into develop
This commit is contained in:
commit
bafe19b48c
170
modules/privatesales_shipping/AdminPrivateSalesShipping.php
Executable file
170
modules/privatesales_shipping/AdminPrivateSalesShipping.php
Executable file
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||||
|
||||
class AdminPrivateSalesShipping extends AdminTab {
|
||||
private $imagelist;
|
||||
|
||||
public function __construct() {
|
||||
$this->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 '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_shipping/privatesale.js"></script>
|
||||
<script type="text/javascript">
|
||||
i18n_delete = "'.$this->l('Are you sure you want to delete this shipping method?').'";
|
||||
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping').'";
|
||||
</script>
|
||||
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping').'" method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Edit a shipping method').'</legend>';
|
||||
|
||||
echo '<label>'.$this->l('Name:').'</label>
|
||||
<div class="margin-form">';
|
||||
foreach($this->_languages as $language) {
|
||||
echo '<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||||
<input type="text" style="width: 500px;" name="name_'.$language['id_lang'].'" value="'.($this->curshipping !== NULL? $this->curshipping['name'][$language['id_lang']]: '').'" />
|
||||
</div>';
|
||||
}
|
||||
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'name');
|
||||
echo '<div class="clear"></div>
|
||||
</div>';
|
||||
|
||||
echo '<br class="clear" />
|
||||
<div class="margin-form">
|
||||
<input type="hidden" name="id_shipping" value="'.($this->curshipping !== NULL? $this->curshipping['id']: '').'" />
|
||||
<input type="submit" class="button" name="submitShippingAdd" value="'.$this->l('Add this shipping method').'" />
|
||||
<input type="submit" class="button'.($this->curshipping !== NULL? '': ' disable"').'" name="submitShippingUpdate" value="'.$this->l('Edit this shipping method').'"'.($this->curshipping !== NULL? '': ' disabled="disabled"').' id="submitShippingUpdate" />
|
||||
</div>';
|
||||
|
||||
echo '</fieldset>
|
||||
</form>';
|
||||
}
|
||||
|
||||
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 '<fieldset class="space">
|
||||
<legend><img src="'.__PS_BASE_URI__.'modules/privatesales/prefs.gif" alt="" title="" /> '.$this->l('Shipping methods list').'</legend>
|
||||
<table class="table" style="width: 100%;">
|
||||
<tr>
|
||||
<th>'.$this->l('ID').'</th>
|
||||
<th>'.$this->l('Name').'</th>
|
||||
<th style="width: 55px;">'.$this->l('Actions').'</th>
|
||||
</tr>';
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'privatesale_shipping_lang`
|
||||
WHERE `id_lang` = '.$cookie->id_lang
|
||||
) as $shipping) {
|
||||
echo '<tr>
|
||||
<td>'.$shipping['id_shipping'].'</td>
|
||||
<td>'.$shipping['value'].'</td>
|
||||
<td>
|
||||
<img style="cursor: pointer;" onclick="itemEdition('.$shipping['id_shipping'].')" title="'.$this->l('Edit this shipping method').'" alt="" src="../img/admin/edit.gif">
|
||||
<img style="cursor: pointer;" onclick="itemDeletion('.$shipping['id_shipping'].')" title="'.$this->l('Delete this shipping method').'" alt="" src="../img/admin/delete.gif">
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
echo '</table>
|
||||
</fieldset>';
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
}
|
BIN
modules/privatesales_shipping/add.png
Executable file
BIN
modules/privatesales_shipping/add.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 570 B |
BIN
modules/privatesales_shipping/logo.gif
Executable file
BIN
modules/privatesales_shipping/logo.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 573 B |
BIN
modules/privatesales_shipping/prefs.gif
Executable file
BIN
modules/privatesales_shipping/prefs.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 351 B |
10
modules/privatesales_shipping/privatesale.js
Executable file
10
modules/privatesales_shipping/privatesale.js
Executable file
@ -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";
|
||||
}
|
||||
}
|
224
modules/privatesales_shipping/privatesales_shipping.php
Executable file
224
modules/privatesales_shipping/privatesales_shipping.php
Executable file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||||
|
||||
class PrivateSales_Shipping extends Module {
|
||||
public function __construct() {
|
||||
$this->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 '<label>'.$this->l('Shipping:').'</label>
|
||||
<div class="margin-form">
|
||||
<div id="tags" style="float: left; padding-top: 5px;">'.$this->l('No shipping method available').'</div>
|
||||
<div class="clear"></div>
|
||||
</div>';
|
||||
} else {
|
||||
echo '
|
||||
<label>'.$this->l('Shipping:').'</label>
|
||||
<div class="margin-form">
|
||||
<div id="tags" style="float: left;">
|
||||
<select id="s_shipping" name="s_shipping">
|
||||
<option value=""></option>';
|
||||
foreach($shipping as $ship) {
|
||||
echo '<option value="'.$ship['id_shipping'].'"'.(isset($ship['id_shipping']) && $ship['id_sale'] !== NULL?' selected="selected"':'').'>'.$ship['value'].'</option>';
|
||||
}
|
||||
echo '
|
||||
</select>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
BIN
modules/privatesales_shipping/table.png
Executable file
BIN
modules/privatesales_shipping/table.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 566 B |
Loading…
Reference in New Issue
Block a user