We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem, Shop

Custom fields for new perch shop customers

Hi,

I know this is a subject already broached by others, but we are working on a Perch shop with Runway and we are trying to add a couple of extra fields to the shop registration process.

What has us a bit confused is that we are using a combination of shop and member functions with different results.

When a new customer registers they use the perch_shop_registration_form(); using the template customer_create.html

We've added two new fields: Phone Number, and Date of Birth, so:

<div class="row">
              <div class="col-md-6">
            <perch:input type="text" id="phone_number" required="true" label="Phone Number"  placeholder="Phone number" />
            <perch:error for="phone_number" type="required">Please add your phone number</perch:error>
        </div>
        <div class="col-md-6">
            <perch:input type="text" id="date_of_birth" required="true" label="Date of Birth"  placeholder="Date of birth" />
            <perch:error for="date_of_birth" type="required">Please add your date of birth</perch:error>
        </div>
</div>

We've also added these fields to member.html and customer.html. When filling out the registration form however these are not saved to the database.

We have also added these same fields to the profile.html template for updating the member created by the shop function, and when they are filled in here, they are saved and outputted to the control panel under the individual member.

Therefore we can see that any custom member fields added to the shop registration do not get saved. Is this a bug?

I saw a similar thread here:

http://forum.grabaperch.com/forum/10-20-2016-add-fields-to-customermember

So we can see this may be an issue others are having. If so is it a case of having to create a separate page with a separate submission to save any custom fields? This can work with some fields, but it looks odd with obvious ones like telephone / mobile number that people would expect at the initial registration.

Any clarity on this would be greatly appreciated!

Wayne Hooper

Wayne Hooper 6 points

  • 1 year ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

When filling out the registration form however these are not saved to the database.

What are you seeing happen?

At the moment everything registers just fine except these custom fields. We have no problems with custom fields used purely on the members side, but when used in conjunction with shop functions they just don't seem to save. Are you aware of ways to add custom fields to the shop registration form? (perch_shop_registration_form(); / customer_create.html)

Drew McLellan

Drew McLellan 2638 points
Perch Support

they just don't seem to save

What are you actually seeing? I can't debug this unless you can describe what's happening specifically.

Wayne, perch members will save additional field when you do this through perch_members_form but perch_shop will not save additional fields when a form is submitted using perch_shop_registration_form. The extra fields will be saved to perch_forms app if added to perch_shop forms, but the fields will not be saved on the Customer. I did extensive testing of the last night for another client and the perch_shop app only saves specific fields and drops the rest.

Hi Robert - thanks for your reply - this is what we were afraid of. We want to save a phone number and date of birth, but it looks like we'll have to do this separately to the shop registration form, but we are worried how this could impact the user experience...

Did you manage to find any way around it? We have another developer looking at it, but he cannot see how he can save these fields into the right part of the database without being able to retrieve the member ID on form submission if that makes sense.

Many thanks

Ok. So there is a way to do this, check if member is logged in and if they have a birthdate saved, if not, you can present a form with this info and save it to the member profile.

That’s the simple explanation. I’ve not provided the code as I am working from my phone at the moment and it’s not code friendly.

Duncan Revell

Duncan Revell 78 points
Registered Developer

I've managed to get the Nest demo site working with a custom field on the registration form and saving against the customer record. I'm not sure how to explain it further - I added the field to customer_create.html and to customer.html and it all just worked...

Duncan Revell said:

I've managed to get the Nest demo site working with a custom field on the registration form and saving against the customer record. I'm not sure how to explain it further - I added the field to customer_create.html and to customer.html and it all just worked...

Duncan, I didn't add this to the customer.html in my testing, therefore this may be the magic sauce... as I only added to customer_create.html. I am going to verify this in my test now... thanks

Duncan, your spot on... when added to customer.html and customer_create.html it will save the additional fields, but when only added to customer_create.html it does't add the field.

This is the first time I've seen where a field has to be added to (2) templates in order for adding additional fields. It seems that customer.html is combined with customer_create.html when adding a new customer... and now I am getting out my shovel to dig in and see where and why...

Hats off to Duncan...

I did my homework and here is what I found...

