Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-05-08 21:28:20 +02:00
parent d5a334c6a8
commit 5171f58e16
5 changed files with 20962 additions and 7156 deletions

View File

@@ -21,7 +21,7 @@ $mdb_dr = new medoo( [
'charset' => 'utf8' 'charset' => 'utf8'
] ); ] );
$mdb -> query( 'TRUNCATE TABLE estella_products' ); $mdb -> query( 'TRUNCATE TABLE estella_products_drmaterac' );
$file = file_get_contents( 'https://b2b.estella.eu/generator/22413dfa-be6d-473d-b301-282351168cf6/xml/aa6648e6-c4a8-4af6-b6ae-33954c47886f' ); $file = file_get_contents( 'https://b2b.estella.eu/generator/22413dfa-be6d-473d-b301-282351168cf6/xml/aa6648e6-c4a8-4af6-b6ae-33954c47886f' );
$doc = new DOMDocument(); $doc = new DOMDocument();
@@ -41,43 +41,24 @@ foreach ( $products as $product )
$ean = $xpath -> query( 'Ean', $product ); $ean = $xpath -> query( 'Ean', $product );
$ean_value = $ean -> item(0) -> nodeValue; $ean_value = $ean -> item(0) -> nodeValue;
if ( $mdb -> count( 'estella_products', [ 'sku' => $indeks_value ] ) == 0 ) $mdb -> insert( 'estella_products_drmaterac', [
{
$mdb -> insert( 'estella_products', [
'sku' => $indeks_value, 'sku' => $indeks_value,
'name' => $nazwa_value, 'name' => $nazwa_value,
'ean' => $ean_value 'ean' => $ean_value
] ); ] );
}
if ( $mdb -> count( 'estella_products_old', [ 'sku' => $indeks_value ] ) == 0 )
{
$mdb -> insert( 'estella_products_old', [
'sku' => $indeks_value,
'name' => $nazwa_value,
'ean' => $ean_value
] );
}
} }
$products_to_delete = []; $estella_products = $mdb_dr -> query( 'SELECT id_product FROM materac_product_lang WHERE name LIKE \'%Estella%\' AND id_product > 0' ) -> fetchAll( PDO::FETCH_COLUMN, 0 );
$estella_products = array_unique($estella_products);
$old_products = $mdb -> select( 'estella_products_old', [ 'sku' ] ); foreach ( $estella_products as $estella_product_id )
foreach ( $old_products as $product_tmp )
{ {
if ( $mdb -> count( 'estella_products', [ 'sku' => $product_tmp['sku'] ] ) == 0 ) $product = $mdb_dr -> get( 'materac_product', '*', [ 'id_product' => $estella_product_id ] );
{ $product_reference = $product['reference'];
$products_to_delete[] = $product_tmp['sku'];
}
}
foreach ( $products_to_delete as $product_to_delete ) if ( !$mdb -> count( 'estella_products_drmaterac', [ 'sku' => $product_reference ] ) )
{
$product_id_tmp = $mdb_dr -> get( 'materac_product', 'id_product', [ 'reference' => $product_to_delete ] );
if ( $product_id_tmp )
{ {
$mdb_dr -> update( 'materac_product', [ 'active' => 0 ], [ 'id_product' => $product_id_tmp ] ); $mdb_dr -> update( 'materac_product', [ 'active' => 0 ], [ 'id_product' => $estella_product_id ] );
$mdb_dr -> update( 'materac_product_shop', [ 'active' => 0 ], [ 'id_product' => $product_id_tmp ] ); $mdb_dr -> update( 'materac_product_shop', [ 'active' => 0 ], [ 'id_product' => $estella_product_id ] );
echo '<p>Deaktywowano produkt: ' . $product_to_delete . '</p>'; echo 'Nie ma produktu w bazie Estella: ' . $product_reference . ', id: ' . $estella_product_id . '<br>';
} }
} }

View File

