Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Ecommerce 0.8.1 - add new member field

Go to End

6 Posts   1117 Views


Community Member, 34 Posts

16 February 2012 at 5:42pm

How do I go about adding a new field to the member account page.

I just need to add Company - so we can match orders/customers to current/existing customers - as we won't accept orders from anyone else.

I found instructions for older version, but nothing for the current version.

I eagerly look forward to hearing from somebody on this.


Community Member, 34 Posts

21 February 2012 at 3:58pm

I was really hoping to get support on this question seeing this module is supported.

I still do not know how to add the Company field to the account form.


Community Member, 34 Posts

22 February 2012 at 11:42am

It seems, I have this in mysite/_config.php

Object::add_extension('Member', 'EcommerceRole');

But it is not adding the company field to the account page.

I cannot figure out why?

I would really love it if someone could please give me some support on this? Or is Silverstripe and the e-commerce module a dead project?


Community Member, 34 Posts

23 February 2012 at 10:51am

Edited: 23/02/2012 10:52am

I solved it.

I had to add the company filed to ecommercerole.php

I have shared this in case anyone else needs to know what to do.

file didn't here is the code

 * EcommerceRole provides customisations to the [email protected] Member}
 * class specifically for this ecommerce module.
 * @package ecommerce
class EcommerceRole extends DataObjectDecorator {

	protected static $group_name = "Shop Customers";
		static function set_group_name($v) {self::$group_name = $v;}
		static function get_group_name(){return self::$group_name;}

