There are two carts that used to be on two different servers. There were scripts in place to update one of the carts via a daily cron job. The owner only edits/adds products in one cart and then the other cart is updated and the new images moved through ftp to the second cart.
Now both carts on on the same hosting account with the second cart as a add on domain on a cpanel server.
I don't like the way this way done before and want to rethink the whole process to make sure this is done efficiently.
The first part is the database:
The updating of the products in the database may need to be done just as before with minimal changes of code. But I do want opinions about how it is done. It looks unnecessarily complicated to me.
My understanding is that the owner never ever edits products on the second site. My inclination is to simply empty the tables on the second site and replace with required tables on first site. The dual wholesale mod is installed which creates one extra field on the products fields.
Here's the code
The second part are the images. There are nearly 7000 images for the products. I thought to simply point the second site to the image directory of the first which is in the root. Changing the image path when it's an addon domain did not work as I had hoped because the root for the add on domain is not the hosting account root but only inside that add on domain. To be clear:PHP Code:$error = "";
$success = "";
//connect to the database
$con = mysql_connect("ip address","secondsite","password");
if (!$con)
{
$error = "Could not connect: " . mysql_error();
}
mysql_select_db("secondsite", $con);
mysql_query("DROP TABLE IF EXISTS `zen_products_description_temp`;");
$query_temp = "CREATE TABLE `zen_products_description_temp` (
`products_id` int(11) NOT NULL AUTO_INCREMENT,
`products_description` text,
`products_viewed` int(5) DEFAULT '0',
`product_is_always_free_shipping` tinyint(1) NOT NULL DEFAULT '0',
`products_status` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`products_id`)
);";
mysql_query($query_temp);
$query_add = "INSERT INTO zen_products_description_temp SELECT a.products_id, products_description, products_viewed, product_is_always_free_shipping, products_status FROM zen_products_description a, zen_products b where a.products_id = b.products_id";
mysql_query($query_add);
//dump 7 specific tables into a .sql file on firstsite database
$command = "mysqldump --user=firstsite --password=deleted --host=ip address firstsite zen_products zen_products_description zen_categories zen_categories_description zen_products_to_categories zen_manufacturers zen_manufacturers_info zen_products_attributes zen_products_options zen_products_options_values zen_products_options_values_to_products_options > secondsite.sql";
exec($command);
//restore those tables into the missarchery database
$restore = "mysql --user=secondsite--password=deleted --host=ip number secondsite< secondsite.sql";
exec($restore);
//close the database connection
mysql_close($con);
//connect to the database
$con2 = mysql_connect("ip address","secondsite","password");
if (!$con2)
{
$error = "Could not connect: " . mysql_error();
}
mysql_select_db("secondsite", $con2);
//update the prices to the retail price
$query = "UPDATE zen_products set products_price = products_price_w, products_price_sorter = products_price_w";
if($test = mysql_query($query)){
$success .= "The prices were successfully updated to the retail price!" . "\n";
}else{
$error .= "Error updating the prices to retail price." . mysql_error() . "\n";
}
//change jmp091023 - add update query to set tax-class values for all products to '1' (taxable).
$query = "UPDATE zen_products set products_tax_class_id = '1'";
if($test = mysql_query($query)){
$success .= "All products are now marked as taxable!" . "\n";
}else{
$error .= "Error updating the products_tax_class_id." . mysql_error() . "\n";
}
//jmp091023 ends.
//update product description and products viewed
$query = "UPDATE zen_products_description a, zen_products_description_temp b, zen_products c SET a.products_description = b.products_description, a.products_viewed = b.products_viewed, c.product_is_always_free_shipping = b.product_is_always_free_shipping, c.products_status = b.products_status WHERE a.products_id = b.products_id and c.products_id = b.products_id;";
if($test2 = mysql_query($query)){
$success .= "Product descriptions, free shipping indicators, and status were preserved!" . "\n";
}else{
$error .= "Error updating the products description." . mysql_error() . "\n";
}
mysql_query("DROP TABLE IF EXISTS `zen_products_description_temp`;");
//close the database connection
mysql_close($con2);
unlink('secondsite.sql');
full path for first site is /home/account name/public_html. For the second site it is /home/account name/public_html/secondsite.com/
So I first changed this define('DIR_WS_IMAGES', 'images/'); to this define('DIR_WS_IMAGES', '/images/'); does not point to first domain in actual root.
Bypassing the file structure and doing this bypassing zen cart image functions completely displaying the full size original image
define('DIR_WS_IMAGES', 'http://firstsite.com/images/');
I can't think of any other way to do it with the configure file though there may be. I'm also wanting to install image handler to make this even more complicated. Guess the images just should be copied to the second site.
So I thought, what if when she uploads an image into the first site, why not have zen copy that image to the other? Or a script that rests in the images folder that detects a new image and then copies it to the second site. That requires no sql queries and no cron job.
So then I thought, wait if I can do that, perhaps I should just set up the first site to send a query to the second site when updating or adding new products. Total synchonization.
But. That does sound pretty intensive and probably more time to do that updating the existing scripts with new database settings and replacing mysql with mysqli.
What's your opinion? If you started from scratch, how would you do it?


Reply With Quote

