Mam coś podobnego MODUŁ nazwa "SalesAndDiscounts" do pobrania w http://www.henribaeyens.com/10ver/filez ... ddiscounts
odejmuje w %
tylko nie ma opcji dodać a chcę zeby dodawał
jak lub co zmienić aby dodawał
PANOWIE CO JEST STAWIAM 0.7 za pomoc
-------------------------------------------------------------
<?php
include_once(_PS_CLASS_DIR_.'AdminTab.php');
include_once(dirname(__FILE__).'/functions.php');
class AdminSalesanddiscounts extends AdminTab {
protected $_lang;
protected $_currency;
protected $_page;
protected $_attributeFieldsDisplay;
protected $_table_width = 0;
public function __construct() {
global $cookie;
$this->table = 'product';
$this->identifier = 'id_product';
$this->className = 'AdminSalesanddiscounts';
$this->name = "salesanddiscounts";
$this->_lang = (!isset($cookie) || !is_object($cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($cookie->id_lang);
$this->_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
if (Tools::isSubmit('submitFilter'.$this->table))
$this->_page = intval($_POST['submitFilter'.$this->table]);
elseif (Tools::isSubmit('page'))
$this->_page = (array_key_exists('page', $_POST)) ? intval($_POST['page']) : intval($_GET['page']);
$this->_page = (!$this->_page) ? 1 : $this->_page;
if (Tools::isSubmit('id_category'))
$this->_category = (array_key_exists('id_category', $_POST)) ? intval($_POST['id_category']) : intval($_GET['id_category']);
else
$this->_category = 1;
$this->fieldsDisplay = array(
'name' => array('title' => $this->l('Name'), 'width' => 340, 'align' => 'left', 'filter_key' => 'b!name', 'orderby' => true),
'reduction_price' => array('title' => $this->l('Discount'), 'width' => 90, 'price' => true, 'align' => 'left', 'filter' => false),
'reduction_percent' => array('title' => $this->l('Discount'), 'width' => 80, 'align' => 'left', 'type' => 'decimal', 'suffix' => '%', 'filter' => false),
'reduction_from' => array('title' => $this->l('From'), 'width' => 120, 'align' => 'center', 'type' => 'date', 'filter' => false, 'search' => false),
'reduction_to' => array('title' => $this->l('To'), 'width' => 120, 'align' => 'center', 'type' => 'date', 'filter' => false, 'search' => false),
'on_sale' => array('title' => $this->l('On sale'), 'width' => 80, 'active' => 'on_sale', 'align' => 'center', 'type' => 'bool', 'orderby' => false)
);
foreach ($this->fieldsDisplay as $key => $params)
$this->table_width += ($params['width'] + 4);
parent::__construct();
}
public function l($string, $specific = false) {
global $_MODULES, $_MODULE;
$file = _PS_MODULE_DIR_.$this->name.'/'.Language::getIsoById($this->_lang).'.php';
if (file_exists($file) && include_once($file))
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
if (!is_array($_MODULES))
return (str_replace('"', '"', $string));
$string2 = str_replace('\'', '\\\'', $string);
$key = '<{'.$this->name.'}prestashop>'.$this->className.'_'.md5($string2);
if (key_exists($key, $_MODULES))
$ret = stripslashes($_MODULES[$key]);
else
$ret = $string;
return str_replace('"', '"', $ret);
}
public function postProcess() {
global $currentIndex, $cookie;
if (array_key_exists('productOrderby', $_GET) && isset($_GET['productOrderby']) && array_key_exists('productOrderway', $_GET) && isset($_GET['productOrderway'])) {
$cookie->{$this->table.'Orderby'} = $_GET['productOrderby'];
$cookie->{$this->table.'Orderway'} = $_GET['productOrderway'];
}
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
$page = 1;
if (Tools::isSubmit('submitFilter'.$this->table))
$page = intval($_POST['submitFilter'.$this->table]);
else if (Tools::isSubmit('page'))
$page = intval(Tools::getValue('page'));
$this->_page = $page;
$p = ($this->_page > 1) ? '&page='.$this->_page : '';
$c = ($category = Tools::getValue('category')) ? '&category='.$category : '';
if (Tools::isSubmit('applyToAll')) {
@ini_set('max_execution_time', 2000);
$fields = array();
if (!empty($_POST['reduction_price'])) {
$reduction_price = ($this->_currency->format == 1 || $this->_currency->format == 3) ? str_replace(",", "", $_POST['reduction_price']) : str_replace(",", ".", $_POST['reduction_price']);
$fields['reduction_price'] = str_replace(" ", "", $reduction_price);
}
if (!empty($_POST['reduction_percent']))
$fields['reduction_percent'] = str_replace(",", ".", $_POST['reduction_percent']);
if (!empty($_POST['reduction_from']))
$fields['reduction_from'] = preg_match("~^[0-9]{2}-[0-9]{2}-[0-9]{4}~", $_POST['reduction_from']) ? implode('-',array_reverse(explode('-',$_POST['reduction_from']))) : $_POST['reduction_from'];
if (!empty($_POST['reduction_to']))
$fields['reduction_to'] = preg_match("~^[0-9]{2}-[0-9]{2}-[0-9]{4}~", $_POST['reduction_to']) ? implode('-',array_reverse(explode('-',$_POST['reduction_to']))) : $_POST['reduction_to'];
if ($_POST['on_sale'] != '')
$fields['on_sale'] = intval($_POST['on_sale']);
if (array_key_exists('category', $_POST)) {
$products = Db::getInstance()->ExecuteS('SELECT `'.$this->identifier .'` FROM `'._DB_PREFIX_.'category_product` WHERE `id_category`='.$_POST['category']);
foreach ($products as $product)
if (!Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table, $fields, 'UPDATE', '`'.$this->identifier.'`='.$product['id_product']))
$this->_errors[] = Tools::displayError('an error occurred while updating data');
} else
Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table, $fields, 'UPDATE');
Tools::redirectAdmin($currentIndex.$c.$p.'&conf=4&token='.$token);
} elseif (Tools::isSubmit('submitChanges')) {
@ini_set('max_execution_time', 2000);
unset($_POST['token']);
unset($_POST['submitFilter'.$this->table]);
unset($_POST['submitChanges']);
$fields = array();
foreach($_POST as $key => $value) {
$should_i_go = false;
list($id_product, $field) = explode("!", $key);
if ($field == "reduction_price") {
$reduction_price = ($this->_currency->format == 1 || $this->_currency->format == 3) ? str_replace(",", "", $value) : str_replace(",", ".", $value);
$fields[$field] = str_replace(" ", "", $reduction_price);
} else if ($field == "reduction_percent")
$fields[$field] = str_replace(",", ".", $value);
else if ($field == "reduction_from")
$fields[$field] = preg_match("~^[0-9]{2}-[0-9]{2}-[0-9]{4}~", $value) ? implode('-',array_reverse(explode('-',$value))) : $value;
else if ($field == "reduction_to") {
$fields[$field] = preg_match("~^[0-9]{2}-[0-9]{2}-[0-9]{4}~", $value) ? implode('-',array_reverse(explode('-',$value))) : $value;
$should_i_go = true;
}
if ($should_i_go) {
//echo '
',print_r($fields),''; if (!Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table, $fields, 'UPDATE', '`'.$this->identifier.'`='.$id_product))
$this->_errors[] = Tools::displayError('an error occurred while updating data');
}
}
Tools::redirectAdmin($currentIndex.$c.$p.'&conf=4&token='.$token);
} else if (array_key_exists('on_sale',$_GET) && isset($_GET['id_product']))
if (!Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.$this->table.'` SET `on_sale` = !`on_sale` WHERE `id_product`='.$_GET['id_product']))
$this->_errors[] = Tools::displayError('an error occurred while updating status');
else
Tools::redirectAdmin($currentIndex.$c.$p.'&conf=4&token='.$token);
parent::postProcess();
}
public function display($token = NULL) {
global $currentIndex, $cookie;
if (!isset($token) || empty($token))
$token = $this->token;
$iso = Db::getInstance()->getValue('SELECT iso_code FROM '._DB_PREFIX_.'lang WHERE `id_lang` = '.$this->_lang);
echo '
';
if ($iso != 'en')
echo '
';
echo '
div.outer {
width: ',$this->table_width,'px;
}
div.table, div.tr {
width: ',$this->table_width,'px;
}
.ajax-load {
background: transparent url(',_MODULE_DIR_,$this->name,'/loading.gif) center center no-repeat;
}
';
$orderBy = ((!isset($cookie->{$this->table.'Orderby'})) ? $this->_orderBy : $cookie->{$this->table.'Orderby'});
$orderWay = ((!isset($cookie->{$this->table.'Orderway'})) ? $this->_orderWay : $cookie->{$this->table.'Orderway'});
if ($category = Tools::getValue('category')) {
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_product`=a.`id_product`';
$this->_where = 'AND cp.`id_category`='.intval($category);
}
$this->lang = true;
$_POST['submitFilter'.$this->table] = $this->_page;
parent::getList($this->_lang, $orderBy, strtoupper($orderWay));
$this->displayList($token);
}
public function displayList($token) {
global $currentIndex;
$categories = Category::getCategories($this->_lang, false);
echo '
'.intval($this->_listTotal).' '.$this->l('product').(intval($this->_listTotal) > 1 ? 's' : '').'
'.$this->l('Display all products').'';
Category::recurseCategory($categories, $categories[0][1], 1, Tools::getValue('category') ? Tools::getValue('category') : 0);
echo '
'; $this->displayListHeader($token);
if (!$this->_listTotal)
echo '
'.$this->l('No products found').' '; $this->displayListContent($token);
$this->displayListFooter($token);
echo '
$(document).ready(function() {
$("#blankAll").click(function() {
$(":input","#applyAll_'.$this->table.'")
.not(":button, :submit, :reset, :hidden")
.val("")
.removeAttr("checked")
.removeAttr("selected");
});
});
';
}
public function displayListHeader($token = NULL) {
global $currentIndex, $cookie;
if (!isset($token) || empty($token))
$token = $this->token;
$page = $this->_page;
$category = Tools::getValue('category');
$totalPages = ceil($this->_listTotal / Tools::getValue('pagination', (isset($cookie->{$this->table.'_pagination'}) ? $cookie->{$this->table.'_pagination'} : $this->_pagination[0])));
if (!$totalPages) $totalPages = 1;
echo '
';
if ($category)
echo '
';
echo '
';
if ($page > 1)
echo '
';
echo $this->l('Page').' '.$page.' / '.$totalPages;
if ($page < $totalPages)
echo '
';
echo ' | '.$this->l('Display').'
';
$selectedPagination = Tools::getValue('pagination', (isset($cookie->{$this->table.'_pagination'}) ? $cookie->{$this->table.'_pagination'} : null));
foreach ($this->_pagination as $value)
echo ' _pagination[1]) ? ' selected="selected2"' : '')).'>'.intval($value).'';
echo '
';
foreach ($this->fieldsDisplay as $key => $params) {
$width = $params['width'];
echo '
'.$params['title']; if (!isset($params['orderby']) || $params['orderby'])
echo '
table.'Orderby='.urlencode($key).'&'.$this->table.'Orderway=desc'.($page > 1 ? '&page='.$page : '').($category ? '&category='.$category : '').'&token='.$token.'">../img/admin/down_orderBy) && ($key == $this->_orderBy) && ($this->_orderWay == 'DESC')) ? '_d' : '').'.gif" />
table.'Orderby='.urlencode($key).'&'.$this->table.'Orderway=asc'.($page > 1 ? '&page='.$page : '').($category ? '&category='.$category : '').'&token='.$token.'">../img/admin/up_orderBy) && ($key == $this->_orderBy) && ($this->_orderWay == 'ASC')) ? '_d' : '').'.gif" />';
echo '
'; }
echo '
';
$keyPress = 'onkeypress="formSubmit(event, \'submitFilterButton_'.$this->table.'\');"';
foreach ($this->fieldsDisplay as $key => $params) {
$value = Tools::getValue($this->table.'Filter_'.(array_key_exists('filter_key', $params) ? $params['filter_key'] : $key));
$width = $params['width'];
echo '
'; if (!isset($params['type']))
$params['type'] = 'text';
if (isset($params['search']) && !$params['search']) {
echo '
--
'; continue;
}
switch ($params['type']) {
case 'bool':
echo '
--
'.$this->l('Yes').'
'.$this->l('No').'
';
break;
case 'date':
case 'datetime':
if (is_string($value))
$value = unserialize($value);
$name = $this->table.'Filter_'.(isset($params['filter_key']) ? $params['filter_key'] : $key);
$nameId = str_replace('!', '__', $name);
includeDatepicker(array($nameId.'_0', $nameId.'_1'));
echo
$this->l('From').'
'.
$this->l('To').' ';
break;
case 'text':
default:
echo '';
}
echo '
'; }
echo '
'; }
public function displayListContent($token=NULL) {
global $currentIndex, $cookie;
if (!isset($token) || empty($token))
$token = $this->token;
$page = $this->_page;
$category = Tools::getValue('category');
if (intval($this->_listTotal) > 0) {
getDatepicker(array('reduction_from', 'reduction_to'));
echo '
';
if ($category)
echo '
';
echo '
'; if ($this->_currency->format == 1 || $this->_currency->format == 3)
echo $this->_currency->sign.' ';
else
echo ' '. $this->_currency->sign;
echo '
%
----
'.$this->l('No').'
'.$this->l('Yes').'
* '.$this->l('blank fields will be ignored').'
'; }
echo '
';
if ($category)
echo '
';
if ($this->_list) {
$r = 1;
foreach ($this->_list as $i => $product) {
$pid = $product[$this->identifier];
echo '
';
foreach ($this->fieldsDisplay as $key => $params) {
$width = $params['width'];
$tmp = explode('!', $key);
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
echo '
'; if (isset($params['active']) && isset($product[$key]))
echo '
identifier.'='.$pid.'&'.$params['active'].($page > 1 ? '&page='.$page : '').($category ? '&category='.$category : '').'&token='.$token.'">
../img/admin/l('Yes') : $this->l('No')).'" title="'.($product[$key] ? $this->l('Yes') : $this->l('No')).'" />
';
elseif (isset($params['activeVisu']) && isset($product[$key]))
echo '../img/admin/l('Yes') : $this->l('No')).'" title="'.($product[$key] ? $this->l('Yes') : $this->l('No')).'" />';
elseif (isset($params['icon']) && (isset($params['icon'][$product[$key]]) || isset($params['icon']['default'])))
echo '../img/admin/';
elseif (isset($params['price'])) {
$display = Tools::displayPrice($product[$key], $this->_currency, false, false);
if ($this->_currency->format == 1 || $this->_currency->format == 3) {
$p = ltrim(ltrim($display, $this->_currency->sign));
echo $this->_currency->sign.' ';
} else {
$p = rtrim(rtrim($display, $this->_currency->sign));
echo ' '.$this->_currency->sign;
}
} elseif (isset($params['type'])) {
if ($params['type'] == "decimal") {
if ($key == "reduction_percent")
echo '';
else
echo $product[$key];
} elseif ($params['type'] == "date") {
getDatepicker(array($pid.'-'.$key));
echo '';
} elseif ($params['type'] == "datetime")
echo Tools::displayDate($product[$key], $this->_lang, true);
} elseif (isset($product[$key]))
echo ($key == "name") ? stripslashes(htmlspecialchars($product[$key])) : $product[$key];
else
echo '--';
echo (isset($params['suffix']) ? ' '.$params['suffix'] : '');
echo '
'; }
echo '
'; }
echo '
'; }
}
public function displayListFooter($token = NULL) {
global $currentIndex, $cookie;
if (!isset($token) || empty($token))
$token = $this->token;
$page = $this->_page;
$totalPages = ceil($this->_listTotal / Tools::getValue('pagination', (isset($cookie->{$this->table.'_pagination'}) ? $cookie->{$this->table.'_pagination'} : $this->_pagination[0])));
if (!$totalPages) $totalPages = 1;
echo '
';
if ($category = Tools::getValue('category'))
echo '
';
echo '
'; if ($page > 1)
echo '
';
echo $this->l('Page').' '.$page.' / '.$totalPages;
if ($page < $totalPages)
echo '
';
echo '
'; }
}
?>
--------------------------------------------------------------------------------