Jump to content

Passing Multiple Customer Variables in Product Description


Recommended Posts

I have modified the product.tpl file so that certain customer parameters are passed.  I can successfully output the variable and do a string replacement.  There are a few customer variables including some new ones I've added to the customer table.  I have verified that the variables are being passed via an override to the productcontroller.php.

 

I have created custom variables in the product description that include a format as ##firstname##, ##lastname##, etc.  My goal is to replace these hashtag annotated variables with the actual data stored in the customer table.  My product.tpl file has the following that successfully performs a string replacement on the first variable.

		{if $firstname}
			<div id="idTab1" class="rte">{str_replace('##firstname##', {$firstname}, $product->description)}</div>
		{else}
		<div id="idTab1" class="rte">{str_replace('mid=##firstname##', {$firstname}, $product->description)}</div>
		{/if}

If I try follow on statements to replace additional variables, only the first variable is replaced, and the output displays the first variable properly, followed by ##variable2##, ##variable3##, ...  This is the code I am using:

{* added firstname in string replacement here *}
		{if $firstname}
			<div id="idTab1" class="rte">{str_replace('##firstname##', {$firstname}, $product->description)}</div>
		{else}
		<div id="idTab1" class="rte">{str_replace('mid=##firstname##', {$firstname}, $product->description)}</div>
		{/if}
{* added lastname in string replacement here *}
		{if $lastname}
			<div id="idTab1" class="rte">{str_replace('##lastname##', {$lastname}, $product->description)}</div>
		{else}
		<div id="idTab1" class="rte">{str_replace('mid=##lastname##', {$lastname}, $product->description)}</div>
		{/if}
{* added yachtclub in string replacement here *}
		{if $yachtclub}
			<div id="idTab1" class="rte">{str_replace('##yachtclub##', {$yachtclub}, $product->description)}</div>
		{else}
		<div id="idTab1" class="rte">{str_replace('mid=##yachtclub##', {$yachtclub}, $product->description)}</div>
		{/if}

How do I make the string replacement so it works for all variables, not just the 1st one?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...