I am at a begginer level with cs-cart coding. I have the output I want in raw format (outputs some strings and links), but are stuck on the next step
Q1. How do I now display my output within a cs-cart frame/page?
This is how my solution works so far
I have created a page (using the admin panel menu) with a input box
I have a php file in the root of the store that takes the $Pist input box, makes some API calls and returns an array of results
using basic php/html tags I have a set of vairables I want to display
Q2. Also is it wrong to go about a solution this way, I know the solution is personalised to my store, and it isn’t an add-on but I don’t want to commercialise it so I think that is ok? i.e. as long as I prevent sql injection there isn’t a security risk and if I am not doing PUTs I am not going to break anything?
It’s better to output to the Smarty template. This way you can separate the logic of the code from the display of its contents, and use all the features that Smarty has to offer.
Hi,
Thanks for the input. I don’t think I have broken any of the listed standards. I am simply using API calls to get data and then manipulating it (but not modifying/PUTing it), what suggests I might have not followed any of those links (and I will go back and have another look, not that I am selling it, but good to learn right from the start!).
My PHP file is called from a submit action from a form using the inbuilt menu/capabilities … so don’t think anything wrong their either?
So how do I follow your advice and use a smarty to display the content (I know how to add a html/smarty block to layout) … could you give me an example based on if I had created a vairable $my_test_variable in my php file how would I display that? does it have to be on the same page where the form called the php file? … or is this where the standards start to become an issue i.e. you can’t get back into cs-cart ‘legitimately’ without an add-on?
Speaking of add-ons, for example it won’t be possible to provide such a solution at the CS-Cart Add-on Market, since your solution (if it is not a service) must have a package with your add-on.
You still haven’t answered either question and twice addressed a question I didn’t ask (I have said I don’t want ot sell it). But thanks for having a crack at it.
where views/auth/popup_login_form.tpl is the relative path to the template from the design/themes/[active_theme_name]/templates/ folder.
Create the template, which path you have specified in the 3rd step. There you will be able to use all the variables you have assigned in the 2nd step. Information on Smarty syntax can be found here: Smarty Documentation
I have tried to apply this and when it wasn’t working I dumbed it down to a simple test but I get a 404 not found error. I believe I have followed @CS-Cart_team instructions but I musn’t have?
1. Created custom_script.php in root directy
<?php
define('AREA', 'A');
define('ACCOUNT_TYPE', 'admin');
require(dirname(__FILE__) . '/init.php');
use Tygh\Registry;
// Sample data to be assigned
$data = array(
'message' => 'Hello, this is a custom message test!',
'timestamp' => date('Y-m-d H:i:s')
);
// Assign the data to a Smarty variable
Tygh::$app['view']->assign('custom_data', $data);
// Display the template
Tygh::$app['view']->display('views/auth/custom_template.tpl');
?>
I see that previously, I wrote that you need to define AREA as A, and recommended to create a template in the theme’s folder. That’s a mistake.
In case you need to display the template from the frontend (theme’s folder), the AREA should be defined as C:
define('AREA', 'C');
In other way, the template must be located within the design/backend/templates folder.
As for the current situation, 404 error in response, I can only assume, that this script has incorrect permissions and/or ownership. Check that everything is correct there.
No, it’s definitely should look like you’ve made if before:
// Assign the data to a Smarty variable
Tygh::$app['view']->assign('custom_data', $data);
// Display the template
Tygh::$app['view']->display('views/auth/custom_template.tpl');
Try to print out the contents of the variable in full:
I ended up getting it working by putting it into the my_changes add-on. That defeats the original point, but at least it takes me closer to my own add-on. Until now I haven’t been too successful with the add-ons. Php, sql, vba, chatgpt no worries, but just can’t get my head around working with cs-cart (API is easy enough, but limited options). Heaps appreciate the help though.