简体   繁体   中英

Extra data in cs-cart cart content

For each of added products in cart content I want to display some extra data, that comes out of other database. Getting data from that database is not a problem. However I am having problems passing custom variable into cart_content.tpl (view file) . This is what I do inside fn_add_product_to_cart (in fn.cart.php file):

foreach ($product_data as $key => $data) {
    $data['test'] = 'testing';
    ........
}

But key test is nowhere to be found inside view (even if I var_dump product variable ). What am I doing wrong?

Thank you in advice.

EDIT: To help you a little bit: I have a view file cart_content.tpl. There is a foreach loop to write down all of the products in users cart.

{foreach from=$_cart_products key="key" item="p" name="cart_products"}
{/foreach}

What I want is to output just a simple test string (like that: {$p.test}) but I don't know, how to add that custom value to array. For start it would be enough to just add some test string so I can use it in view.

Hope it helps. It should be really simple, just add new value to associative array and that's it but it does not work that way here I guess.

Well, I did it! In that very same function, you add $cart['products'][$_id]['test'] = 'test'; and it works!

You should assing it to view:

Tygh::$app['view']->assign('test', $data['test']);

Afte you can use it in .tpl like {$test}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM