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)
-   -   new/custom php page? (https://forum.x-cart.com/showthread.php?t=49898)

masada3336 09-26-2009 08:20 PM

new/custom php page?
 
Hi there.
I have bought a new search program, and need to modify a search page. I'd like to insert some php code into it, but search.php has a lot of code and calls and programming logic that I can't seem to understand (I have tried deleting code line by line, but always get some kind of error).
Is there some basic layout for a php page (that I can get a code snippet) that is basically a blank page and will allow me to put standard php code into? For that matter, is there a way to have a custom php page that has the template with "hello there" even on it in regular php, not calling a tpl page?
Thanks a bunch!!!

JWait 09-27-2009 07:47 AM

Re: new/custom php page?
 
Here is an example taken from
http://www.w3schools.com/PHP/DEfaULT.asP

<html>
<body>

<?php
echo "hello there";
?>

</body>
</html>

To get your content to be "surrounded" by your cart's design however you will need to create a template ("myphp.tpl")and include it by putting {include file="myphp.tpl"} in x-cart wherever you want your content to be displayed. Its not quite as simple as that but, not really much more difficult either. You may or may not need the "html" and/or "body" tags depending on where you place it in x-cart.
Example: name the following myphp.tpl and save it to the root directory of x-cart
Code:

<?php
echo "hello there";
?>

Now, in xcart-root/skin1/customer/home.tpl find where it says {include file="help.tpl"}. Copy and paste it (putting a <br /> between the old and new, and then change "help" to "myphp". Clear your templates cache (www.yoursite.com/cleanup.php) and reload the page. "hello there" should appear right after (or before, depending on which instance you modified above) the "News" section.

masada3336 09-27-2009 08:39 AM

Re: new/custom php page?
 
Thanks a million J!
I'd like the page to sit alone though - not be a template that's included within the home page - just like either the cart.php, search.php, news.php, or any of the other php pages that only have one type of content in them.
If I did this correctly, it shows on the main template on each page, not when I call xcart/mypage.php right?
Thanks again!

JWait 09-27-2009 08:59 AM

Re: new/custom php page?
 
A lot depends on how you want to access it. You could just make a static page and include a link in the speed bar. That will put your content in the "center" area of your cart (similar to your FAQ page).

Your php will probably need some of the "includes" that are used by x-cart. Look at just about any php script x-cart uses (they are near the top... (require "./auth.php"; require "./security.php"; whatever ones seem necessary).

JWait 09-27-2009 09:10 AM

Re: new/custom php page?
 
It sounds like you are working on a "search" module, but you didn't specify if it was for the customer or admin. Anyway, what if you used the present link ("advanced search") and linked it to your new "my_search.tpl and my_search.php" using the existing search template and search.php and cloned them, putting in your own code.

I would be interested to see what you come up with.

masada3336 09-27-2009 10:43 AM

Re: new/custom php page?
 
Yep - I am trying to put together a new search module for my site. I've tried to dissect the search.php page. I've commented out just about everything to just a bare-bones page, but when I do that I get a "page not found" error.
I guess what I'm looking for is how to build a basic php page...what elements have to go in it, and where they have to be. I've gleaned from these forums that I need a php page with an include to a tpl file?

my search.php is this:

Code:

<?php
#
# $Id: mysearch.php,v 1.5.2.2 2008/04/11 18:09:11 osipov Exp $
#

require "./auth.php";

require $xcart_dir."/include/categories.php";
require $xcart_dir."/skin1/mysearch.tpl";

$smarty->assign("_mysearch_",$_new_page_);
$smarty->assign("main","_mysearch_");

$smarty->assign("location", $location);
$smarty->assign("products",$products);

func_display("customer/home.tpl",$smarty);

?>


I flushed my templates, but just for a test my tpl file:
Code:

{* $Id: mysearch.tpl *}

test

The result is a page with the error "page not found" in the body area (where I want "test" displayed) and the actual template contents in raw text at the top of the page.

Where am I screwing up?

masada3336 09-27-2009 10:57 AM

Re: new/custom php page?
 
I've tried to use balinor's post here, but it doesn't explain how tpl's interact with php pages and vice-versa.
Thanks again!

JWait 09-27-2009 10:58 AM

Re: new/custom php page?
 
Umm.. try looking at skin1/customer/search.tpl.
Note that it has some "search" parameters and then at the bottom of the code (after the button) it has
Code:

<a href="search.php"><u>{$lng.lbl_advanced_search}</u></a>
try changing "search.php" to "mysearch.php" but I would add our friendly little
Code:

echo "hello there";
to mysearch.php so that it has something (anything) to display and go from there.

JWait 09-27-2009 11:11 AM

Re: new/custom php page?
 
I'm no wiz at php but I think the
require $xcart_dir."/skin1/mysearch.tpl";
is wrong.

There should be a include skin1/search.tpl that calls mysearch.php, not the other way around (I think).

A .tpl is pretty much html, and html can include php, but I'm not sure about the other way around. I know php can include html code, that can be displayed, but I'm not sure that entire .tpls can be used.

cflsystems 09-27-2009 11:59 AM

Re: new/custom php page?
 
Quote:

Originally Posted by masada3336
Yep - I am trying to put together a new search module for my site. I've tried to dissect the search.php page. I've commented out just about everything to just a bare-bones page, but when I do that I get a "page not found" error.
I guess what I'm looking for is how to build a basic php page...what elements have to go in it, and where they have to be. I've gleaned from these forums that I need a php page with an include to a tpl file?

my search.php is this:

Code:

<?php
#
# $Id: mysearch.php,v 1.5.2.2 2008/04/11 18:09:11 osipov Exp $
#
 
require "./auth.php";
 
require $xcart_dir."/include/categories.php";
require $xcart_dir."/skin1/mysearch.tpl";
 
$smarty->assign("_mysearch_",$_new_page_);
$smarty->assign("main","_mysearch_");
 
$smarty->assign("location", $location);
$smarty->assign("products",$products);
 
func_display("customer/home.tpl",$smarty);
 
?>


I flushed my templates, but just for a test my tpl file:
Code:

{* $Id: mysearch.tpl *}
 
test

The result is a page with the error "page not found" in the body area (where I want "test" displayed) and the actual template contents in raw text at the top of the page.

Where am I screwing up?


If you want this page displayed on customers side in skin1/cusotmer/home_main.tpl you have to specify which template to load when your new.php is called

{if $main eq "_mysearch_"}
{include file="path_to_file/mysearch.tpl"}
{/if}

Just look at the if statement there you will get the idea

masada3336 09-27-2009 12:33 PM

Re: new/custom php page?
 
Thanks guys - I did get it to work now and am just trying to get the specific php calls working now. I'll let ya know when it's working and what I did to make it work correctly.
Thanks again!

masada3336 09-27-2009 09:38 PM

Re: new/custom php page?
 
OK guys - I have successfully implemented php being used in the tpl file. I can get it to echo "hello world". However, in the tpl file I have a call to http://www.mysite.com/my_search_file.php:
Code:

{include_php file="http://www.mysite.com/my_search_file.php"}
When I go to mysite.com/mysearch.php, when I only have it echo "hello world" it works. When i ask it like I have above to pull the php file, it gives me a smarty error "my_search_file.php is not readable in /mysite/Smarty-2.6.19/Smarty.class.php on line 1092"
Anyone know what gives?
TIA!

JWait 09-28-2009 04:22 AM

Re: new/custom php page?
 
Well, "not readable" is usually a permissions problem, but I'm not sure of the "include_php file" syntax.
Usually it would be a link like <a href="http://www.mysite.com/my_search_file.php">my search file</a>.

Also, look at search.tpl and search.php and the way they interact with each other. In search.tpl it "calls" search.php twice, once at the beginning of the file...
<form method="post" action="search.php" name="productsearchform">
and then again towards the end of the file...
<a href="search.php" class="Search">{$lng.lbl_advanced_search}</a>.

Each instance does something different. The first one asks for user input and then processes it. The second one "opens" search.php so the user can choose which input is relevant. Searching x-cart is a pretty involved process.

masada3336 09-29-2009 07:23 AM

Re: new/custom php page?
 
OK - I've tried everything I know of how to get this php search script to work. I've tried embedding it within {php} {/php} tags in the tpl file, but when I do that, it shows a blank page. So, I've had to refrence it as an external file from the tpl file:
Code:

{include_php file="skin1/customer/new/search.php"}
This is the only way to get it to call successfully, but then I run into a timeout error...shouldn't I be able to put the php code within the tpl files? Is there something that might cause an error I should be looking for that might cause it not to display if it's inside a tpl file, vs. outside include?

masada3336 09-29-2009 07:26 AM

Re: new/custom php page?
 
Oh, the logic for everything is this: xcart/mysearch.php --> skin1/customer/mysearch.tpl --> skin1/customer/new/search.php which is the actual code for the search...

JWait 09-29-2009 09:48 AM

Re: new/custom php page?
 
You really shouldn't have .php files in the skin1 directory. What if you moved it to x-cart root/include (except that is where the original search.php is) - can you rename your "new" search.php to mysearch2.php?


All times are GMT -8. The time now is 12:56 AM.

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