1

I am trying to find a way to split a customer text attribute in order to display it on the frontend.

I have added a new text field to the customer address and would like to display this value on the frontend in View.phtml file. The problem is that the value is stored as a string depending on customer location for Euro we have €|c and for UK we have £|p stored in this field.

I need to some how split this value for display it in separate places.

I am using jQuery to validate a price form on the frontend. Customers from EU need to have the €|c value displayed and UK customer need to have the £|p displayed from the TextAttribute.

So I need to somehow get the customer attribute to show in the product/view.phtml file THEN split the array()

Here's my code:

 if (x<100) { //c OR p Value needs to go here validOptions.push( "<?php echo $address->getCurrency(); ?>"+x+""); } else { var y = x.toString(); var z = y.split(''); //£ OR € Value needs to go here validOptions.push("<?php echo $address->getCurrency(); ?>"+z[0]+"."+z[1]+""+z[2]+""); } x++; 

Does anyone know how to do this please give me a heads up...

2 Answers 2

3

Use the following snippet to retrieve your attribute and split it on a |

$currency = Mage::getSingleton('customer/session')->getCustomer()->getData('your-custom-attributecode'); $currency_split = explode('|', $currency); 
4
  • Thanks for your advice, The code gives me the following result Array1.00 Commented Feb 24, 2014 at 21:18
  • Try and echo $currency_split[0] or $currency_split[1] instead of $currency_split Commented Feb 24, 2014 at 21:22
  • Did you manage to resolve the issue? @user1704524 Commented Mar 6, 2014 at 12:29
  • Yes, I had to tweak your suggestion slightly but it worked! Commented Mar 7, 2014 at 13:23
2

Thanks, this works fine..

<?php $split = explode('|', $address->getCurrency()); echo $split[0]; ?>"+z[0]+"."+z[1]+""+z[2]+"?> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.