feat: Update product tax rules and disable products containing "AMZ" in their names
This commit is contained in:
24
.vscode/ftp-kr.sync.cache.json
vendored
24
.vscode/ftp-kr.sync.cache.json
vendored
@@ -7537,13 +7537,13 @@
|
|||||||
},
|
},
|
||||||
"google-merchant_id-1.xml": {
|
"google-merchant_id-1.xml": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 67206135,
|
"size": 67546876,
|
||||||
"lmtime": 0,
|
"lmtime": 0,
|
||||||
"modified": true
|
"modified": true
|
||||||
},
|
},
|
||||||
"google-merchant_id-2.xml": {
|
"google-merchant_id-2.xml": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 2735059,
|
"size": 2730429,
|
||||||
"lmtime": 0,
|
"lmtime": 0,
|
||||||
"modified": true
|
"modified": true
|
||||||
},
|
},
|
||||||
@@ -21188,21 +21188,21 @@
|
|||||||
},
|
},
|
||||||
"theme.css": {
|
"theme.css": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 433653,
|
"size": 433642,
|
||||||
"lmtime": 1741161153571,
|
"lmtime": 1747727146233,
|
||||||
"modified": false
|
"modified": false
|
||||||
},
|
},
|
||||||
"theme.css.map": {
|
"theme.css.map": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 1360070,
|
"size": 1360031,
|
||||||
"lmtime": 1742304582226,
|
"lmtime": 1747727146233,
|
||||||
"modified": true
|
"modified": false
|
||||||
},
|
},
|
||||||
"theme.scss": {
|
"theme.scss": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 640863,
|
"size": 640847,
|
||||||
"lmtime": 1742304582234,
|
"lmtime": 1747727143345,
|
||||||
"modified": true
|
"modified": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fonts": {
|
"fonts": {
|
||||||
@@ -24340,8 +24340,8 @@
|
|||||||
"js": {
|
"js": {
|
||||||
"custom.js": {
|
"custom.js": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 28210,
|
"size": 28364,
|
||||||
"lmtime": 1747228389623,
|
"lmtime": 1747727195285,
|
||||||
"modified": false
|
"modified": false
|
||||||
},
|
},
|
||||||
"index.php": {
|
"index.php": {
|
||||||
|
|||||||
@@ -3,6 +3,57 @@
|
|||||||
include(dirname(__FILE__) . '/config/config.inc.php');
|
include(dirname(__FILE__) . '/config/config.inc.php');
|
||||||
include(dirname(__FILE__) . '/init.php');
|
include(dirname(__FILE__) . '/init.php');
|
||||||
|
|
||||||
|
// Pobierz aktualny język kontekstu (ustaw odpowiedni ID języka, np. 1 dla polskiego)
|
||||||
|
$id_lang = Context::getContext()->language->id;
|
||||||
|
|
||||||
|
// Znajdź wszystkie produkty, których nazwa zawiera " AMZ"
|
||||||
|
$sql = '
|
||||||
|
SELECT p.`id_product`
|
||||||
|
FROM `' . _DB_PREFIX_ . 'product_lang` pl
|
||||||
|
JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = pl.`id_product`
|
||||||
|
WHERE pl.`id_lang` = ' . (int)$id_lang . '
|
||||||
|
AND pl.`name` LIKE \'% AMZ%\'
|
||||||
|
';
|
||||||
|
$products = Db::getInstance()->executeS($sql);
|
||||||
|
|
||||||
|
if (!empty($products)) {
|
||||||
|
foreach ($products as $row) {
|
||||||
|
$id_product = (int)$row['id_product'];
|
||||||
|
|
||||||
|
// Ustaw id_tax_rules_group = 62 w tabeli product
|
||||||
|
Db::getInstance()->update(
|
||||||
|
'product',
|
||||||
|
['id_tax_rules_group' => 62],
|
||||||
|
'id_product = ' . $id_product
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ustaw id_tax_rules_group = 62 w tabeli product_shop (dla sklepu o ID = 1)
|
||||||
|
Db::getInstance()->update(
|
||||||
|
'product_shop',
|
||||||
|
['id_tax_rules_group' => 62],
|
||||||
|
'id_product = ' . $id_product
|
||||||
|
);
|
||||||
|
|
||||||
|
// disable product
|
||||||
|
Db::getInstance()->update(
|
||||||
|
'product',
|
||||||
|
['active' => 0],
|
||||||
|
'id_product = ' . $id_product
|
||||||
|
);
|
||||||
|
|
||||||
|
Db::getInstance()->update(
|
||||||
|
'product_shop',
|
||||||
|
['active' => 0],
|
||||||
|
'id_product = ' . $id_product
|
||||||
|
);
|
||||||
|
}
|
||||||
|
echo 'Zaktualizowano stawkę VAT (62) dla wszystkich produktów zawierających "AMZ" w nazwie.';
|
||||||
|
} else {
|
||||||
|
echo 'Nie znaleziono produktów z "AMZ" w nazwie.';
|
||||||
|
}
|
||||||
|
|
||||||
|
die( '-- Import zakończony --' );
|
||||||
|
|
||||||
// Load XML file
|
// Load XML file
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$xmlString = file_get_contents('https://cdn.projectpro.pl/drmaterac.pl/produkty-amz.xml');
|
$xmlString = file_get_contents('https://cdn.projectpro.pl/drmaterac.pl/produkty-amz.xml');
|
||||||
@@ -15,6 +66,9 @@ if (!$xml) {
|
|||||||
die("Error: Cannot parse XML");
|
die("Error: Cannot parse XML");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$config['update_price'] = false; // Ustaw na true, jeśli chcesz aktualizować ceny produktów
|
||||||
|
$config['update_tax_id'] = true; // Ustaw na true, jeśli chcesz aktualizować ID podatku
|
||||||
|
|
||||||
// Logowanie czasu wykonania
|
// Logowanie czasu wykonania
|
||||||
function logTime($message, $startTime) {
|
function logTime($message, $startTime) {
|
||||||
file_put_contents('import_log.txt', $message . ' - Czas: ' . round(microtime(true) - $startTime, 10) . " s\n", FILE_APPEND);
|
file_put_contents('import_log.txt', $message . ' - Czas: ' . round(microtime(true) - $startTime, 10) . " s\n", FILE_APPEND);
|
||||||
@@ -58,7 +112,7 @@ function createAttribute($name, $values) {
|
|||||||
|
|
||||||
Db::getInstance()->insert('attribute_group_shop', [
|
Db::getInstance()->insert('attribute_group_shop', [
|
||||||
'id_attribute_group' => (int)$attributeGroup->id,
|
'id_attribute_group' => (int)$attributeGroup->id,
|
||||||
'id_shop' => 2
|
'id_shop' => 1
|
||||||
], false, true, Db::REPLACE);
|
], false, true, Db::REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +126,7 @@ function createAttribute($name, $values) {
|
|||||||
|
|
||||||
Db::getInstance()->insert('attribute_shop', [
|
Db::getInstance()->insert('attribute_shop', [
|
||||||
'id_attribute' => (int)$attribute->id,
|
'id_attribute' => (int)$attribute->id,
|
||||||
'id_shop' => 2
|
'id_shop' => 1
|
||||||
], false, true, Db::REPLACE);
|
], false, true, Db::REPLACE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +308,7 @@ function calculatePriceImpact($basePrice, $combinationPrice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addProductToShops($product) {
|
function addProductToShops($product) {
|
||||||
$shops = [1, 2];
|
$shops = [1];
|
||||||
foreach ($shops as $shopId) {
|
foreach ($shops as $shopId) {
|
||||||
Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'product_shop` (`id_product`, `id_shop`, `id_category_default`, `price`, `active`)
|
Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'product_shop` (`id_product`, `id_shop`, `id_category_default`, `price`, `active`)
|
||||||
VALUES ('.(int)$product->id.', '.(int)$shopId.', 2, '.(float)$product->price.', 1)');
|
VALUES ('.(int)$product->id.', '.(int)$shopId.', 2, '.(float)$product->price.', 1)');
|
||||||
@@ -263,7 +317,7 @@ function addProductToShops($product) {
|
|||||||
|
|
||||||
// Funkcja do przypisania kombinacji do obu sklepów
|
// Funkcja do przypisania kombinacji do obu sklepów
|
||||||
function addCombinationToShops($combination) {
|
function addCombinationToShops($combination) {
|
||||||
$shops = [1, 2];
|
$shops = [1];
|
||||||
foreach ($shops as $shopId) {
|
foreach ($shops as $shopId) {
|
||||||
Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'product_attribute_shop` (`id_product_attribute`, `id_product`, `id_shop`, `price`)
|
Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'product_attribute_shop` (`id_product_attribute`, `id_product`, `id_shop`, `price`)
|
||||||
VALUES ('.(int)$combination->id.', '.(int)$combination->id_product.', '.(int)$shopId.', '.(float)$combination->price.')');
|
VALUES ('.(int)$combination->id.', '.(int)$combination->id_product.', '.(int)$shopId.', '.(float)$combination->price.')');
|
||||||
@@ -272,7 +326,7 @@ function addCombinationToShops($combination) {
|
|||||||
|
|
||||||
// Funkcja do dodawania obrazów do obu sklepów
|
// Funkcja do dodawania obrazów do obu sklepów
|
||||||
function addImageToShops($imageId, $productId) {
|
function addImageToShops($imageId, $productId) {
|
||||||
$shops = [1, 2];
|
$shops = [1];
|
||||||
foreach ($shops as $shopId) {
|
foreach ($shops as $shopId) {
|
||||||
Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'image_shop` (`id_image`, `id_product`, `id_shop`, `cover`)
|
Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'image_shop` (`id_image`, `id_product`, `id_shop`, `cover`)
|
||||||
VALUES ('.(int)$imageId.', '.(int)$productId.', '.(int)$shopId.', 0)');
|
VALUES ('.(int)$imageId.', '.(int)$productId.', '.(int)$shopId.', 0)');
|
||||||
@@ -424,7 +478,9 @@ foreach ($productsBySymbol as $symbol => $products)
|
|||||||
$mainProduct->ean13 = (string)$mainProductData->sku;
|
$mainProduct->ean13 = (string)$mainProductData->sku;
|
||||||
$mainProduct->id_category_default = $id_category_default;
|
$mainProduct->id_category_default = $id_category_default;
|
||||||
$mainProduct->link_rewrite = createLinkRewrite((string)$mainProductData->title);
|
$mainProduct->link_rewrite = createLinkRewrite((string)$mainProductData->title);
|
||||||
$mainProduct->id_shop_list = [2]; // Przypisanie do sklepów
|
$mainProduct->id_shop_list = [1]; // Przypisanie do sklepów
|
||||||
|
$mainProduct->active = 1; // Ustawienie produktu jako aktywnego
|
||||||
|
$mainProduct->id_tax_rules_group = 62; // Ustawienie ID grupy reguł podatkowych
|
||||||
$mainProduct->add();
|
$mainProduct->add();
|
||||||
|
|
||||||
// ❗ Teraz przypisanie do kategorii
|
// ❗ Teraz przypisanie do kategorii
|
||||||
@@ -442,7 +498,7 @@ foreach ($productsBySymbol as $symbol => $products)
|
|||||||
|
|
||||||
Db::getInstance()->insert('product_shop', [
|
Db::getInstance()->insert('product_shop', [
|
||||||
'id_product' => (int)$mainProduct->id,
|
'id_product' => (int)$mainProduct->id,
|
||||||
'id_shop' => 2,
|
'id_shop' => 1,
|
||||||
'id_category_default' => (int)$id_category_default,
|
'id_category_default' => (int)$id_category_default,
|
||||||
'price' => (float)$mainProduct->price,
|
'price' => (float)$mainProduct->price,
|
||||||
'active' => 1,
|
'active' => 1,
|
||||||
@@ -468,13 +524,49 @@ foreach ($productsBySymbol as $symbol => $products)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( $config['update_price'] == true )
|
if ( $config['update_price'] == true and $mainProduct ->id != 35873 )
|
||||||
{
|
{
|
||||||
$mainProduct->price = floatval(str_replace(',','',$mainProductData->price));
|
// $mainProduct->price = floatval(str_replace(',','',$mainProductData->price));
|
||||||
$description = (string)$mainProductData->description;
|
// $description = (string)$mainProductData->description;
|
||||||
$description = str_replace("\n", "<br>", $description);
|
// $description = str_replace("\n", "<br>", $description);
|
||||||
$mainProduct->description = createMultiLangField($description);
|
// $mainProduct->description = createMultiLangField($description);
|
||||||
$mainProduct->update();
|
// $mainProduct->update();
|
||||||
|
|
||||||
|
// update price new price is old brutto price / 1.23
|
||||||
|
// get price brutto from db
|
||||||
|
// $oldPrice = Db::getInstance()->getValue('SELECT price FROM '._DB_PREFIX_.'product WHERE id_product = '.(int)$mainProduct->id);
|
||||||
|
// $newPrice = floatval(str_replace(',', '', $mainProductData->price)) / 1.23; // assuming old price is brutto
|
||||||
|
// // update price in product table
|
||||||
|
// Db::getInstance()->update('product', ['price' => $newPrice], 'id_product = '.(int)$mainProduct->id);
|
||||||
|
// // update price in product_shop table
|
||||||
|
// Db::getInstance()->update('product_shop', ['price' => $newPrice], 'id_product = '.(int)$mainProduct->id);
|
||||||
|
// echo "<p>Zaktualizowałem cenę produktu: " . (string)$mainProductData->title . " na " . $newPrice . "</p>";
|
||||||
|
|
||||||
|
// // do the same with combinations
|
||||||
|
// // get all combinations for the product from db
|
||||||
|
// $combinations = Db::getInstance()->executeS('SELECT id_product_attribute FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$mainProduct->id);
|
||||||
|
// foreach ($combinations as $combination) {
|
||||||
|
// // get old price from db
|
||||||
|
// $oldCombinationPrice = Db::getInstance()->getValue('SELECT price FROM '._DB_PREFIX_.'product_attribute WHERE id_product_attribute = '.(int)$combination['id_product_attribute']);
|
||||||
|
// $newCombinationPrice = floatval(str_replace(',', '', $oldCombinationPrice)) / 1.23; // assuming old price is brutto
|
||||||
|
// // update price in product_attribute table
|
||||||
|
// Db::getInstance()->update('product_attribute', ['price' => $newCombinationPrice], 'id_product_attribute = '.(int)$combination['id_product_attribute']);
|
||||||
|
// // // update price in product_attribute_shop table
|
||||||
|
// Db::getInstance()->update('product_attribute_shop', ['price' => $newCombinationPrice], 'id_product_attribute = '.(int)$combination['id_product_attribute']);
|
||||||
|
// echo "<p>Zaktualizowałem cenę kombinacji: " . (string)$mainProductData->title . " na " . $newCombinationPrice . "</p>";
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $config['update_tax_id'] == true )
|
||||||
|
{
|
||||||
|
// Update tax ID in product column id_tax_rules_group, value 62, table materac_product
|
||||||
|
Db::getInstance()->update('product', ['id_tax_rules_group' => 62], 'id_product = '.(int)$mainProduct->id );
|
||||||
|
// also table materac_product_shop
|
||||||
|
Db::getInstance()->update('product_shop', ['id_tax_rules_group' => 62], 'id_product = '.(int)$mainProduct->id );
|
||||||
|
|
||||||
|
// change product to active by db
|
||||||
|
Db::getInstance()->update('product', ['active' => 1], 'id_product = '.(int)$mainProduct->id);
|
||||||
|
Db::getInstance()->update('product_shop', ['active' => 1], 'id_product = '.(int)$mainProduct->id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +616,7 @@ foreach ($productsBySymbol as $symbol => $products)
|
|||||||
$combination->reference = (string)$productData->sku;
|
$combination->reference = (string)$productData->sku;
|
||||||
// ean13
|
// ean13
|
||||||
$combination->ean13 = (string)$productData->sku;
|
$combination->ean13 = (string)$productData->sku;
|
||||||
$combination->id_shop_list = [2]; // Przypisanie do sklepów
|
$combination->id_shop_list = [1]; // Przypisanie do sklepów
|
||||||
$combination->price = calculatePriceImpact($mainProductData->price, $productData->price);
|
$combination->price = calculatePriceImpact($mainProductData->price, $productData->price);
|
||||||
$combination->add();
|
$combination->add();
|
||||||
|
|
||||||
@@ -576,13 +668,13 @@ foreach ($productsBySymbol as $symbol => $products)
|
|||||||
echo "<p>Dodałem produkt: " . (string)$mainProductData->title . "</p>";
|
echo "<p>Dodałem produkt: " . (string)$mainProductData->title . "</p>";
|
||||||
}
|
}
|
||||||
if ($combinationAdded) {
|
if ($combinationAdded) {
|
||||||
echo "<p>Dodałem kombinację: " . (string)$mainProductData->title . "</p>";
|
echo "<p>Dodałem kombinację: " . (string)$mainProductData->title . ". Produkt ID: " . $mainProduct->id . "</p>";
|
||||||
}
|
}
|
||||||
break; // Break if a new product or combination was added
|
break; // Break if a new product or combination was added
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reload page after 1s if product or combination was added
|
// reload page after 1s if product or combination was added
|
||||||
if ($productAdded || $combinationAdded) {
|
if ($productAdded || $combinationAdded) {
|
||||||
echo "<script>setTimeout(function(){location.reload();}, 250);</script>";
|
// echo "<script>setTimeout(function(){location.reload();}, 250);</script>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 80 KiB |
Reference in New Issue
Block a user