How To Do This With Smarty

Hello,

I would like to ask you guys this question, not sure if anyone can or not.

let say on the product edit page, we see there is basic WYSIWYG editor, just like this editor on this forums.

my question is, is there any possibilities to make it work like this; you use the editor just like normal, but it will support the smarty html.

normally it will save the data with normal html kind of tags. but I was thinking to change it and the final results of output saved as data on database.

let say acme become acme-company

acme
acme-company

Simtech
Simtech

I don't know how to call this in English and Cs-cart, but maybe it call rendering or what?

My point is to save rendered data in db field.

I am sure there should be someway to do it. as I have tried to pay with cs-cart and changed something here and I could to change entire outputs with certain placeholder and keyword.

\app\functions\smarty_plugins\function.render_location.php

$br = new RenderManager($dispatch, $area, $dynamic_object, $location_id, $lang_code, $device_filter);

$esliText = $br->render();

///DELETED some working code here, but example is clear

return $esliText;
// return $br->render();

\app\functions\smarty_plugins\function.render_location.php

in this case I can imagine that with help of 'update_product_post' hook how can we do render product['desc'] before saved in database or update it right way with the hook and resave the rendered final version in db field?

Please share your knowledge, thanks!

Try to find how the HTML block with SMARTY support is rendered in CS-Cart. This should help you

Try to find how the HTML block with SMARTY support is rendered in CS-Cart. This should help you

Hello eComLabs,

yeah, it's exactly what I am thinking. but I couldn't figure it out how to do. on cs-cart, I have learned many things with php hooks and functions on \app\functions\*.php little, and little smarty functions. however I don't think rendering is there.

but \app\Tygh is huge, and plus all OOP(Object Oriented Programming) and with that category I couldn't learn too much, but trying to figure it out.

I am sure somewhere should able to do this with hooks or functions if we can find it.

cs-cart support seems don't care and they don't have a documentations to explain how works the rendering part.

if we can figure this out, I am sure this will bring a huge adaptability to cs-cart. for example with this, you can also adapt the spinning text apps/functions. this is and will be very huge market for cs-cart.

I am really like cs-cart and that is reason I am investing a lots of my time, money, energy to learn. however, sometimes facing this kind of things, stuck somewhere.

Try to use in template

{eval_string var=$description}

The description variable should contain required content

(!) Not tested

Try to use in template

{eval_string var=$description}

The description variable should contain required content

(!) Not tested

Dear eComLabs,

Thank you very much for your redirection and it works. however, I couldn't figure out one thing;

currently it works if I have saved product description with smarty html code on backend and if I have changed the product desc with eval_string in frontend.

how to do the same thing in backward?

for example I want to it to save on backend after execute eval_string code? I mean after the POST, I want to execute eval and save the result in database.

I know on the php part with the hook "update_product_post" possible. but how to use the smarty function "eval_string" with php?

Please dear eComLabs, I need here some help. Thanks in advance!

Try to use

$description = Tygh::$app['view']->fetch('string:' . $description);

Try to use

$description = Tygh::$app['view']->fetch('string:' . $description);

Hi eComLabs,

I have tried your code, but it doesn't work. look;

use Tygh\Registry;

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
if ($mode == ‘update’) {

	$description = Tygh::$app['view']->fetch('string:' . $_REQUEST['product_data']['short_description']);

fn_print_r($_REQUEST[‘product_data’][‘short_description’]);
fn_print_die($description);

}

}

results are this;

Hello from {$product.company_id|fn_get_company_name} in {$product.company_id|fn_get_company_name}

Hello from in

did I miss anything eComLabs? the smarty code should executed before posting or we should execute it here, isn't? if we execute here, then again, how can we use the eval_string, smarty functions in PHP?

