fix conflict adminProduct
This commit is contained in:
commit
91efe4469e
@ -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 '<p><input type="submit" class="button" name="submitDel'.$this->table.'" value="'.$this->l('Delete selection').'" onclick="return confirm(\''.$this->l('Delete selected items?', __CLASS__, TRUE, FALSE).'\');" /></p>';
|
||||
|
||||
if((int)$this->_category->id_parent == 1){
|
||||
echo '<hr>';
|
||||
echo '<h2>Ordonner les produits</h2>';
|
||||
echo '<p><input type="submit" class="button" name="reorder'.$this->table.'" value="'.$this->l('Order products').'" /></p>';
|
||||
}
|
||||
|
||||
echo '<hr>';
|
||||
$languages = Language::getLanguages(FALSE);
|
||||
|
268
modules/braderie/AdminBraderie.php
Normal file
268
modules/braderie/AdminBraderie.php
Normal file
@ -0,0 +1,268 @@
|
||||
<?php
|
||||
if(!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminBraderie extends AdminTab
|
||||
{
|
||||
private $_html = '';
|
||||
private $error = '';
|
||||
|
||||
public function display()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$id_category = Tools::getValue('id_category', 1);
|
||||
$id_product = Tools::getValue('id_product', false);
|
||||
|
||||
$db = Db::getInstance();
|
||||
/*$sql_category = '
|
||||
SELECT * FROM `'._DB_PREFIX_.'privatesale` ps
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ps.`id_category` = cl.`id_category`
|
||||
WHERE ps.`braderie` = 1
|
||||
AND cl.`id_lang` = '.(int) $cookie->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 .= '<link type="text/css" rel="stylesheet" href="'._MODULE_DIR_.'bulkupdate/chosen.min.css" />';
|
||||
$this->_html .= '<script type="text/javascript" src="'._MODULE_DIR_.'bulkupdate/chosen.jquery.min.js"></script>';
|
||||
$this->_html .= '<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
$(".chosen-select").chosen(
|
||||
{
|
||||
allow_single_deselect:true,
|
||||
placeholder_text_single : "Choisir une vente",
|
||||
no_results_text : "Aucun résultat",
|
||||
enable_split_word_search : true,
|
||||
search_contains : true,
|
||||
}
|
||||
);
|
||||
|
||||
var $token = "'.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'";
|
||||
var $product_id = 0;
|
||||
|
||||
$(\'#sale\').change(function() {
|
||||
$.ajax({
|
||||
type: \'POST\',
|
||||
url: \''._MODULE_DIR_.'braderie/ajax.php?action=getCategories'.'\',
|
||||
dataType: \'json\',
|
||||
data: { sale: $(this).val() },
|
||||
success: function(response) {
|
||||
$(\'#category\').empty();
|
||||
for (var i in response) {
|
||||
var html = \'<option value="\'+ response[i].id_category +\'">\'+ response[i].id_category +\' - \'+ response[i].name +\'</option>\';
|
||||
$(\'#category\').append(html);
|
||||
}
|
||||
$(".chosen-select").trigger("chosen:updated");
|
||||
$("#divider, #category_input_group, #ean_input_group, #storage_input_group, #button_input_group, #show_current_category_button, #quantity_input_group").show();
|
||||
$("#error").empty();
|
||||
},
|
||||
error: function(xhr) {
|
||||
$("#ean_from_product").empty();
|
||||
$("#error").empty().append(JSON.parse(xhr.responseText));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#category").change(function(event) {
|
||||
$("#show_current_category_button").show();
|
||||
});
|
||||
|
||||
$("#input_ean").change(function(event) {
|
||||
$.ajax({
|
||||
type: \'POST\',
|
||||
url: \''._MODULE_DIR_.'braderie/ajax.php?action=getProductId'.'\',
|
||||
dataType: \'json\',
|
||||
data: { ean: $(this).val() },
|
||||
success: function(response) {
|
||||
if (response.name == null) {
|
||||
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
|
||||
$("#ean_from_product").empty();
|
||||
return false;
|
||||
}
|
||||
|
||||
$product_id = response.id_product;
|
||||
$attibute_id = response.id_product_attribute;
|
||||
$("#ean_from_product").empty().append(response.name);
|
||||
if ($attibute_id) {
|
||||
$("#hidden_attribute_id").val($attibute_id);
|
||||
} else {
|
||||
$("#hidden_attribute_id").val(0);
|
||||
}
|
||||
$("#hidden_product_id").val($product_id);
|
||||
$("#error").empty()
|
||||
},
|
||||
error: function(xhr) {
|
||||
$("#ean_from_product").empty();
|
||||
$("#error").empty().append(JSON.parse(xhr.responseText));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#check_button").click(function(event) {
|
||||
|
||||
if ($product_id == undefined || $product_id == 0) {
|
||||
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($token.length == 0) {
|
||||
$("#error").empty().append("'.$this->l('Un problème de sécurité est survenu. Merci de réinitialisé la page').'");
|
||||
return false;
|
||||
}
|
||||
|
||||
window.open("?tab=AdminCatalog&updateproduct&id_product=" + $product_id + "&token=" + $token);
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#add_button").click(function(event) {
|
||||
event.preventDefault();
|
||||
if ($product_id == undefined || $product_id == 0) {
|
||||
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
|
||||
return false;
|
||||
}
|
||||
|
||||
var emplacement = $("#input_storage").val();
|
||||
|
||||
if (emplacement.length == 0 || emplacement>205) {
|
||||
$("#error").empty().append("'.$this->l('L\'emplacement n\'est pas renseigné ou est mal renseigné').'");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($("#input_quantity").val().length == 0) {
|
||||
$("#error").empty().append("'.$this->l('La quantité n\'est pas renseignée').'");
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#hidden_product_id").val($product_id);
|
||||
|
||||
$.ajax({
|
||||
type: \'POST\',
|
||||
url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\',
|
||||
dataType: \'json\',
|
||||
data: {
|
||||
parent_category: $("#sale").val(),
|
||||
category: $("#category").val(),
|
||||
storage: $("#input_storage").val(),
|
||||
product: $("#hidden_product_id").val(),
|
||||
quantity: $("#input_quantity").val(),
|
||||
attribute: $("#hidden_attribute_id").val()
|
||||
},
|
||||
success: function(response) {
|
||||
$("#error").empty().append(response);
|
||||
$("#input_ean, #input_storage").val("");
|
||||
$("#ean_from_product").empty();
|
||||
},
|
||||
error: function(xhr) {
|
||||
$("#error").empty().append(JSON.parse(xhr.responseText));
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#show_current_category_button").click(function() {
|
||||
$category = $("#category").val();
|
||||
if ($category.length == 0) {
|
||||
$("#error").empty().append("'.$this->l('Catégorie invalide').'");
|
||||
return false;
|
||||
}
|
||||
window.open("?tab=AdminCatalog&viewcategory&id_category=" + $category + "&token=" + $token, "_blank");
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>';
|
||||
echo $this->_html;
|
||||
}
|
||||
|
||||
private function _buildHtmlCategoryBlock($categories, $small_titles)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$token = Tools::getAdminToken('AdminBraderie'.(int)(Tab::getIdFromClassName('AdminBraderie')).(int)($cookie->id_employee));
|
||||
|
||||
$html = '
|
||||
<style>
|
||||
.chosen-container { width: 315px !important; }
|
||||
.button-container input { margin: 10px 25px; }
|
||||
#error, #ean_from_product { margin-left: 210px; }
|
||||
#error { font-weight: bold; margin-bottom: 20px; color: #CC0000; }
|
||||
</style>
|
||||
<fieldset>
|
||||
<legend>'.$this->l('Braderie').'</legend>';
|
||||
if ($this->error) {
|
||||
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
|
||||
} else {
|
||||
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
|
||||
}
|
||||
$html .= '<div class="margin-form">
|
||||
<label>'.$this->l('Ventes').' : </label>
|
||||
<select class="chosen-select" id="sale" name="sale">
|
||||
<option value=""></option>';
|
||||
|
||||
foreach ($categories as $key => $value) {
|
||||
$html .= '<option value="'.$value['id_category'].'">'.$value['id_category'].' - '.$value['name'].(!empty($small_titles[(int)$value['id_category']])?' - '.$small_titles[(int)$value['id_category']]:'').'</option>';
|
||||
}
|
||||
|
||||
$html .= ' </select>
|
||||
</div>
|
||||
<hr id="divider" style="display: none;">
|
||||
<div class="margin-form" id="category_input_group" style="display: none;">
|
||||
<label>'.$this->l('Catégories').' : </label>
|
||||
<select class="chosen-select" id="category" name="category">
|
||||
<option value=""></option>
|
||||
</select>
|
||||
<input type="submit" class="button" id="show_current_category_button" value="'.$this->l('Voir cette catégorie').'" style="margin-left: 20px; display: none">
|
||||
</div>
|
||||
<form id="formBraderie" action="?tab=AdminBraderie&token='.$token.'" method="POST">
|
||||
<div class="margin-form" id="ean_input_group" style="display: none;">
|
||||
<label>'.$this->l('Code EAN').' : </label>
|
||||
<input type="text" name="ean" id="input_ean">
|
||||
<p id="ean_from_product"></p>
|
||||
</div>
|
||||
<div class="margin-form" id="storage_input_group" style="display: none;">
|
||||
<label>'.$this->l('Emplacement').' : </label>
|
||||
<input type="text" name="storage" id="input_storage">
|
||||
</div>
|
||||
<div class="margin-form" id="quantity_input_group" style="display: none;">
|
||||
<label>'.$this->l('Quantité').' : </label>
|
||||
<input type="number" name="quantity" id="input_quantity" value="1">
|
||||
</div>
|
||||
<div class="margin-form button-container" id="button_input_group" style="display: none;">
|
||||
<input type="submit" class="button" name="adminbraderie" value="'.$this->l('Ajouter').'" style="margin-left: 200px;" id="add_button">
|
||||
<input type="submit" class="button" id="check_button" value="'.$this->l('Vérifier').'">
|
||||
</div>
|
||||
<input type="hidden" name="product" id="hidden_product_id">
|
||||
<input type="hidden" name="attribute" id="hidden_attribute_id">
|
||||
</form>
|
||||
</fieldset>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
228
modules/braderie/ajax.php
Normal file
228
modules/braderie/ajax.php
Normal file
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__).'../../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'../../../init.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
switch (Tools::getValue('action')) {
|
||||
case 'getCategories':
|
||||
die(json_encode(getCategories()));
|
||||
break;
|
||||
|
||||
case 'getProductId':
|
||||
die(json_encode(getProductId()));
|
||||
break;
|
||||
|
||||
case 'addToSellout':
|
||||
die(json_encode(addToSellout()));
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(418);
|
||||
die('I\'m a teapot');
|
||||
break;
|
||||
}
|
||||
|
||||
function getCategories()
|
||||
{
|
||||
global $cookie;
|
||||
$id_sale = (int)Tools::getValue('sale', false);
|
||||
|
||||
if (!$id_sale) {
|
||||
http_response_code(500);
|
||||
return Tools::displayError('Catégorie invalide');
|
||||
}
|
||||
|
||||
//$db = Db::getInstance();
|
||||
//$sql = 'SELECT * FROM `'._DB_PREFIX_.'privatesale_category` pc LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON pc.`id_category` = cl.`id_category` WHERE pc.`id_sale` = '.$id_sale.' AND cl.`id_lang` = '.(int)$cookie->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
modules/braderie/braderie.php
Normal file
49
modules/braderie/braderie.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
class Braderie extends Module
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user