@@ -0,0 +1,64 @@
<?php
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
include '../_plugins/medoo.php';
include '../settings.php';
$mdb = new medoo( [
'database_type' => 'mysql',
'database_name' => $settings['db']['database'],
'server' => $settings['db']['host'] ,
'username' => $settings['db']['user'],
'password' => $settings['db']['password'],
'charset' => 'utf8'
] );
$mdb_dr = new medoo( [
'database_type' => 'mysql',
'database_name' => 'admin_lulandia',
'server' => 'dedyk8.cyber-folks.pl',
'username' => 'admin_lulandia',
"password" => '6_atdQ-N#xlN-t#0',
'charset' => 'utf8'
] );
$mdb -> query( 'TRUNCATE TABLE estella_products_lulandia' );
$file = file_get_contents( 'https://b2b.estella.eu/generator/22413dfa-be6d-473d-b301-282351168cf6/xml/aa6648e6-c4a8-4af6-b6ae-33954c47886f' );
$doc = new DOMDocument();
$doc -> loadXML( $file );
$xpath = new DOMXPath( $doc );
$products = $xpath->query('//Document/Produkt');
foreach ( $products as $product )
{
$indeks = $xpath -> query( 'Indeks', $product );
$indeks_value = $indeks -> item(0) -> nodeValue;
$nazwa = $xpath -> query( 'Nazwa', $product );
$nazwa_value = $nazwa -> item(0) -> nodeValue;
$ean = $xpath -> query( 'Ean', $product );
$ean_value = $ean -> item(0) -> nodeValue;
$mdb -> insert( 'estella_products_lulandia', [
'sku' => $indeks_value,
'name' => $nazwa_value,
'ean' => $ean_value
] );
}
$estella_products = $mdb_dr -> query( 'SELECT id_product FROM materac_product_lang WHERE name LIKE \'%Estella%\' AND id_product > 0' ) -> fetchAll( PDO::FETCH_COLUMN, 0 );
$estella_products = array_unique($estella_products);
foreach ( $estella_products as $estella_product_id )
{
$product = $mdb_dr -> get( 'materac_product', '*', [ 'id_product' => $estella_product_id ] );
$product_reference = $product['reference'];
if ( !$mdb -> count( 'estella_products_lulandia', [ 'sku' => $product_reference ] ) )
{
$mdb_dr -> update( 'materac_product', [ 'active' => 0 ], [ 'id_product' => $estella_product_id ] );
$mdb_dr -> update( 'materac_product_shop', [ 'active' => 0 ], [ 'id_product' => $estella_product_id ] );
echo 'Nie ma produktu w bazie Estella: ' . $product_reference . ', id: ' . $estella_product_id . '<br>';
}
}

View File

@@ -0,0 +1,65 @@
<?php
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
include '../_plugins/medoo.php';
include '../settings.php';
$mdb = new medoo( [
'database_type' => 'mysql',
'database_name' => $settings['db']['database'],
'server' => $settings['db']['host'] ,
'username' => $settings['db']['user'],
'password' => $settings['db']['password'],
'charset' => 'utf8'
] );
$mdb_dr = new medoo( [
'database_type' => 'mysql',
'database_name' => 'admin_masimmo_shop',
'server' => 'dedyk8.cyber-folks.pl',
'username' => 'admin_masimmo_shop',
"password" => '-T.C0Q-6iPO@e+Fi',
'charset' => 'utf8'
] );
$mdb -> query( 'TRUNCATE TABLE estella_products_masimmo' );
$file = file_get_contents( 'https://b2b.estella.eu/generator/22413dfa-be6d-473d-b301-282351168cf6/xml/aa6648e6-c4a8-4af6-b6ae-33954c47886f' );
$doc = new DOMDocument();
$doc -> loadXML( $file );
$xpath = new DOMXPath( $doc );
$products = $xpath->query('//Document/Produkt');
foreach ( $products as $product )
{
$indeks = $xpath -> query( 'Indeks', $product );
$indeks_value = $indeks -> item(0) -> nodeValue;
$nazwa = $xpath -> query( 'Nazwa', $product );
$nazwa_value = $nazwa -> item(0) -> nodeValue;
$ean = $xpath -> query( 'Ean', $product );
$ean_value = $ean -> item(0) -> nodeValue;
$mdb -> insert( 'estella_products_masimmo', [
'sku' => $indeks_value,
'name' => $nazwa_value,
'ean' => $ean_value
] );
}
$estella_products = $mdb_dr -> query( 'SELECT id_product FROM ps_product_lang WHERE name LIKE \'%Estella%\' AND id_product > 0' ) -> fetchAll( PDO::FETCH_COLUMN, 0 );
$estella_products = array_unique($estella_products); echo count( $estella_products ) . '<br>';
foreach ( $estella_products as $estella_product_id )
{
$product = $mdb_dr -> get( 'ps_product', '*', [ 'id_product' => $estella_product_id ] );
$product_reference = $product['reference'];
if ( !$mdb -> count( 'estella_products_masimmo', [ 'sku' => $product_reference ] ) )
{
$mdb_dr -> update( 'ps_product', [ 'active' => 0 ], [ 'id_product' => $estella_product_id ] );
$mdb_dr -> update( 'ps_product_shop', [ 'active' => 0 ], [ 'id_product' => $estella_product_id ] );
echo 'Nie ma produktu w bazie Estella: ' . $product_reference . ', id: ' . $estella_product_id . '<br>';
}
}
echo 'koniec';

15804
drmaterac.pl/estella.xml Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long