Most possibly braces are HTML entities in your case (e.g. { instead of { )

Try to switch WYSIWYG editor to the source code mode and check again

Most possibly braces are HTML entities in your case (e.g. { instead of { )

Try to switch WYSIWYG editor to the source code mode and check again

No, even pure smarty format text, still it doesn't work. I did some research and find out that there is really something is missing. for example, after POST sent on admin panel, we are sending only smarty code and it's not rendered code. but then did something like below code, but then find out this is not exact solution.

use Tygh\Tygh;
use Tygh\Registry;
use Tygh\SmartyEngine\Core as SmartyCore;

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
if ($mode == ‘update’) {

//$description = Tygh::$app[‘view’]->fetch(‘string:’ . $description);
//$description = Tygh::$app[‘view’]->fetch(‘string:’ . $_REQUEST[‘product_data’][‘short_description’]);

//fn_print_die($_REQUEST);
//fn_print_die(Tygh::$app[‘view’]);

$description = Tygh::$app[‘view’]->fetch(‘string:’ . $_REQUEST[‘product_data’][‘short_description’]);

/////////////////////////////////////////////////////
//these codes works perfectly and as expected
$Smarty = new Smarty();
$template = “{1|fn_get_company_name} in {1|fn_get_company_name}”;
$compiled = $Smarty->fetch(‘string:’ . $template);
fn_print_r($compiled); fn_print_r(is_object($Smarty));
/////////////////////////////////////////////////////

$template1 = “{$_REQUEST[‘product_data’][‘short_description’]}”;
$compiled1 = smarty_function_eval_string(array(“var”=>$template1), $Smarty);
fn_print_r($template1);
fn_print_r($compiled1);
fn_print_r(“================”);

fn_print_r($_REQUEST[‘product_data’][‘short_description’]);
fn_print_die($description);

}

}

on the admin panel, we do input the smarty code and it's not compiled/rendered and pure code sent to back end.

on frontend already works if we saved the smarty code on database, this part is done. with this {eval_string var=$description}

well, after receiving code with POST, we must render it. but how?

I have even tried to copy smarty function to my func.php file and use it there as you see, but still it doesn't work. I read many articles on internet and tried above code, but still after receiving smarty code, still not works.

if receiving code and render it as above like my style, then will be another problems, because in that case, all cs-cart's variables that used in smarty template won't work. for example $product.product_id won't work, because you have to manually tell to smarty which product are you talking....

then what is solution here?

cs-cart support won't answer to this? probably support team don't know either, but for sure architec they know this.

Sorry, I cannot help you without detailed examination. The mentioned code works on my local installation

Hello!

I have check your first message, it will be easier to save the data in the required way with using the update_product_pre hook.

You can search vai preg_match in the $product_data['full_description']. For example, you search for the following pattern:

if (preg_match('/href="dispatch=.*"/', $product_data['full_description'], $matches)) {
    foreach ($matches as $match) {
        $replace = fn_url($match, 'C');
        $product_data['full_description'] = str_replace($match, $replace, $product_data['full_description']);
    }
}

or something like this. Not the best solution of course, but it should work :)

Hello!

I have check your first message, it will be easier to save the data in the required way with using the update_product_pre hook.

You can search vai preg_match in the $product_data['full_description']. For example, you search for the following pattern:

if (preg_match('/href="dispatch=.*"/', $product_data['full_description'], $matches)) {
    foreach ($matches as $match) {
        $replace = fn_url($match, 'C');
        $product_data['full_description'] = str_replace($match, $replace, $product_data['full_description']);
    }
}

or something like this. Not the best solution of course, but it should work :)

Hello cs-cart team,

Thank you very much for your reply.

but what I was asking was not just to change one link, but use whole smarty html. by your example, only if we use certain cs-cart links, then it's ok. but by your example, smarty template can't be rendered.

example you can't render this;

{$product.company_id|fn_get_company_name} provides various {$product.category_id|fn_get_category_name} products and {$product.product_id|fn_get_product_name} published on {$product.timestamp|timeformat} and since then in {$product.city_id|fn_get_city_name} sold {$product.product_id|fn_get_myordertotal_count}.

I have been searching a solution on this and read too many articles by eComLabs` redirect and very clearly understand this;

on product edit page, if we input smarty code on the field, because the product edit page itself is using smarty already, we can't render it right way on the page and as well it will be wrong. I have tried to edit the update.tpl file to see how it works and result is somehow not success.

{$product_data.product_id|fn_print_r}
{if $product_data.short_description|trim}
{assign var="my_short_description" value={$product_data.short_description|trim nofilter}}
{*eval_string var=$my_short_description*}///this line not works here, why? tried eval and eval_string, both not works
{/if}

{eval $my_short_description} ///kind of eval, but outs only

{assign var=“putti” value=“{eval $my_short_description}”} ///kind of eval, but outs only

{$putti|fn_print_r}
{$product_data[‘my_short_description’] = $putti }
{$my_short_description|fn_print_r}
{$product_data[‘my_short_description’]|fn_print_r}

If you know, please, please, please, can you tell me how can I do render the smarty code from db field on update.tpl? or better solution on php with the hooks? or what is your solution?

if you read above, eComLabs redirected me right, ->fetch but it won't work. I already tried on localhost or domain, ultimate or multi-vendor, it won't work. I read many article, there are some of them;

http://www.smarty.net/docs/en/api.fetch.tpl

https://www.smarty.net/docsv2/en/language.function.eval.tpl

https://stackoverflow.com/questions/1866221/smarty-how-to-evaluate-string-as-a-variable

https://stackoverflow.com/questions/4315046/smarty-evaluate-a-template-stored-in-a-php-variable?rq=1

then how we can do achieve this?

this is very important thing, if we can achieve this, then cs-cart is more adaptable with other software like spintext or other anything.

Please help, I believe many cs-cart owners looking for a solution.

Thanks in advance!

I even tried copying the smart function into my func.php file and using it as you can see but it still doesn't work. I have read a lot of articles online and tried the above code but after getting the smart code it still doesn't work.
if you get the code and display it like above in my style then that will be another problem because in that case all the cs-cart variables used in the smarty template won't work. for example $product.product_id won't work because you'll have to manually tell smarty which product you're talking about.

Hello cs-cart team,

Thank you very much for your reply.

but what I was asking was not just to change one link, but use whole smarty html. by your example, only if we use certain cs-cart links, then it's ok. but by your example, smarty template can't be rendered.

example you can't render this;

{$product.company_id|fn_get_company_name} provides various {$product.category_id|fn_get_category_name} products and {$product.product_id|fn_get_product_name} published on {$product.timestamp|timeformat} and since then in {$product.city_id|fn_get_city_name} sold {$product.product_id|fn_get_myordertotal_count}.

I have been searching a solution on this and read too many articles by eComLabs` redirect and very clearly understand this;

on product edit page, if we input smarty code on the field, because the product edit page itself is using smarty already, we can't render it right way on the page and as well it will be wrong. I have tried to edit the update.tpl file to see how it works and result is somehow not success.

{$product_data.product_id|fn_print_r}
{if $product_data.short_description|trim}
{assign var="my_short_description" value={$product_data.short_description|trim nofilter}}
{*eval_string var=$my_short_description*}///this line not works here, why? tried eval and eval_string, both not works
{/if}

{eval $my_short_description} ///kind of eval, but outs only

{assign var=“putti” value=“{eval $my_short_description}”} ///kind of eval, but outs only

{$putti|fn_print_r}
{$product_data[‘my_short_description’] = $putti }
{$my_short_description|fn_print_r}
{$product_data[‘my_short_description’]|fn_print_r}

If you know, please, please, please, can you tell me how can I do render the smarty code from db field on update.tpl? or better solution on php with the hooks? or what is your solution?

if you read above, eComLabs redirected me right, ->fetch but it won't work. I already tried on localhost or domain, ultimate or multi-vendor, it won't work. I read many article, there are some of them;

http://www.smarty.net/docs/en/api.fetch.tpl

https://www.smarty.net/docsv2/en/language.function.eval.tpl

https://stackoverflow.com/questions/1866221/smarty-how-to-evaluate-string-as-a-variable

https://stackoverflow.com/questions/4315046/smarty-evaluate-a-template-stored-in-a-php-variable?rq=1

then how we can do achieve this?

this is very important thing, if we can achieve this, then cs-cart is more adaptable with other software like spintext or other anything.

Please help, I believe many cs-cart owners looking for a solution.

Thanks in advance!

Sorry for my late response. Could you please let me know if you have tried to add to update.tpl something like this?

{eval_string var=$product_data.full_description}

And in the description use the variables in this way:

{$product_data.company_id|fn_get_company_name} provides various ..

Looking forward to your reply.

Sorry for my late response. Could you please let me know if you have tried to add to update.tpl something like this?

{eval_string var=$product_data.full_description}

And in the description use the variables in this way:

{$product_data.company_id|fn_get_company_name} provides various ..

Looking forward to your reply.

Thanks for your reply. Unfortunately it doesn't work. try by yourself.

but in frontend it works, I already mention about it above, but not in backend.

Why it should work in the backend? It should show you initial code only, isn't it? The final code is rendered in the store-front

Why it should work in the backend? It should show you initial code only, isn't it? The final code is rendered in the store-front

If you read above, I already mention, it works in storefront, not in the backend. why it has to work in the backend? because that is exactly what I am trying to do and asking for. in that way cs-cart can be integrated with different apps. if it works in storefront, there must be possibilities work in backend....

for that reason I said "probably support team don't know either, but for sure architect they know this."

if this can be figure out to work in backend, then cs-cart has a big option on integrate with other code base and it's such amazing for developers.

We have just checked the code in the admin panel and it works as expected

{$description = "

{1|fn_get_company_name} provides various ..

"} {eval_string var=$description}
result
Simtech provides various ..

We have just checked the code in the admin panel and it works as expected

{$description = "

{1|fn_get_company_name} provides various ..

"} {eval_string var=$description}
result
Simtech provides various ..

No, it's not working for me.

eComLabs,

try to put this code(including the

tag) in database and execute eval_string with the product variables(example $product_data.short_description)

{$product_data.company_id|fn_get_company_name} provides various ..

I have tried these and 1 works, the other one not works, even they both has exact the same code.

not works;

{$description6 = $product_data.short_description}
{eval_string var=$description6}
not works;
{eval_string var=$product_data.short_description}
works;
{$description5 = "

{$product_data.company_id|fn_get_company_name} provides various ..

"}
{eval_string var=$description5}

Why is that? what could be problem?

Please give more details about where do you use this code? Looks like the $product_data array does not have the short_description value on your page