	function extraStatics() {
		return array(
			'db' => array(
			    'Company' => 'Varchar(100)',
				'Address' => 'Varchar(255)',
				'AddressLine2' => 'Varchar(255)',
				'City' => 'Varchar(100)',
				'PostalCode' => 'Varchar(30)',
				'State' => 'Varchar(100)',
				'Country' => 'Varchar',
				'HomePhone' => 'Varchar(100)',
				'MobilePhone' => 'Varchar(100)',
				'Notes' => 'HTMLText'

	static function findCountryTitle($code) {
		user_error("depreciated, please use EcommerceRole::find_country_title", E_USER_NOTICE);
		return self::find_country_title($code);

	static function find_country_title($code) {
		$countries = Geoip::getCountryDropDown();
		// check if code was provided, and is found in the country array
		if($code && $countries[$code]) {
			return $countries[$code];
		} else {
			return false;

	 * Find the member's country.
	 * If there is no member logged in, try to resolve
	 * their IP address to a country.
	 * @return string Found country of member
	static function findCountry() {
		user_error("depreciated, please use EcommerceRole::find_country", E_USER_NOTICE);
		return self::find_country();
	static function find_country() {
		$member = Member::currentUser();

		if($member && $member->Country) {
			$country = $member->Country;
		} else {
			if($country = ShoppingCart::get_country())
				return $country;
			// HACK Avoid CLI tests from breaking (GeoIP gets in the way of unbiased tests!)
			// @todo Introduce a better way of disabling GeoIP as needed (Geoip::disable() ?)
			if(Director::is_cli()) {
				$country = null;
			} else {
				$country = Geoip::visitor_country();

		return $country;

	static function add_members_to_customer_group() {
		$gp = DataObject::get_one("Group", "\"Title\" = '".self::get_group_name()."'");
		if(!$gp) {
			$gp = new Group();
			$gp->Title = self::get_group_name();
			$gp->Sort = 999998;
		$allCombos = DB::query("
			SELECT \"Group_Members\".\"ID\", \"Group_Members\".\"MemberID\", \"Group_Members\".\"GroupID\"
			FROM \"Group_Members\"
			WHERE \"Group_Members\".\"GroupID\" = ".$gp->ID.";"
		//make an array of all combos
		$alreadyAdded = array();
		$alreadyAdded[-1] = -1;
		if($allCombos) {
			foreach($allCombos as $combo) {
				$alreadyAdded[$combo["MemberID"]] = $combo["MemberID"];
		$unlistedMembers = DataObject::get(
			$where = "\"Member\".\"ID\" NOT IN (".implode(",",$alreadyAdded).")",
			$sort = null,
			$join = "INNER JOIN \"Order\" ON \"Order\".\"MemberID\" = \"Member\".\"ID\""

		//add combos
		if($unlistedMembers) {
			$existingMembers = $gp->Members();
			foreach($unlistedMembers as $member) {

	 * Create a new member with given data for a new member,
	 * or merge the data into the logged in member.
	 * IMPORTANT: Before creating a new Member record, we first
	 * check that the request email address doesn't already exist.
	 * @param array $data Form request data to update the member with
	 * @return boolean|object Member object or boolean FALSE
	public static function createOrMerge($data) {
		user_error("depreciated, please use EcommerceRole::ecommerce_create_or_merge", E_USER_NOTICE);
		return self::ecommerce_create_or_merge($data);

	public static function ecommerce_create_or_merge($data) {
		// Because we are using a ConfirmedPasswordField, the password will
		// be an array of two fields
		if(isset($data['Password']) && is_array($data['Password'])) {
			$data['Password'] = $data['Password']['_Password'];
		// We need to ensure that the unique field is never overwritten
		$uniqueField = Member::get_unique_identifier_field();
		if(isset($data[$uniqueField])) {
			$SQL_unique = Convert::raw2xml($data[$uniqueField]);
			// TODO review - should $uniqueField be quoted by Member::get_unique_identifier_field() already? (this would be sapphire bug) 
			$existingUniqueMember = DataObject::get_one('Member', "\"$uniqueField\" = '{$SQL_unique}'");
			if($existingUniqueMember && $existingUniqueMember->exists()) {
				if(Member::currentUserID() != $existingUniqueMember->ID) {
					return false;
		if(!$member = Member::currentUser()) {
			$member = new Member();
		return $member;

	function updateCMSFields($fields) {
		$fields->addFieldToTab('Root.Main', new DropdownField('Country', 'Country', Geoip::getCountryDropDown()));

	 * Give the two letter code to resolve the title of the country.
	 * @param string $code Country code
	 * @return string|boolean String if country found, boolean FALSE if nothing found
	function getEcommerceFields() {
		$fields = new FieldSet(
			new HeaderField(_t('EcommerceRole.PERSONALINFORMATION','Personal Information'), 3),
			new TextField('Company', _t('EcommerceRole.COMPANY','Company')),
			new TextField('FirstName', _t('EcommerceRole.FIRSTNAME','First Name')),
			new TextField('Surname', _t('EcommerceRole.SURNAME','Surname')),
			new TextField('HomePhone', _t('EcommerceRole.HOMEPHONE','Phone')),
			new TextField('MobilePhone', _t('EcommerceRole.MOBILEPHONE','Mobile')),
			new EmailField('Email', _t('EcommerceRole.EMAIL','Email')),
			new TextField('Address', _t('EcommerceRole.ADDRESS','Address')),
			new TextField('AddressLine2', _t('EcommerceRole.ADDRESSLINE2','&nbsp;')),
			new TextField('City', _t('EcommerceRole.CITY','City')),
			new TextField('PostalCode', _t('EcommerceRole.POSTALCODE','Postal Code')),
			new DropdownField('Country', _t('EcommerceRole.COUNTRY','Country'), Geoip::getCountryDropDown(), self::find_country())
		$this->owner->extend('augmentEcommerceFields', $fields);
		return $fields;

	 * Return which member fields should be required on [email protected] OrderForm}
	 * and [email protected] ShopAccountForm}.
	 * @return array
	function getEcommerceRequiredFields() {
		$fields = array(
		$this->owner->extend('augmentEcommerceRequiredFields', $fields);
		return $fields;

	public function CountryTitle() {
		return self::find_country_title($this->owner->Country);

	//this method needs to be tested!
	public function onAfterWrite() {



Community Member, 6 Posts

15 March 2012 at 11:01pm

that's great!


Forum Moderator, 238 Posts

26 March 2012 at 4:14pm

Hi Kiwipearls,

My apologies for not answering your questions sooner. I'm not aware of a subscribe-to-all feature so that I can instantly get problems to my inbox.

I've created a tutorial/recipe in the shop module docs: