X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   StyleSwitch "mod" - running into some issues. (https://forum.x-cart.com/showthread.php?t=39717)

jbcarey 05-13-2008 01:47 AM

StyleSwitch "mod" - running into some issues.
 
hello,

I've been working on this Xcart for two weeks and I've managed to write a complete custom theme...

But now my client wishes to have a different stylesheet depending on which "categorie" the client is in... (so home.cat + sub.cat)... I'd like someone to follow my "train of Thought" and possibly tell me where I'm going wrong....


1st. I've created styleswitch.php in "xcart_dir/modules/styleswitch/"...

this is what is contains

PHP Code:

if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }
                    
                    
$sql func_query("SELECT DISTINCT parentid FROM xcart_categories WHERE categoryid='{$cat}' LIMIT 1");
                    
print_r($sql);
                    
$resmysql_query($sql) or die(mysql_error());
                    
                    echo 
$sqlprint_r($row);
                    while(
$row=mysql_fetch_assoc($res)) )
                    {
                    switch (
$row["parentid"]) {
                    case 
"15":
                    
$StyleSwitch'<style type="text/css">body {background-image: url(images/lolalayout/bg-15.gif);}
                                            .background { background-image: url(images/lolalayout/15.gif);}</style>'
;
                                            
$smarty->assign("StyleSwitch"$StyleSwitch);
                                            break;
                    
                    case 
"5":
                    
$StyleSwitch'<style type="text/css">body {background-image: url(images/lolalayout/bg-5.gif);}
                                            .background { background: #000000;}</style>'
;
                                            
$smarty->assign("StyleSwitch"$StyleSwitch);
                                            break;
                    }
                    }
                    
?> 


then I created StyleSwitch.tpl in "xcart_dir/skin1/modules/styleswitch/"...

Code:

{* $Id: StyleSwitch.tpl,v 1.8.2.1 2006/11/16 13:12:29 max Exp $ *}
{if $StyleSwitch}

{include file="{$xcart_dir}/modules/StyleSwitch/styleswitch.php"}
{/if}



finally in "home.tpl" i call up the "files".... I suppose.

Code:

{include file="{$SkinDir}/modules/StyleSwitch/StyleSwitch.tpl" }



also i "home.php" i put

Code:

if ($active_modules["StyleSwitch"])
    include $xcart_dir."/modules/StyleSwitch/styleswitch.php";


but nothing seems to be working.... could a php/smarty/xcart pro have a look at this for me please???? :oops:

WhiteDoveGifts 05-13-2008 02:40 AM

Re: StyleSwitch "mod" - running into some issues.
 
Hi,

Welcome to the X-Cart community!

There's a 3rd party mod that seems to be doing what you want to achieve:

http://www.bcsengineering.com/store/customer/product.php?productid=159&cat=0&page=3

Also, please update your forum signature with your exact X-Cart version in order to get specified answers for your version.

jbcarey 05-13-2008 02:54 AM

Re: StyleSwitch "mod" - running into some issues.
 
i did have a look at the "product" but my boss came to the conclusion he doesn't want to charge our client with what is supposed to be a simple "mod"....

Basically all i'd need to do is load a different css file dependant on what ParentCategorie is loaded... no more no less.

So I'm stuck with the questions :D

intel352 05-13-2008 04:24 AM

Re: StyleSwitch "mod" - running into some issues.
 
First, to be able to use the $active_modules variable, you have to have an entry in the xcart_modules table for your module. Also, you need to stay consistent with naming of the module directories, styleswitch vs StyleSwitch (and it needs to match your entry into xcart_modules).

Just a note, you don't *need* to configure this as a module, imho, as you could just set it up as a straight include, but that's up to you.


Second, you're trying to include a PHP file in Smarty, which you cannot do (it won't work properly), at least using the method that you're using (this is the proper method), but even then, you don't need to include that php file from smarty, as you already have it included from home.php, and the file has already created a variable for use with smarty.

Sooooo...

modules/StyleSwitch/styleswitch.php:
PHP Code:

<?php
if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }

$switchid false;
if( 
$current_category['parentid'] > ) {
    
/* Get array of all cats */
    
$all_cats func_query("SELECT categoryid, parentid FROM xcart_categories");

    
/* Build 2-dim array of parent->child cats */
    
$all_cat_arr = array();
    foreach(
$all_cats AS $_cat) {
        
$all_cat_arr[$_cat['parentid']][] = $_cat['categoryid'];
    }

    
/* Get absolute parent */
    
$switchid _get_absolute_parent($current_category['parentid'], $all_cat_arr);

}

if( !
$switchid ){
    
$switchid $current_category['categoryid'];
}

switch (
$switchid) {
    case 
'15':
        
$StyleSwitch '<style type="text/css">';
        
$StyleSwitch .= 'body {background-image: url(images/lolalayout/bg-15.gif);}';
        
$StyleSwitch .= '.background { background-image: url(images/lolalayout/15.gif);}';
        
$StyleSwitch .= '</style>';
        
$smarty->assign('StyleSwitch'$StyleSwitch);
    break;

    case 
'5':
        
$StyleSwitch '<style type="text/css">';
        
$StyleSwitch .= 'body {background-image: url(images/lolalayout/bg-5.gif);}';
        
$StyleSwitch .= '.background { background: #000000;}';
        
$StyleSwitch .= '</style>';
        
$smarty->assign('StyleSwitch'$StyleSwitch);
    break;
}

