refactor: Simplify product update logic and remove unused tax rules group handling

This commit is contained in:
2025-06-06 00:36:03 +02:00
parent 1d3d247a1a
commit 66d27c548b
2 changed files with 33 additions and 53 deletions

View File

@@ -7537,7 +7537,7 @@
},
"google-merchant_id-1.xml": {
"type": "-",
"size": 64085549,
"size": 64133014,
"lmtime": 0,
"modified": true
},
@@ -11780,8 +11780,8 @@
},
"import-product.php": {
"type": "-",
"size": 27503,
"lmtime": 1748716538167,
"size": 33542,
"lmtime": 1748903578581,
"modified": false
},
"index.php": {
@@ -18221,11 +18221,23 @@
},
"views": {
"js": {
"index.php": {
"type": "-",
"size": 1309,
"lmtime": 0,
"modified": false
},
"jquery.autocomplete_productsearch.js": {
"type": "-",
"size": 21892,
"lmtime": 1747228389587,
"modified": false
},
"leosearch.js": {
"type": "-",
"size": 5163,
"lmtime": 1748904347658,
"modified": false
}
}
}
@@ -50009,8 +50021,8 @@
},
"detail1526395446.tpl": {
"type": "-",
"size": 29782,
"lmtime": 1741161598708,
"size": 29810,
"lmtime": 1748904347660,
"modified": false
},
"detail1526396195.tpl": {

View File

@@ -55,68 +55,36 @@ foreach ( $products_array as $product )
$price = 0; // jeśli są kombinacje, to cena jest 0
$reference = $product['ean'];
$id_tax_rules_group = 62; // ID grupy reguł podatkowych
$active = 1; // Ustawienie produktu jako nieaktywny
$sql = 'UPDATE `' . _DB_PREFIX_ . 'product`
SET `price` = ' . (float)$price . ',
`id_tax_rules_group` = ' . (int)$id_tax_rules_group . ',
`active` = ' . (int)$active . '
WHERE `reference` = \'' . pSQL($reference) . '\'';
$result = Db::getInstance()->execute($sql);
$active = 0; // Ustawienie produktu jako nieaktywny
$result = Db::getInstance()->executeS('SELECT id_product FROM `' . _DB_PREFIX_ . 'product` WHERE `reference` = \'' . pSQL($reference) . '\'');
// $id_product może być tablicą
if ( is_array( $result ) )
// table `materac_product`
if ( $reference )
{
foreach ( $result as $id )
$sql = 'UPDATE `' . _DB_PREFIX_ . 'product` SET `price` = ' . (float)$price . ', `active` = ' . (int)$active . ' WHERE `reference` = \'' . pSQL($reference) . '\'';
$result = Db::getInstance()->execute($sql);
// table `materac_product_shop`
$products_ids = Db::getInstance()->executeS('SELECT id_product FROM `' . _DB_PREFIX_ . 'product` WHERE `reference` = \'' . pSQL($reference) . '\'');
foreach ( $products_ids as $id )
{
// update materac_product_shop where id_product = id_product
$sql_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_shop`
SET `price` = ' . (float)$price . ',
`id_tax_rules_group` = ' . (int)$id_tax_rules_group . ',
`active` = ' . (int)$active . '
WHERE `id_product` = ' . $id['id_product'];
$sql_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_shop` SET `price` = ' . (float)$price . ', `active` = ' . (int)$active . ' WHERE `id_product` = ' . (int)$id['id_product'];
$result_shop = Db::getInstance()->execute($sql_shop);
echo "Zaktualizowano produkt z referencją $reference, id_product: " . $id['id_product'] . ", cena: $price, id_tax_rules_group: $id_tax_rules_group, active: $active<br>";
echo "Zaktualizowano produkt z referencją $reference, id_product: " . $id['id_product'] . ", cena: $price, active: $active<br>";
}
}
else
{
// update materac_product_shop where id_product = id_product
$sql_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_shop`
SET `price` = ' . (float)$price . ',
`id_tax_rules_group` = ' . (int)$id_tax_rules_group . ',
`active` = ' . (int)$active . '
WHERE `id_product` = ' . (int)$result;
$result_shop = Db::getInstance()->execute($sql_shop);
if ( !$result_shop )
echo "Zaktualizowano produkt z referencją $reference, id_product: $result, cena: $price, id_tax_rules_group: $id_tax_rules_group, active: $active<br>";
}
// update materac_product_attribute by reference
foreach ( $product['combinations'] as $combination )
{
$sql_combination = 'UPDATE `' . _DB_PREFIX_ . 'product_attribute`
SET `price` = ' . (float)$combination['price'] . '
WHERE `reference` = \'' . pSQL($combination['ean']) . '\'';
$sql_combination = 'UPDATE `' . _DB_PREFIX_ . 'product_attribute` SET `price` = ' . (float)$combination['price'] . ' WHERE `reference` = \'' . pSQL($combination['ean']) . '\'';
$result_combination = Db::getInstance()->execute($sql_combination);
// get id_product_attribute from materac_product_attribute where reference = KodEAN-13
$id_product_attribute = Db::getInstance()->getValue('SELECT id_product_attribute FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `reference` = \'' . pSQL($combination['ean']) . '\'');
if ( !$result_combination )
$combination_ids = Db::getInstance()->executeS('SELECT id_product_attribute FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `reference` = \'' . pSQL($combination['ean']) . '\'');
foreach ( $combination_ids as $id_combination )
{
echo "Error: Cannot update product attribute with reference " . $combination['ean'] . "<br>";
continue;
$sql_combination_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_attribute_shop` SET `price` = ' . (float)$combination['price'] . ' WHERE `id_product_attribute` = ' . (int)$id_combination['id_product_attribute'];
$result_combination_shop = Db::getInstance()->execute($sql_combination_shop);
echo "Zaktualizowano kombinację z referencją " . $combination['ean'] . ", id_product_attribute: " . $id_combination['id_product_attribute'] . ", cena: " . $combination['price'] . "<br>";
}
// update materac_product_attribute_shop where id_product_attribute = id_product_attribute
$sql_combination_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_attribute_shop`
SET `price` = ' . (float)$combination['price'] . '
WHERE `id_product_attribute` = ' . (int)$id_product_attribute;
$result_combination_shop = Db::getInstance()->execute($sql_combination_shop);
}
echo "Zaktualizowano kombinacje dla produktu z referencją $reference<br>";
}
exit;