Displaying api output


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

  1. I have created a page (using the admin panel menu) with a input box
  2. 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
  3. 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?

Cheers :slight_smile:


  1. 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.

  2. It’s up to you decide how to make you add-on, but in case you wish to offer it to other people, you need to rework it to comply with the coding standards:
    Coding Standards — CS-Cart 4.16.x documentation
    DOs and DON’Ts for CS-Cart Devs — CS-Cart 4.16.x documentation
    Controllers — CS-Cart 4.16.x documentation

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.

In this case, I recommend starting with these tutorials, which will introduce you to the wonderful world of CS-Cart add-ons. :slight_smile:

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.

Oh, sorry, I read it in the wrong way. Instead of

I have read

I want to commercialise it so I think that is ok?

Forgive me for my blindness :smiling_face_with_tear:

In case you will use the separate script, you need to do the following:

  1. Make sure that your script connects to the installation itself. This can be achieved by including the following code in the beginning of your script:
define('AREA', 'A');
define('ACCOUNT_TYPE', 'admin');

require(dirname(__FILE__) . '/init.php');
  1. Once all the necessary data is processed and is ready to be displayed, you can now to put it into the Smarty variable:
Tygh::$app['view']->assign('variable_name', $data);

where variable_name will be the name of the variable that can be used in the Smarty template.

  1. Than, since all the code is located within one separate script (not as separate controller within an add-on), you can manually display the template:

where views/auth/popup_login_form.tpl is the relative path to the template from the design/themes/[active_theme_name]/templates/ folder.

  1. 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
1 Like

MANY thanks for this @CS-Cart_team!

1 Like