Forums / General Questions / need a little help thinking through an issue between two carts

need a little help thinking through an issue between two carts

Views: 1,025

Results 1 to 19 of 19
13 Feb 2015, 2:49 PM
#1
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

need a little help thinking through an issue between two carts

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

$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');

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:
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?

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

13 Feb 2015, 3:12 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: need a little help thinking through an issue between two carts

Have you considered the "Multi-Site Module"?

13 Feb 2015, 4:44 PM
#3
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

Yeah, I had a passing thought to that. But checkout has always been the issue. Don't all templates have to use the same url for checkout? Or is that just when you have ssl turned on? One site uses ssl and the other does not. Owner has definitely stated that neither site can reference the other - keeping retail and wholesale completely separate in the end. The reason why the dual wholesale mod is installed is to have both prices with only wholesale displaying on one and only retail on the other and insure updating correctly.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

13 Feb 2015, 6:15 PM
#4
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

delia:

Yeah, I had a passing thought to that. But checkout has always been the issue. Don't all templates have to use the same url for checkout? Or is that just when you have ssl turned on? One site uses ssl and the other does not. Owner has definitely stated that neither site can reference the other - keeping retail and wholesale completely separate in the end. The reason why the dual wholesale mod is installed is to have both prices with only wholesale displaying on one and only retail on the other and insure updating correctly.

With the multi site module each site can be configured separately. Including the ssl. One site can use ssl while the other does not, but also both can have their own ssl.

13 Feb 2015, 6:22 PM
#5
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

Yeah, that I figured out but there's different payment and shipping methods between the two sites so varied that I don't see how it's possible to have both coexist on the same site. Great idea though.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

13 Feb 2015, 6:24 PM
#6
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

It is also possible to specify the different payment mods. Every value that is present in the the configuration table, can be overridden in the sites config file.

13 Feb 2015, 9:04 PM
#7
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

I wonder... That would well worth the effort if it can be done. Thanks.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

13 Feb 2015, 11:33 PM
#9
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

I'll be talking with the owner to see if this will work. I have installed several multi sites before so hopefully all will go well Those configure settings I haven't done with that before but have with my mobile template so I think I'm going to be okay.

Great getting the responses - working by your self sometimes feedback is just invaluable when one's brain gets overwhelmed.

Thanks to everyone!

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

8 Mar 2015, 1:52 PM
#10
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

@Design75 I have run into a problem. I upgraded multi-site to 1.5.4. The biggest difference between the two sites is that one is normal - and one customer pending approval so it's goes to the login screen. On the site that requires login/signup, it throws this error

[08-Mar-2015 09:35:36 America/New_York] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/domain/public_html/multi/includes/config_sites/deliasample.com_config.php:4) in /home/domain/public_html/multi/includes/functions/sessions.php on line 115

So the session gets started twice this way. I don't know if this has been an issue before or if it is just post 1.5.1 versions.

I tried both ways - having the database set as customer pending or just in the site_config file. Makes no difference.

I assume I did the file integrations right - there really wasn't much to it really.

So I figure the problem in the init_sessions.php.

// bof Multi site - Prioritise the GET variable over the cookie.
elseif(isset($_GET[session_name()])) {
zen_setcookie(session_name(), $_GET[session_name()], time()+$SESS_LIFE, '/', (zen_not_null($current_domain) ? $current_domain : ''));
if(isset($_COOKIE[session_name()])&&($_COOKIE[session_name()]!=$_GET[session_name()])) {
$_COOKIE[session_name()] = $_GET[session_name()];
}
}
//eof Multi site

What do you think?

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

8 Mar 2015, 1:54 PM
#11
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

uh, should I take this to the multisite thread?

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

8 Mar 2015, 2:07 PM
#12
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

delia:

uh, should I take this to the multisite thread?

Officially according to the forum rules you should :laugh:.
To be hones I have not used the multi site mod in some time. I use my own improved Multi Store(commercial) module.
I will make a 1.5.4 test site and see what happens with the session.php. But chances are it is the source of the problem

8 Mar 2015, 7:59 PM
#13
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

Okay, did a quick test and all is showing. , but I can not reproduce the error.

What is on line 115 of your sessions.php

8 Mar 2015, 8:37 PM
#14
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

sessions or init_sessions.php

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

8 Mar 2015, 8:41 PM
#15
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

delia:

sessions or init_sessions.php

this was the error you showed in post #10

[08-Mar-2015 09:35:36 America/New_York] PHP Warning:  session_start():  Cannot send session cache limiter - headers already sent (output started  at  /home/domain/public_html/multi/includes/config_sites/deliasample.com_config.php:4)  in /home/domain/public_html/multi/includes/functions/sessions.php on  line 115

That is why I asked for sessions.php

Also could you post the contents of deliasample.com_config.php ?

8 Mar 2015, 8:48 PM
#16
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

<?php  
$template_dir = "ultra";  
define('UltraProducts','ultra');  
define('CUSTOMERS_APPROVAL_AUTHORIZATION', '1');
?> 

The sessions.php file is the default one for 1.5.4 (uh, did I mention that version?)

line 115 is $temp = session_start();

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

8 Mar 2015, 9:09 PM
#17
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

Yes you did mention that it was 1.5.4

did you by any chance save the file deliasample.com_config.php as UTF8 and not as UTF8 W/O BOM ??
Although if I try different encodings it does not change anything.

8 Mar 2015, 10:29 PM
#18
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: need a little help thinking through an issue between two carts

I just realized something. The sidebox is not showing for the second site. There's more wrong here than I realized, I think.

I will back into it fresh tomorrow and try again.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

8 Mar 2015, 10:44 PM
#19
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: need a little help thinking through an issue between two carts

delia:

I just realized something. The sidebox is not showing for the second site. There's more wrong here than I realized, I think.

I will back into it fresh tomorrow and try again.

Ok, good night and waiting to hear from you