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...

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);
  • Thanks for your advice, The code gives me the following result Array1.00 – user1704524 Feb 24 '14 at 21:18
  • Try and echo $currency_split[0] or $currency_split[1] instead of $currency_split – Sander Mangel Feb 24 '14 at 21:22
  • Did you manage to resolve the issue? @user1704524 – Sander Mangel Mar 6 '14 at 12:29
  • Yes, I had to tweak your suggestion slightly but it worked! – user1704524 Mar 7 '14 at 13:23
2

Thanks, this works fine..

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.