Page 1 of 1

Help with php code conflicts and CMS MS

Posted: Mon Jul 23, 2007 7:48 pm
by JohnnyB
Hi,

I am developing an ecommerce site using a 3rd party php script.  And, I'm going to use CMS MS to manage content on the non-shopping pages.  In other words, pages that will not have product displayed, e.g., about us, contact, and other informational pages.  But, I still need to display global blocks of content (header, menu, footer), a 'minicart' and other includes that are dependent upon the ecommerce database.

I have been able to do this successfully by including content using the smarty {php} {/php} tags.  But, for some reason I am having problems with the ecommerce script's minicart.  It works correctly on a test site without CMS MS.

Inside my CMS MS template, I have tried using an iframe embed, and a user defined tag, and I can not get it to work. The page will hang and then display a server 500 error.  But without the minicart code, the page displays correctly with out problems. 

[EDIT: I should probably provide some URLs. 
Test site without CMS MS installed: http://www.bathtanicals[dot]com/new/cart/index.php
Test site with CMS MS installed: http://www.bathtanicals[dot]com/new/cart-cms/index.php
Replace [dot] with . (I don't want those pgs indexed... thanks ]



Here's the minicart code.  Does anyone see any red flags?  Is there anything that might conflict with CMS MS?  Could it be the session variables?
{php}
if(trim(@$_POST['sessionid']) != '')
$thesessionid = trim(@$_POST['sessionid']);
else
$thesessionid = session_id();
$thesessionid = str_replace("'",'',$thesessionid);
$useEuro=false;
$mcgndtot=0;
$totquant=0;
$totmitems=0;
$shipping=0;
$mcdiscounts=0;
if(@$_SESSION['xscountrytax'] != '') $xscountrytax=$_SESSION['xscountrytax']; else $xscountrytax=0;
$optPriceDiff=0;
$mcpdtxt='';
if(@$incfunctionsdefined==TRUE){
$alreadygotadmin = getadminsettings();
}else{
$sSQL = "SELECT countryLCID,countryCurrency,adminStoreURL FROM admin INNER JOIN countries ON admin.adminCountry=countries.countryID WHERE adminID=1";
$result = mysql_query($sSQL) or print(mysql_error());
$rs = mysql_fetch_array($result);
$adminLocale = $rs["countryLCID"];
$useEuro = ($rs["countryCurrency"]=="EUR");
$storeurl = $rs["adminStoreURL"];
if((substr(strtolower($storeurl),0,7) != "http://") && (substr(strtolower($storeurl),0,8) != "https://"))
$storeurl = "http://" . $storeurl;
if(substr($storeurl,-1) != "/") $storeurl .= "/";
mysql_free_result($result);
}
if(@$_POST['mode']=='checkout'){
if(@$_POST['checktmplogin'] != ''){
$sSQL = "SELECT tmploginname FROM tmplogin WHERE tmploginid='" . mysql_escape_string(trim(@$_POST['sessionid'])) . "' AND tmploginchk='" . mysql_escape_string(@$_POST['checktmplogin']) . "'";
$result = mysql_query($sSQL) or print(mysql_error());
if($rs = mysql_fetch_assoc($result))
$_SESSION['clientID']=$rs['tmploginname'];
}else{
$_SESSION['clientID']=NULL; unset($_SESSION['clientID']);
}
}
$sSQL = "SELECT cartID,cartProdID,cartProdName,cartProdPrice,cartQuantity FROM cart WHERE cartCompleted=0 AND " . getsessionsql();
$result = mysql_query($sSQL) or print(mysql_error());
while($rs = mysql_fetch_assoc($result)){
$optPriceDiff=0;
$mcpdedit =" edit";
$mcpdtxt .= "(".$rs["cartQuantity"] .")". ' ' . $rs["cartProdName"]. " ... \$" .(($rs["cartProdPrice"]+$optPriceDiff)*(int)$rs["cartQuantity"]) .$mcpdedit.""."\n";
$result2 = mysql_query($sSQL) or print(mysql_error());
$rs2 = mysql_fetch_assoc($result2);
if(! is_null($rs2['sumDiff'])) $optPriceDiff=$rs2['sumDiff'];
mysql_free_result($result2);
$subtot = (($rs['cartProdPrice']+$optPriceDiff)*(int)$rs['cartQuantity']);
$totquant+=(int)$rs['cartQuantity'];
$totmitems=$totmitems+$rs["cartQuantity"];
$mcgndtot += $subtot;
}
mysql_free_result($result);
{/php}

{php}
// *** Start Mini Cart Display ***
// Determine if there are contents and display correct bg class 
{/php}

{php} print $xxMCSC; {/php}
{php}
//Show Checkout title if has contents
if($totmitems!=''){
print "".$xxMCCO."";
// Display minicart contents if not empty
{/php}

{php} print "You currently have ".$totmitems . " " . $xxMCIIC."" {/php}
{php} if($mcpdtxt == '') $xscountrytax=0; {/php}
{php} $shipping = (double)$_SESSION['xsshipping'];
print "". $xxTotal . " " . FormatEuroCurrency(($mcgndtot+$shipping+$xscountrytax)-$mcdiscounts) .""{/php}
{php} //Begin JS slide effect {/php}
Show Details


Cart Contents
{php} if(@$_POST["mode"]=="update"){ {/php}
{php} print $xxMainWn{/php}
{php} }else{ {/php}
{php} print ""."\n".$mcpdtxt."";
if($mcpdtxt != '' && @$_SESSION['discounts'] != ''){
$mcdiscounts = (double)$_SESSION['discounts']; {/php}
{php} print "" .$xxDscnts . " " . FormatEuroCurrency($mcdiscounts).""{/php}
{php} }
if($mcpdtxt != '' && (string)@$_SESSION['xsshipping'] != ''){
$shipping = (double)$_SESSION['xsshipping'];
if($shipping==0) $showshipping=''.$xxFree.''; else $showshipping=FormatEuroCurrency($shipping); {/php}
{php} print "[ ".$xxMCShpE . " " . $showshipping." ]" {/php}
{php} }
if($mcpdtxt == '') $xscountrytax=0; {/php}
{php} print "". $xxTotal . " " . FormatEuroCurrency(($mcgndtot+$shipping+$xscountrytax)-$mcdiscounts) .""{/php}
{php} } {/php}
{php} print "CHECKOUT";{/php}
Hide Details



{php} } {/php}
I replaced the traditional

Code: Select all

<?php and ?> with smarty php tags and enabled smarty php in config.php
Also, the minicart is dependent upon the include file to open the database (ecommerce db) and a few other files that provide data and functionality.  The files by themselves haven't produced any errors and load correctly.  It is only when I load the minicart code that breaks the site.

Also, the top of the template has:
session_cache_limiter('none');
session_start();
ob_start();
Which is required for the ecommerce minicart functionality.

Thanks in advance for any suggestions!

Re: Help with php code conflicts and CMS MS

Posted: Mon Jul 23, 2007 7:52 pm
by calguy1000
As has been discussed on numerous other threads.... you need to use an explicit database connection when accessing another database from within cms.  as well, you should call adodb_connect() at the end to re-establish the cms database connection.

So instead of just calling:
mysql_query($query);

you need to first do something like this:
$mydb = mysql_connect(...);
$results = mysql_query( $mydb, $query );

i.e:  You need to get an explicit database handle and pass that to all of the mysql calls.

Re: Help with php code conflicts and CMS MS

Posted: Mon Jul 23, 2007 8:09 pm
by JohnnyB
Thanks calguy1000!

I'll explore this approach.

Re: Help with php code conflicts and CMS MS

Posted: Mon Jul 23, 2007 10:33 pm
by JohnnyB
Not sure if it matters, but I'm using the same database for the ecommerce tables and CMS MS tables.  Except that the CMS MS tables have a unique prefix.


Ok.  So, I have an include file that sets a variable called, $dbh which connects to the 'ecommerce' database.    If I understand correctly, I can just use that $dbh in the code above.  For example, in all instances of:

  $sSQL = "SELECT countryLCID,countryCurrency,adminStoreURL FROM admin INNER JOIN countries ON admin.adminCountry=countries.countryID WHERE adminID=1";
  $result = mysql_query($dbh, $sSQL) or print(mysql_error());

Or, am I missing something?  Because, I still can't figure this out.

BTW, my other ecommerce database queries are working and not breaking the CMS MS output. It is just that minicart code that breaks it.

Re: Help with php code conflicts and CMS MS - updated - session ids conflict

Posted: Tue Jul 24, 2007 1:51 am
by JohnnyB
I've been able to narrow things down to the session id

I have the minicart displaying, but inside the CMS MS generated pages, the minicart does not display items in the shopping cart.

So, I added a print $thesessionid statement inside of my CMS MS template near the minicart code and, added a print $thesessionid inside of some of the non CMS MS generated page (inside ecommerce generated pages) and the 2 session ids were different.

So, it looks like I need to figure out session ids.

I did a search of CMS MS files and did not find a result for 'thesessionid'  So, I know that CMS MS doesn't use the same variable.

Could the different session ids be because the ecommerce code is being included inside of another script, CMS MS?  Is there some material about session ids for CMS MS that I can read? 

Re: Help with php code conflicts and CMS MS

Posted: Tue Jul 24, 2007 3:24 am
by JohnnyB
Is there a way to unset the CMS MS session_id?

I can't put my finger on a session_id variable in include.php.  But, I think if I can eliminate the CMS MS session so that the cart session is used instead, I might be ok.  ???

EDIT: I should probably provide some URLs.
Test site without CMS MS installed: http://www.bathtanicals[dot]com/new/cart/index.php
Test site with CMS MS installed: http://www.bathtanicals[dot]com/new/cart-cms/index.php
and to see the 'ecommerce' seession, go to: http://www.bathtanicals[dot]com/new/cart-cms/skincare.php

Replace [dot] with . (I don't want those pgs indexed... thanks ]


->UPDATE:
I managed to make the session the same for CMS MS pages with ecommerce includes and non-shopping pages / pages outside of CMS MS, by editing the include.php file.  I commented
// @session_name('CMSSESSID' . $session_key);
and
//  @session_start();

So now I have the same session, but now I still don't have cart contents displayed in the minicart inside of CMS MS generated pages. So, maybe I'm back to a database issue. But, the database is the same for CMS MS and the ecommerce scripts....
:-\

Re: Help with php code conflicts and CMS MS

Posted: Tue Jul 24, 2007 3:05 pm
by JohnnyB
->UPDATE:
I managed to make the session the same for CMS MS pages with ecommerce includes and non-shopping pages / pages outside of CMS MS, by editing the include.php file.  I commented
// @session_name('CMSSESSID' . $session_key);
and
//  @session_start();
I just realized that I need  @session_start(); to login to admin.  Now, the cms ms session and the ecommerce session are the same on all pages.  But, I'm still having trouble finding theproblem with the minicart.  It doesn't display the products in the cart.  The ecommerce script and cms ms share the same db.

The minicart works in all non cms ms generated pages.