function 
_get_absolute_parent($catid$all_cats) {
    
reset($all_cats);
    foreach(
$all_cats AS $_parentcat=>$_children) {
        if( 
in_array($catid$_children) ) {
            if(
$_parentcat == 0) {
                return 
$catid;
            }
            return 
_get_absolute_parent($_parentcat$all_cats);
        }
    }
    
/* else, failed */
    
return false;
}

?>


home.php (before line: func_display("customer/home.tpl",$smarty);):
PHP Code:

if ($active_modules['StyleSwitch'])
    include 
$xcart_dir '/modules/StyleSwitch/styleswitch.php'


home.tpl (before line: </head>):
Code:

{if $StyleSwitch ne ""}{$StyleSwitch}{/if}


NOTE: I haven't tested this yet, but should point you in the right direction...

jbcarey 05-13-2008 05:04 AM

Re: StyleSwitch "mod" - running into some issues.
 
I'm putting this into action and testing it... thanks for the "kick in the right direction" :D

intel352 05-13-2008 03:12 PM

Re: StyleSwitch "mod" - running into some issues.
 
I just checked out your site's xcart install, looks like it worked! Did you have to change anything, or did it do fine as-is?

EDIT: I just noticed 1 issue in the _get_absolute_parent function, if you haven't corrected it already, I suggest you copy that into your code.
When the function calls itself again, it wasn't referring to the proper parentid variable, I fixed that in my post.

jbcarey 05-13-2008 11:28 PM

Re: StyleSwitch "mod" - running into some issues.
 
Quote:

Originally Posted by intel352
I just checked out your site's xcart install, looks like it worked! Did you have to change anything, or did it do fine as-is?

EDIT: I just noticed 1 issue in the _get_absolute_parent function, if you haven't corrected it already, I suggest you copy that into your code.
When the function calls itself again, it wasn't referring to the proper parentid variable, I fixed that in my post.



hey, yes it worked "as is", so that was an amazing piece of help... i will test with the new code you have uploaded but thanks very much!

jbcarey 06-12-2008 05:57 AM

Re: StyleSwitch "mod" - running into some issues.
 
Hey, "i'm back" :D

I've been off this project for a month and now that my client has noticed a "mistake" in the switcher...

http://www.lolalola.be/xcart/home.php
http://www.lolalola.be/xcart/home.php?cat=4 as you can see.... it does change the styles, according to the "parent - Id"

But as soon as you choose a product in any category " http://www.lolalola.be/xcart/product.php?productid=58&cat=46&page=1" it switches back to the default green style..... now ofcourse that is not what is meant to happen....


PHP Code:

<?php
if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }



$switchid false;
if( 
$current_category['parentid'] > ) {
    
/* Get array of all cats */
    
$all_cats func_query("SELECT categoryid, parentid FROM xcart_categories");

    
/* Build 2-dim array of parent->child cats */
    
$all_cat_arr = array();
    foreach(
$all_cats AS $_cat) {
        
$all_cat_arr[$_cat['parentid']][] = $_cat['categoryid'];
    }

    
/* Get absolute parent */
    
$switchid _get_absolute_parent($current_category['parentid'], $all_cat_arr);

}

if( !
$switchid ){
    
$switchid $current_category['categoryid'];
}

switch (
$switchid) {
    case 
'15':
    
$StyleSwitch '<style type="text/css">';
        
$StyleSwitch .= 'body {background-image: url(http://www.lolalola.be/xcart/skin1/images/lolalayout/bg_15.gif);}';
        
$StyleSwitch .= '.background { background-image: url(http://www.lolalola.be/xcart/skin1/images/lolalayout/15.gif);}';
        
$StyleSwitch .= '</style>';
        
$smarty->assign('StyleSwitch'$StyleSwitch);
        break;
    
        case 
'54':
    
$StyleSwitch '<style type="text/css">';
        
$StyleSwitch .= 'html body {background-image: url(http://www.lolalola.be/xcart/skin1/images/lolalayout/bg_54.gif); !important}';
        
$StyleSwitch .= '.background { background-image: url(http://www.lolalola.be/xcart/skin1/images/lolalayout/54.gif);}';
        
$StyleSwitch .= '</style>';
        
$smarty->assign('StyleSwitch'$StyleSwitch);
        
    break;

    
    default: 
            
}


function 
_get_absolute_parent($catid$all_cats) {
    
reset($all_cats);
    foreach(
$all_cats AS $_parentcat=>$_children) {
        if( 
in_array($catid$_children) ) {
            if(
$_parentcat == 0) {
                return 
$catid;
            }
            return 
_get_absolute_parent($_parentcat$all_cats);
        }
    }
    
/* else, failed */
    
return false;
}


?>



I've included the code that does work for the switch, but not 100% --> Can some please help me out... I know it is probably just one line of code, but I design, not develop :oops:


All times are GMT -8. The time now is 02:34 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.