Forach In Template To Show All Product Codes In Product Line

I have a column in product_options_inventory table named s_gstok.(which I addded as a new column) Each product has option combinations and a variable in s_gstok table. I need to show these values in products manage page. I want them to seem in each product line.



I made an example that I try to show product_code like this: ProductCode1, ProductCode2, ProductCode3. All of these product code belong to only one product which has combinations.



Here is the code I made for example:



product.post.php

<br />
if ($mode == 'manage') {<br />
<br />
		$products = Registry::get('view')->getTemplateVars('products');<br />
				<br />
				foreach ($products as $k => $d) {<br />
				$data = db_get_array("SELECT ?:product_options_inventory.product_code FROM ?:products ".<br />
								   "LEFT JOIN ?:product_options_inventory ON ?:product_options_inventory.product_id = ?:products.product_id ".<br />
								   "WHERE ?:products.product_id = ?i", $d['product_id'] );<br />
				<br />
						foreach ($data as $v){<br />
							$products[$k]['product_code'] = $v['product_code'];<br />
						}<br />
				<br />
				}<br />
<br />
		   Registry::get('view')->assign('products', $products);<br />
}<br />

```<br />
<br />
[b]manage_body.post.tpl[/b]<br />
```php
<br />
{if $products}<br />
{foreach from=$products item="product"}<br />
	{$product.product_code}<br />
{/foreach}<br />
{/if}<br />

```<br />
<br />
But it is not correct. Where am I making mistake? <img src="upload://n4syhXZrRhsStKvmS4jT3Mp2S3k.png" class="bbc_emoticon" alt=":("><br />
<br />
Note: I am going to change product_code variable according to my database.

[quote name=‘ooaykac’ timestamp=‘1430240650’ post=‘212851’]But it is not correct. Where am I making mistake? :(

[/quote]



Do you receive any errors? Or product codes are just not displayed?

Hello eCom. Below you can see the picture. first product has NO product code. Second product has a main product code and 3 option combinations with product code.





In my_field column, I am trying to list all cıombination product codes of a product in its line. But it shows only last combination product code and in each product. See my_field column in picture.

Try to replace:



foreach ($data as $v){
$products[$k]['product_code'] = $v['product_code'];
}




with



if (!empty($data)) {
foreach ($data as $v){
$products[$k]['product_code'] .= (", " . $v['product_code']);
}
}

Hello eCom. I have realized that I shlould not to use “foreach loop” in template. I changed


$products[$k]['product_code'] = $v['product_code'];


to


$products[$k]['product_code'] .= $v['product_code'];




and from


{foreach from=$products item="product"}
{$product.product_code}
{/foreach}


to


{$product.product_code}


This is the correct way. Now it's working. Thank you.

You are welcome!