$search_for = ['first_name', 'last_name', 'email', 'taxID', 'taxID_type']; // <<<=== here is where it's searching the submitted form for required fields

$Template   = $this->api->get('Template');
$Template->set('shop/customers/customer.html', 'shop'); // <<<=== then it uses customer.html
$template_ids = $Template->find_all_tag_ids(); // <<<=== and right here, this is where the magic is happening, if the additional field is here, then it will be saved from submitted form

$search_for = array_merge($search_for, $template_ids); // <<<=== because now the fields from both templates are merged...

Thanks Robert - and Duncan!

We will take another look - it's weird because we did place fields in customer.html too, but we were still not getting results.

This is our customer.html template in perch>templates>shop>customers>customer.html:

<perch:shop id="first_name" type="text" label="First name" required="true" />
<perch:shop id="last_name" type="text" label="Last name" required="true" />
<perch:shop id="email" type="email" label="Email" required="true" />
<perch:shop id="phone_number" type="text" label="Phone number" /> // Custom Fields
<perch:shop id="date_of_birth" type="text" label="Date of Birth" /> // Custom Fields

And this is the custom fields within our customer_create.html template:

 <div class="row">
        <div class="col-md-6">
            <perch:input type="text" id="phone_number" required="true" label="Phone Number"  placeholder="Phone number" />
            <perch:error for="phone_number" type="required">Please add your phone number</perch:error>
        </div>
        <div class="col-md-6">
            <perch:input type="text" id="date_of_birth" required="true" label="Date of Birth"  placeholder="Date of birth" />
            <perch:error for="date_of_birth" type="required">Please add your date of birth</perch:error>
        </div>
</div>

We tried registering new customers, but these two new fields are still not outputted under the member, unless we re-enter them through the update profile section.

We've checked the diagnostics for the shop add on and core perch but everything is up to date.

Can you guys see anything I might be doing wrong compared to your code?

Thanks for your help with this!

Wayne, you will have to add them to the member.html and profile.html if you intend these to also be on the member. The above answers only apply to adding to customer. I’ve not tested if Customer creation will pass all fields to member too.

If these fields don’t pass from Customer to member during creation then you may still need my solution of checking a logged in member for this info and if it doesn’t exist then present a form requiring this info.

Something more. If you are expecting to do something with the birth date, your best to use a date field, then also add an error for format otherwise the input will not always be enforced by the browser but perch will double check before accepting and send it back for correction. Save yourself a lot of headache now, as this was a hard lesson I learned a long time ago.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Wayne,

Only the name and email are passed from Shop to Members. The Member app is literally only used as the mechanism to log into into a secure area. Custom fields are only held against the Customer entry and are held in the customer table.

Robert Ketter said:

If these fields don’t pass from Customer to member during creation then you may still need my solution of checking a logged in member for this info and if it doesn’t exist then present a form requiring this info.

Fields on the member are available to all other apps, therefore this is the best solution if you need to store additional fields. Of course you could take this a step further and only check if the member has these fields when they are buying an item which requires this info.

Hi Robert,

Yes - you are right, I've been meaning to swap over the date of birth to a proper date field.

Regarding the custom fields, thank you - I realise we have been missing the whole perch shop customers area hidden away under orders! We were convinced nothing was saving, since we were only looking at what was saving into the members area.

We will reassess the situation now we know this...

Can I also ask in that case, is it possible to update the information saved into perch shop customers in the same way you can for members in the profile area?

It’s best to keep additional fields on the member in my opinion, as there is already authentication in place and all this is available across all apps. Also, tags applied from shop will be applied on the member so it just makes sense to keep all on member rather then Customer.

EDIT: If you need an example I am sure I can provide an example to add more info to the member during checkout.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Wayne,

You can use perch_shop_customer_edit_form()

Robert,

I think I would have to disagree - although as usual it depends on the use case. Wherever Shop is involved, in my mind the members app is just authentication - the customer object becomes “master”. But again, I guess it depends on the goals of the site...

Duncan, how do you access the property once stored on the Customer? Is there a perch_customer_get() like there is in member perch_member_get()?

I’m not picking at anyone here, I am learning at the same time I teach and advise. Always looking for the best solution.