Merge remote-tracking branch 'origin/ticket/r16492-bulkupdate'
This commit is contained in:
commit
ffe8c187e8
@ -281,26 +281,26 @@ class TaxCore extends ObjectModel
|
||||
*/
|
||||
public static function getProductTaxRate($id_product, $id_address = NULL)
|
||||
{
|
||||
$id_country = (int)Country::getDefaultCountryId();
|
||||
$id_state = 0;
|
||||
$id_county = 0;
|
||||
$rate = 0;
|
||||
if (!empty($id_address))
|
||||
{
|
||||
$address_infos = Address::getCountryAndState($id_address);
|
||||
if ($address_infos['id_country'])
|
||||
{
|
||||
$id_country = (int)($address_infos['id_country']);
|
||||
$id_state = (int)$address_infos['id_state'];
|
||||
$id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
|
||||
$id_country = (int)Country::getDefaultCountryId();
|
||||
$id_state = 0;
|
||||
$id_county = 0;
|
||||
$rate = 0;
|
||||
if (!empty($id_address)) {
|
||||
$address_infos = Address::getCountryAndState($id_address);
|
||||
if ($address_infos['id_country']) {
|
||||
$id_country = (int)($address_infos['id_country']);
|
||||
$id_state = (int)$address_infos['id_state'];
|
||||
$id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
|
||||
}
|
||||
|
||||
if (!empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT'))
|
||||
return 0;
|
||||
if (!empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT')) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rate = Tax::getProductTaxRateViaRules((int)$id_product, (int)$id_country, (int)$id_state, (int)$id_county))
|
||||
return $rate;
|
||||
if ($rate = Tax::getProductTaxRateViaRules((int)$id_product, (int)$id_country, (int)$id_state, (int)$id_county)) {
|
||||
return $rate;
|
||||
}
|
||||
|
||||
return $rate;
|
||||
}
|
||||
|
@ -537,47 +537,53 @@ class AdminBulkUpdate extends AdminTab {
|
||||
}
|
||||
|
||||
$output .= '<p class="conf">'.$this->l('Products updated').'</p>';
|
||||
} elseif(Tools::isSubmit('submitUploadPrices')) {
|
||||
}
|
||||
// MAJ Rapide produits (Reduction, Prix d'achat HT, Prix d'achat TTC)
|
||||
elseif(Tools::isSubmit('submitUploadPrices'))
|
||||
{
|
||||
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
|
||||
fgetcsv($f, 0, ';');
|
||||
|
||||
$products = array();
|
||||
$prices = array();
|
||||
|
||||
if(Tools::getValue('price_process') == 2) {
|
||||
while($line = fgetcsv($f, 0, ';')) {
|
||||
if(empty($line[0])) {
|
||||
if (Tools::getValue('price_process') == 2) {
|
||||
while ($line = fgetcsv($f, 0, ';')) {
|
||||
if (empty($line[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$products[] = (int) $line[0];
|
||||
}
|
||||
} elseif(Tools::getValue('price_process') == 3
|
||||
|| Tools::getValue('price_process') == 4){
|
||||
while($line = fgetcsv($f, 0, ';')) {
|
||||
if(empty($line[0])) {
|
||||
}
|
||||
// Prix d'achat HT || Prix public TTC
|
||||
elseif (Tools::getValue('price_process') == 3 || Tools::getValue('price_process') == 4) {
|
||||
while ($line = fgetcsv($f, 0, ';')) {
|
||||
if (empty($line[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$prices[] = array(
|
||||
(int) $line[0],
|
||||
$line[1]
|
||||
(int) $line[0],
|
||||
$line[1]
|
||||
);
|
||||
}
|
||||
}else {
|
||||
while($line = fgetcsv($f, 0, ';')) {
|
||||
if(empty($line[0])) {
|
||||
}
|
||||
// Reduction
|
||||
else {
|
||||
while ($line = fgetcsv($f, 0, ';')) {
|
||||
if (empty($line[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!isset($line[1])) {
|
||||
if (!isset($line[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$products[] = (int) $line[0];
|
||||
$prices[] = array(
|
||||
(int) $line[0],
|
||||
(float) $line[1] > 1? (float) $line[1] / 100: (float) $line[1]
|
||||
(float) $line[1] > 1 ? (float) $line[1] / 100: (float) $line[1]
|
||||
);
|
||||
|
||||
}
|
||||
@ -585,17 +591,18 @@ class AdminBulkUpdate extends AdminTab {
|
||||
|
||||
fclose($f);
|
||||
|
||||
if(Tools::getValue('price_process') == 1
|
||||
|| Tools::getValue('price_process') == 2) {
|
||||
// Reduction || ...
|
||||
if (Tools::getValue('price_process') == 1 || Tools::getValue('price_process') == 2) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
DELETE FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` IN ('.implode(', ', $products).')
|
||||
');
|
||||
}
|
||||
|
||||
if(Tools::getValue('price_process') == 1) {
|
||||
foreach($prices as $price) {
|
||||
if((int) $price[0] != 0) {
|
||||
// Reduction
|
||||
if (Tools::getValue('price_process') == 1) {
|
||||
foreach ($prices as $price) {
|
||||
if ((int) $price[0] != 0) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'specific_price` VALUES (
|
||||
DEFAULT,
|
||||
@ -617,51 +624,64 @@ class AdminBulkUpdate extends AdminTab {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Tools::getValue('price_process') == 3) {
|
||||
foreach($prices as $price) {
|
||||
if((int) $price[0] != 0){
|
||||
|
||||
// Prix d'achat HT
|
||||
if (Tools::getValue('price_process') == 3) {
|
||||
foreach ($prices as $price) {
|
||||
if ((int) $price[0] != 0){
|
||||
$price[1] = str_replace(',', '.', $price[1]);
|
||||
$price_ht = floatval($price[1]);
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'product`
|
||||
SET wholesale_price = '. (float)$price_ht .'
|
||||
WHERE id_product ='. (int)$price[0]);
|
||||
}else{
|
||||
} else {
|
||||
$output .= '<p class="error">ID produit à 0, ligne non traitée : '.serialize($price).'</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Tools::getValue('price_process') == 4) {
|
||||
foreach($prices as $price) {
|
||||
if((int) $price[0] != 0){
|
||||
|
||||
// Prix public TTC
|
||||
if (Tools::getValue('price_process') == 4) {
|
||||
foreach ($prices as $price) {
|
||||
if ((int) $price[0] != 0){
|
||||
$price[1] = str_replace(',', '.', $price[1]);
|
||||
$price_ht = floatval($price[1] / 1.20);
|
||||
// Find Tax for this id product
|
||||
// product.id_tax_rules_group => tax_rules_group => tax_rule => tax.rate
|
||||
$tax = new Tax();
|
||||
$taxValue = $tax->getProductTaxRate((int)$price[0]);
|
||||
if ($taxValue == 0) {
|
||||
$taxValue = 20;
|
||||
}
|
||||
|
||||
$price_ht = floatval($price[1] / (1 + $taxValue / 100) );
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'product`
|
||||
SET price = '. (float)$price_ht .'
|
||||
WHERE id_product ='. (int)$price[0]);
|
||||
}else{
|
||||
} else {
|
||||
$output .= '<p class="error">ID produit à 0, ligne non traitée : '.serialize($price).'</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '<p class="conf">'.$this->l('Products updated').'</p>';
|
||||
} elseif(Tools::isSubmit('submitUploadProductDescriptions')) {
|
||||
}
|
||||
elseif (Tools::isSubmit('submitUploadProductDescriptions')) {
|
||||
$id_lang = Tools::getValue('description_process');
|
||||
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
|
||||
fgetcsv($f, 0, ';');
|
||||
|
||||
$products = array();
|
||||
|
||||
while($line = fgetcsv($f, 0, ';')) {
|
||||
if($line[0] == '' || $line[1] == '') {
|
||||
while ($line = fgetcsv($f, 0, ';')) {
|
||||
if ($line[0] == '' || $line[1] == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$products[] = $line;
|
||||
}
|
||||
foreach($products as $line) {
|
||||
foreach ($products as $line) {
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'product_lang`
|
||||
SET `description` = "'. pSQL($line[1],true) .'"
|
||||
@ -675,14 +695,15 @@ class AdminBulkUpdate extends AdminTab {
|
||||
|
||||
fclose($f);
|
||||
$output .= '<p class="conf">'.$this->l('Products updated').'</p>';
|
||||
} elseif(Tools::isSubmit('submitUploadCombinations')) {
|
||||
}
|
||||
elseif (Tools::isSubmit('submitUploadCombinations')) {
|
||||
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
|
||||
fgetcsv($f, 0, ';');
|
||||
|
||||
$products = array();
|
||||
|
||||
while($line = fgetcsv($f, 0, ';')) {
|
||||
if(empty($line[0])) {
|
||||
while ($line = fgetcsv($f, 0, ';')) {
|
||||
if (empty($line[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -713,7 +734,7 @@ class AdminBulkUpdate extends AdminTab {
|
||||
|
||||
$output .= '<p class="conf">'.$this->l('Products updated').'</p>';
|
||||
|
||||
} elseif(Tools::isSubmit('submitExportDeb')){
|
||||
} elseif (Tools::isSubmit('submitExportDeb')){
|
||||
set_time_limit(300);
|
||||
$id_lang = Tools::getValue('id_lang', $cookie->id_lang);
|
||||
$deb = Tools::getValue('deb', 0);
|
||||
|
Loading…
Reference in New Issue
Block a user