From e46f547c537f0c1106bf09314221b219c934f57f Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 12 May 2017 12:04:28 +0200 Subject: [PATCH] fix cron_discount and add cron to reorder braderi --- modules/ant_configurations/cron_discount.php | 32 ++++++++-- .../cron_reorder_braderie.php | 60 +++++++++++++++++++ 2 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 modules/ant_configurations/cron_reorder_braderie.php diff --git a/modules/ant_configurations/cron_discount.php b/modules/ant_configurations/cron_discount.php index a595bf58..1b6cb38e 100644 --- a/modules/ant_configurations/cron_discount.php +++ b/modules/ant_configurations/cron_discount.php @@ -21,6 +21,28 @@ $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; include dirname(__FILE__).'/../../config/config.inc.php'; +// CLEAN DISCOUNT QUAND CHANGEMENTS +// $discount_toclean = array(); +// foreach(Db::getInstance()->ExecuteS(' +// SELECT dh.id_discount +// FROM `ps_ant_discount_history` dh +// LEFT JOIN `ps_order_discount` o ON (o.`id_discount` = dh.`id_discount`) +// WHERE o.`id_order` IS NULL +// AND dh.`used` = 0 +// ') as $d){ +// $discount_toclean[] = (int)$d['id_discount']; +// } +// Db::getInstance()->ExecuteS(' +// UPDATE ps_discount +// SET +// `value` = 0, +// `id_discount_type` = 3, +// `minimal` = 10, +// `include_tax`= 0, +// `id_currency` = 0 +// WHERE id_discount IN ('.implode(',',$discount_toclean).') +// '); + $user_discounts = array(); foreach(Db::getInstance()->ExecuteS(' SELECT `id_customer` @@ -66,12 +88,12 @@ function generateDiscount($id_customer) { $discount = new Discount(); $discount->id_customer = (int)$id_customer; - $discount->id_discount_type = 2; + $discount->id_discount_type = 3; // free shipping $discount->behavior_not_exhausted = 1; $discount->cumulable = 0; $discount->cumulable_reduction = 1; - $discount->minimal = 50; - $discount->include_tax = 1; + $discount->minimal = 10; + $discount->include_tax = 0; $discount->cart_display = 0; $discount->active = 1; $discount->quantity = 1; @@ -98,8 +120,8 @@ function generateDiscount($id_customer) $discount->description[$language['id_lang']] = $description[$language['id_lang']]; } - $discount->id_currency = 1; - $discount->value = 10; + $discount->id_currency = 0; + $discount->value = 0; if($discount->add(true, false, array(1)) ) { return $discount; diff --git a/modules/ant_configurations/cron_reorder_braderie.php b/modules/ant_configurations/cron_reorder_braderie.php new file mode 100644 index 00000000..a4e2e44d --- /dev/null +++ b/modules/ant_configurations/cron_reorder_braderie.php @@ -0,0 +1,60 @@ +ExecuteS(' + SELECT pc.`id_category` + FROM `'._DB_PREFIX_.'privatesale_category` pc + LEFT JOIN `'._DB_PREFIX_.'privatesale` p ON (p.id_sale = pc.id_sale) + WHERE p.`braderie` = 1 +') as $c){ + $categories[] = $c['id_category']; +} + +foreach ($categories as $key => $id_category) { + $products = Db::getInstance()->ExecuteS(' + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_product` cp + RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product=p.id_product AND pl.`id_lang` = 1) + WHERE cp.id_category ='.(int)$id_category.' AND p.quantity != 0 + ORDER BY cp.`position` + '); + + foreach ($products as $key => $product) { + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'category_product` + SET `position` = '. (int)($key) .' + WHERE `id_product` = '.(int)($product['id_product']).' + AND `id_category`='.(int)$id_category + ); + } + + $products_zero = Db::getInstance()->ExecuteS(' + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_product` cp + RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product=p.id_product AND pl.`id_lang` = 1) + WHERE cp.id_category ='.(int)$id_category.' AND p.quantity == 0 + ORDER BY cp.`position` + '); + $position = count($products); + foreach ($$products_zero as $key => $product) { + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'category_product` + SET `position` = '. (int)($position) .' + WHERE `id_product` = '.(int)($product['id_product']).' + AND `id_category`='.(int)$id_category + ); + $position++; + } +}