diff --git a/adm/tabs/AdminProducts.php b/adm/tabs/AdminProducts.php index 16719843..1cb0028e 100755 --- a/adm/tabs/AdminProducts.php +++ b/adm/tabs/AdminProducts.php @@ -245,6 +245,62 @@ class AdminProducts extends AdminTab Tools::redirectAdmin($currentIndex.(Tools::getValue('id_category') ? '&id_category='.Tools::getValue('id_category') : '').'&token='.($token ? $token : $this->token)); } + if (Tools::isSubmit('reorderproduct')) { + global $cookie, $currentIndex; + + // Position mise à 0 + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'category_product` + SET `position` = 0 + WHERE `id_category` = '.(int)$this->_category->id + ); + + // Récupération de tous les produits de la catégorie ordonée + // selon la position de la sous-catégorie puis de la position dans la sous catégorie et sinon par id_product + $first_products = Db::getInstance()->ExecuteS(' + SELECT cp.* + FROM `'._DB_PREFIX_.'category_product` cp + LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.id_parent = cp.id_category) + LEFT JOIN `'._DB_PREFIX_.'category_product` cp2 ON (cp2.id_category = c.id_category AND cp2.id_product=cp.id_product) + RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) + WHERE cp.id_category ='.(int)$this->_category->id.' + AND cp2.id_product IS NOT NULL + ORDER BY c.position, cp2.position + '); + $second_products = Db::getInstance()->ExecuteS(' + SELECT cp.* + FROM `'._DB_PREFIX_.'category_product` cp + RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) + WHERE cp.id_category ='.(int)$this->_category->id.' + AND cp.id_product NOT IN + ( + SELECT cp2.id_product + FROM `'._DB_PREFIX_.'category_product` cp2 + WHERE cp2.id_category IN + ( + SELECT id_category + FROM `'._DB_PREFIX_.'category` + WHERE id_parent ='.(int)$this->_category->id.' + ) + ) + ORDER BY cp.id_product + '); + + $products = array_merge($first_products,$second_products); + // Update des postions + foreach ($products as $key => $product) { + if ($key == 0){ + continue; + } + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'category_product` + SET `position` = '. (int)($key) .' + WHERE `id_product` = '.(int)($product['id_product']) + ); + } + Tools::redirectAdmin($currentIndex.(Tools::getValue('id_category') ? '&id_category='.Tools::getValue('id_category') : '').'&token='.($token ? $token : $this->token)); + } + if(Tools::isSubmit('cloneProduct')){ $products = Tools::getValue('productBox'); $id_category_clonage = Tools::getValue('id_category_clonage'); @@ -1634,6 +1690,12 @@ class AdminProducts extends AdminTab if ($this->delete) echo '

'; + + if((int)$this->_category->id_parent == 1){ + echo '
'; + echo '

Ordonner les produits

'; + echo '

'; + } echo '
'; $languages = Language::getLanguages(FALSE); diff --git a/modules/braderie/AdminBraderie.php b/modules/braderie/AdminBraderie.php new file mode 100644 index 00000000..a7ef9f02 --- /dev/null +++ b/modules/braderie/AdminBraderie.php @@ -0,0 +1,268 @@ +id_lang;*/ + $sql_category = ' + SELECT c.`id_category`, cl.`name` FROM `'._DB_PREFIX_.'category` c + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category` + WHERE c.`id_parent` = 1 + AND cl.`id_lang` = '.(int) $cookie->id_lang.' + ORDER BY c.`id_category` DESC'; + $categories = $db->ExecuteS($sql_category); + + $ids_categories = array(); + foreach ($categories as $key => $category) { + $ids_categories[] = (int) $category["id_category"]; + } + + $small_titles = array(); + foreach (Db::getInstance()->executeS(' + SELECT ex.`value`, ps.`id_category` + FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` ex + LEFT JOIN `'._DB_PREFIX_.'privatesale` ps on ex.`id_sale` = ps.`id_sale` + LEFT JOIN `'._DB_PREFIX_.'category` c on c.`id_category` = ps.`id_category` + WHERE ex.`id_field` = 1 + AND ex.`id_lang` = '. (int) $cookie->id_lang.' + AND c.`id_category` IN ('.implode(',', $ids_categories).') + ') as $key => $data) { + $small_titles[(int) $data['id_category']] = $data['value']; + } + + $this->_html .= $this->_buildHtmlCategoryBlock($categories, $small_titles); + + $this->_html .= ''; + $this->_html .= ''; + $this->_html .= ''; + echo $this->_html; + } + + private function _buildHtmlCategoryBlock($categories, $small_titles) + { + global $cookie; + + $token = Tools::getAdminToken('AdminBraderie'.(int)(Tab::getIdFromClassName('AdminBraderie')).(int)($cookie->id_employee)); + + $html = ' + +
+ '.$this->l('Braderie').''; + if ($this->error) { + $html .= '

'.$this->error.'

'; + } else { + $html .= '

'.$this->error.'

'; + } + $html .= '
+ + +
+ + +
+ + + + + + +
+
'; + return $html; + } + +} diff --git a/modules/braderie/ajax.php b/modules/braderie/ajax.php new file mode 100644 index 00000000..e0a8e2b3 --- /dev/null +++ b/modules/braderie/ajax.php @@ -0,0 +1,228 @@ +id_lang; + + return Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'category` c + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category` + WHERE c.`id_parent` = '.$id_sale.' + AND cl.`id_lang` = '.(int)$cookie->id_lang + ); +} + +function getProductId() +{ + global $cookie; + $ean = (float)Tools::getValue('ean', false); + + if (!$ean) { + http_response_code(500); + return Tools::displayError('Code EAN invalide'); + } + + if (!is_float($ean)) { + http_response_code(500); + return Tools::displayError('Code EAN invalide'); + } + + //$db = Db::getInstance(); + //$sql = 'SELECT `'._DB_PREFIX_.'product_lang`.`id_product`, `'._DB_PREFIX_.'product_lang`.`name` FROM `'._DB_PREFIX_.'product` LEFT JOIN `'._DB_PREFIX_.'product_lang` ON `'._DB_PREFIX_.'product`.id_product = `'._DB_PREFIX_.'product_lang`.id_product WHERE `ean13` = '.$ean.' AND `id_lang` = '.(int)$cookie->id_lang.' ORDER BY `date_add` DESC LIMIT 1'; + $result = Db::getInstance()->getRow(' + SELECT p.`id_product`, p.`reference`, pl.`name` + FROM `'._DB_PREFIX_.'product` p + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`) + WHERE p.`ean13` = '.pSQL($ean).' + AND pl.`id_lang` = '.(int)$cookie->id_lang.' + ORDER BY `date_add` DESC + '); + + if (empty($result)) { + //$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_attribute` WHERE `ean13` = '.pSQL($ean).' ORDER BY `id_product_attribute` DESC LIMIT 1'; + /*$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_lang` WHERE `id_product` = '.(int)($result[0]['id_product']).' LIMIT 1'; + $tmp = $db->ExecuteS($sql)[0]; + $result[0]['name'] = $tmp['name']; + $result[0]['reference'] = ($result[0]['reference']) ? $result[0]['reference'] : $tmp['reference'];*/ + + $result = Db::getInstance()->getRow(' + SELECT pa.*, pl.`name`, p.`reference` as product_reference + FROM `'._DB_PREFIX_.'product_attribute` pa + LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = pa.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`) + WHERE pa.`ean13` = '.pSQL($ean).' + AND pl.`id_lang` = '.(int)$cookie->id_lang.' + ORDER BY pa.`id_product_attribute` + DESC' + ); + $result['reference'] = (!empty($result['reference'])) ? $result['reference'] : $result['product_reference']; + + } + + if (!empty($result)) { + return $result; + } else { + http_response_code(500); + return Tools::displayError('Aucun produit trouvé'); + } +} + +function addToSellout() +{ + $parent_category = (int)Tools::getValue('parent_category', false); + if (!$parent_category || !is_int($parent_category)) { + http_response_code(500); + return Toold::displayError('La catégorie principale n\'est pas valide'); + } + + $category = (int)Tools::getValue('category', false); + if (!$category || !is_int($category)) { + http_response_code(500); + return Toold::displayError('La catégorie n\'est pas valide'); + } + + $product_id = (int)Tools::getValue('product', false); + if (!$product_id || !is_int($product_id)) { + http_response_code(500); + return Tools::displayError('Le produit n\'est pas valide'); + } + + $quantity = (int)Tools::getValue('quantity', false); + if (!$quantity || !is_int($quantity)) { + http_response_code(500); + return Tools::displayError('La quantitée n\'est pas valide'); + } + + $storage = Tools::getValue('storage'); + if (empty($storage)) { + http_response_code(500); + return Tools::displayError('L\'emplacement n\'est pas valide'); + } + + $id_attribute = (int)Tools::getValue('attribute', false); + + // duplication produit classique + $product = new Product($product_id); + $id_product_old = $product->id; + unset($product->id); + unset($product->id_product); + $product->active = 1; + $product->quantity = $quantity; + $product->reference = $storage.'-'.$product->reference; + + $languages = Language::getLanguages(false); + foreach ($languages as $key => $language) { + $category_name = Db::getInstance()->getRow(' + SELECT cl.`name` + FROM `'._DB_PREFIX_.'category_lang` cl + LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON (ps.`id_category` = cl.`id_category`) + LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` pps ON (pps.`id_sale` = ps.`id_sale`) + WHERE pps.`id_product` = '.(int)$id_product_old.' + AND cl.`id_lang` = '.(int)$language['id_lang'] + ); + $product->name[(int)$language['id_lang']] = $product->name[$language['id_lang']].' - '.strtoupper($category_name['name']); + } + + $product->id_category_default = (int)$category; + + if ($product->add()) { + if (!$id_attribute) { + $combinationImages = Product::duplicateAttributes($id_product_old, $product->id, $quantity); + } else { + // duplication spécific attribute + $combinationImages = Product::duplicateOneAttribute($id_product_old, $product->id, (int) $id_attribute, $quantity); + } + + Product::duplicateSpecificPrices($id_product_old, $product->id); + Product::duplicateFeatures($id_product_old, $product->id); + Product::duplicateAccessories($id_product_old, $product->id); + GroupReduction::duplicateReduction($id_product_old, $product->id); + + $product->UpdateCategories(array((int)$category,(int)$parent_category)); + + /*$max_position = Db::getInstance()->getValue("SELECT MAX(cp.`position`) AS max FROM `"._DB_PREFIX_."category_product` cp WHERE cp.`id_category`=" . (int)$category); + $add_category = Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."category_product` (`id_product`, `id_category`, `position`) + VALUES ( + '". $product->id ."', + '". (int)$category ."', + '". (int)($max_position + 1 ) ."' + )"); + + $max_position_in_parent = Db::getInstance()->getValue("SELECT MAX(cp.`position`) AS max FROM `"._DB_PREFIX_."category_product` cp WHERE cp.`id_category`=" . (int)$parent_category); + $add_parent_category = Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."category_product` (`id_product`, `id_category`, `position`) + VALUES ( + '". $product->id ."', + '". (int)$parent_category ."', + '". (int)($max_position_in_parent + 1 ) ."' + )");*/ + + if ($product->hasAttributes()) + Product::updateDefaultAttribute($product->id); + + Image::duplicateProductImages($id_product_old, $product->id, $combinationImages); + } + return Tools::displayError('Le produit à été mis dans la braderie'); +} + +function pSQLArray($data) +{ + foreach ($data as $key => $value) { + if (is_array($value)) { + $this->pSQLArray($value); + } else { + $data[$key] = pSQL($value); + } + } + return $data; +} + +function recurse_copy($src, $dst) { + if (is_dir($src) && is_dir($dst)) { + $dir = opendir($src); + mkdir($dst); + while(false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' )) { + if ( is_dir($src . '/' . $file) ) { + recurse_copy($src . '/' . $file, $dst . '/' . $file); + } + else { + copy($src . '/' . $file, $dst . '/' . $file); + } + } + } + } +} diff --git a/modules/braderie/braderie.php b/modules/braderie/braderie.php new file mode 100644 index 00000000..65e591e2 --- /dev/null +++ b/modules/braderie/braderie.php @@ -0,0 +1,49 @@ +name = 'braderie'; + $this->tab = 'administration'; + $this->version = '1.0'; + parent::__construct(); + + $this->displayName = $this->l('Braderie'); + $this->description = $this->l('Gestion de la braderie'); + + $this->_html = ''; + } + + public function install() + { + $tabs_i18n = array( + 'fr' => 'Braderie', + 'en' => 'Sellout', + ); + + $t = new Tab(); + $t->id_parent = (int) Tab::getIdFromClassName('AdminCatalog'); + $st->position = (int) Tab::getNewLastPosition($t->id_parent); + $t->active = TRUE; + $t->module = 'braderie'; + $t->class_name = 'AdminBraderie'; + foreach(Language::getLanguages() as $lang) { + if(isset($tabs_i18n[$lang['iso_code']])) { + $t->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']]; + } else { + $t->name[$lang['id_lang']] = $tabs_i18n['en']; + } + } + $t->save(); + + return parent::install(); + } + + public function uninstall() + { + if (parent::uninstall() == false) + return false; + return true; + } + +} diff --git a/override/classes/Product.php b/override/classes/Product.php index afc4251d..eacd73d9 100644 --- a/override/classes/Product.php +++ b/override/classes/Product.php @@ -102,4 +102,87 @@ class Product extends ProductCore WHERE pa.`id_product_attribute` = '.(int)($id_product_attribute).' ORDER BY pa.`id_product_attribute`'); } + + + public static function duplicateOneAttribute($id_product_old, $id_product_new, $old_attribute_id, $quantity = 0) + { + $return = true; + $combinationImages = array(); + + $result = Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'product_attribute` + WHERE `id_product` = '.(int)($id_product_old).' AND `id_product_attribute` = '.(int)($old_attribute_id)); + foreach ($result as $row) + { + $id_product_attribute_old = (int)($row['id_product_attribute']); + $result2 = Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'product_attribute_combination` + WHERE `id_product_attribute` = '.$id_product_attribute_old); + + if ($quantity>0) { + $row['quantity'] = $quantity; + } + $row['id_product'] = $id_product_new; + unset($row['id_product_attribute']); + $return &= Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute', $row, 'INSERT'); + + $id_product_attribute_new = (int)(Db::getInstance()->Insert_ID()); + if ($resultImages = self::_getAttributeImageAssociations($id_product_attribute_old)) + { + $combinationImages['old'][$id_product_attribute_old] = $resultImages; + $combinationImages['new'][$id_product_attribute_new] = $resultImages; + } + foreach ($result2 AS $row2) + { + $row2['id_product_attribute'] = $id_product_attribute_new; + $return &= Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute_combination', $row2, 'INSERT'); + } + } + return !$return ? false : $combinationImages; + } + + /* + * @Override + * Ajout d'une quantité choisie + */ + public static function duplicateAttributes($id_product_old, $id_product_new, $quantity = 0) + { + $return = true; + $combinationImages = array(); + + $result = Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'product_attribute` + WHERE `id_product` = '.(int)($id_product_old)); + foreach ($result as $row) + { + $id_product_attribute_old = (int)($row['id_product_attribute']); + $result2 = Db::getInstance()->ExecuteS(' + SELECT * + FROM `'._DB_PREFIX_.'product_attribute_combination` + WHERE `id_product_attribute` = '.$id_product_attribute_old); + + if ($quantity>0) { + $row['quantity'] = $quantity; + } + $row['id_product'] = $id_product_new; + unset($row['id_product_attribute']); + $return &= Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute', $row, 'INSERT'); + + $id_product_attribute_new = (int)(Db::getInstance()->Insert_ID()); + if ($resultImages = self::_getAttributeImageAssociations($id_product_attribute_old)) + { + $combinationImages['old'][$id_product_attribute_old] = $resultImages; + $combinationImages['new'][$id_product_attribute_new] = $resultImages; + } + foreach ($result2 AS $row2) + { + $row2['id_product_attribute'] = $id_product_attribute_new; + $return &= Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute_combination', $row2, 'INSERT'); + } + } + return !$return ? false : $combinationImages; + } }