Question

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

Was it helpful?

Solution

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);

OTHER TIPS

Thanks, this works fine..

<?php $split = explode('|', $address->getCurrency());
  echo $split[0]; ?>"+z[0]+"."+z[1]+""+z[2]+"?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top