close wanted sale

This commit is contained in:
Marion Muszynski 2017-09-15 10:09:15 +02:00
parent ede8721e84
commit deec098272
2 changed files with 69 additions and 1 deletions

View File

@ -362,6 +362,22 @@ class AdminPrivateSalesSales extends AdminTab {
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Uncombinable
$input = array(
'type' => 'switch',
'name' => 'uncombinable',
'label' => $this->l('Non cumulable :'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->uncombinable==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->uncombinable==0?0:1):0),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Featured
$input = array(
'type' => 'switch',
@ -1134,6 +1150,7 @@ class AdminPrivateSalesSales extends AdminTab {
$sale->logout = Tools::getValue('logout', 0);
$sale->new = Tools::getValue('new', 0);
$sale->braderie = Tools::getValue('braderie', 0);
$sale->uncombinable = Tools::getValue('uncombinable', 0);
$sale->forward_news = Tools::getValue('forward_news', 0);
$sale->pub = Tools::getValue('pub', 0);
$sale->id_category = Tools::getValue('id_category', Configuration::get('PRIVATESALES_ROOT'));
@ -1218,6 +1235,7 @@ class AdminPrivateSalesSales extends AdminTab {
$sale->pub = Tools::getValue('pub', 0);
$sale->new = Tools::getValue('new', 0);
$sale->braderie = Tools::getValue('braderie', 0);
$sale->uncombinable = Tools::getValue('uncombinable', 0);
$sale->forward_news = Tools::getValue('forward_news', 0);
$sale->id_category = Tools::getValue('id_category', Configuration::get('PRIVATESALES_ROOT'));
$sale->id_employee = (int) Tools::getValue('id_employee');

View File

@ -14,6 +14,7 @@ class Sale {
var $pub = 0;
var $new = 0;
var $braderie = 0;
var $uncombinable = 0;
var $forward_news = 0;
var $lock_position = 0;
var $id_category;
@ -41,6 +42,7 @@ class Sale {
$this->pub = $sale['pub'];
$this->new = $sale['new'];
$this->braderie = $sale['braderie'];
$this->uncombinable = $sale['uncombinable'];
$this->forward_news = $sale['forward_news'];
$this->id_category = $sale['id_category'];
$this->id_employee = $sale['id_employee'];
@ -94,6 +96,7 @@ class Sale {
`logout` = '.(int) $this->logout.',
`new` = '.(int) $this->new.',
`braderie` = '.(int) $this->braderie.',
`uncombinable` = '.(int) $this->uncombinable.',
`forward_news` = '.(int) $this->forward_news.',
`public` = '.(int) $this->pub.',
`id_category` = '.(int) $this->id_category.',
@ -191,6 +194,7 @@ class Sale {
'.(int) $this->pub.',
'.(int) $this->new.',
'.(int) $this->braderie.',
'.(int) $this->uncombinable.',
'.(int) $this->forward_news.',
'.(int) $this->id_category.',
'.(int) $this->id_employee.',
@ -364,6 +368,7 @@ class Sale {
'pub' => $ps[0]['public'],
'new' => $ps[0]['new'],
'braderie' => $ps[0]['braderie'],
'uncombinable' => $ps[0]['uncombinable'],
'forward_news' => $ps[0]['forward_news'],
'position' => $ps[0]['position'],
'lock_position' => $ps[0]['lock_position'],
@ -1982,6 +1987,24 @@ class Sale {
}
}
/**
* Test if the sale is tagged as uncombinable or not
* @param [int] $id_sale
* @return boolean
*/
public static function isUncombinable($id_sale)
{
$result = Db::getInstance()->getValue('
SELECT `uncombinable`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `id_sale` = '.(int)$id_sale.'
');
if($result && (int)$result == 1){
return true;
}
return false;
}
/**
* Test the combination of two sale in the cart
* Only classic and particular delivery sales can be added together
@ -1993,8 +2016,35 @@ class Sale {
* @param array(id_sale, delivery_delay, shipping) $adding_sale [the sale of the new added product]
* @return boolean
*/
public static function isCombinable($current_sale, $adding_sale)
public static function isCombinable($sale, $added_sale)
{
if(is_array($sale) && is_array($added_sale)){
$current_sale = $sale;
$adding_sale = $added_sale;
} else {
// We can test with the attribute
if((int)$sale->uncombinable == 1 || (int)$added_sale->uncombinable == 1) {
return false;
}
// $sale and $added_sale are Sale object
$current_sale = array(
'id_sale'=> (int) $sale->id,
'delivery_delay'=> (int) $sale->delivery_delay,
'shipping' => self::getShippingSale((int)$sale->id)
);
$adding_sale = array(
'id_sale'=> (int) $added_sale->id,
'delivery_delay'=> (int) $added_sale->delivery_delay,
'shipping' => self::getShippingSale((int)$added_sale->id)
);
}
// Sale is uncombinable
if(self::isUncombinable((int)$current_sale['id_sale']) || self::isUncombinable((int)$adding_sale['id_sale'])) {
return false;
}
// Same sale
if((int)$adding_sale['id_sale'] == (int)$current_sale['id_sale']){
return true;