| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- require_once("DataBase_Net/Product_Net.php");
- require_once("DataBase/Product.php");
- require_once("DataBase_Net/Price_Net.php");
- require_once("DataBase/Price.php");
- require_once("DataBase/Priceset.php");
- // sync Product database
- $product = new Product();
- $product_net = new Product_Net();
- $price = new Price();
- $price_net = new Price_Net();
- $priceset = new Priceset();
- $new_product_count = 0;
- $del_product_count = 0;
- // delete remote products if not locally available anymore
- $remote_product = $product_net->get('', array('product_id'));
- foreach($remote_product as $tmp)
- {
- if($product->exists($tmp[0], " available=1 ") == false)
- {
- $product_net->delete($tmp[0]);
-
- // delete also the prices
- $local_pricesets = $priceset->get('');
- foreach($local_pricesets as $tmp_priceset)
- {
- $tmp_price = $price_net->getPrice($tmp_priceset[0], $tmp[0]);
- if(count($tmp_price) > 0)
- $price_net->delete($tmp_price[0][0]);
- }
- $del_product_count++;
- }
- }
- // add products remote if newly available locally
- $remote_products = $product_net->get('', array('product_id'));
- $local_products = $product->get('', array('product_id'), " available=1 ");
- foreach($local_products as $tmp)
- {
- $found = false;
-
- foreach($remote_products as $remote_tmp)
- {
- if($remote_tmp[0] == $tmp[0])
- {
- $found = true;
- break;
- }
- }
-
- $tmp_data = $product->get($tmp[0], array( "name",
- "details",
- "category_id",
- "tax_id",
- "available",
- "group_id",
- "order_number",
- "anmerkung"));
-
- if(!$found)
- {
- $product_net->create($tmp[0], $tmp_data[0]);
- $new_product_count++;
- }
- else
- {
- $product_net->update($tmp[0], $tmp_data[0]);
- }
- }
- $main_box->add(new NTKLabel("", "neue Produkte online: ".$new_product_count), 200, 0, "background-color: #dfe7f3;");
- $main_box->add(new NTKLabel("", "online Produkte gelöscht: ".$del_product_count), 200, 0, "background-color: #dfe7f3;");
- // check for prices on products
- $local_products = $product->get('', array('product_id'), " available=1 ");
- $local_pricesets = $priceset->get('');
- foreach($local_products as $tmp)
- {
- foreach($local_pricesets as $tmp_priceset)
- {
- $tmp_price = $price->getPrice($tmp_priceset[0], $tmp[0]);
-
- if(count($tmp_price) <= 0)
- continue;
-
- if($price_net->exists($tmp_priceset[0], $tmp[0]))
- $price_net->update($tmp_priceset[0], $tmp[0], array_slice($tmp_price[0], 3));
- else
- $price_net->create($tmp_priceset[0], $tmp[0], array_slice($tmp_price[0], 3));
- }
- }
- ?>
|