Forum

Thread tagged as: Problem, Runway, Shop

Shop address edited changes not being saved

Hi,

I am having trouble understanding and getting a customer address to be editable via the profile element of my site.

I am using the shop app and after much trial and error I am trying to get back to basics and follow:

https://docs.grabaperch.com/addons/shop/examples/managing-addresses/

So, from my profile.php page, I am calling my address template:

perch_shop_customer_addresses([
    'template' => 'addresses/address_profile'
]);

The address template is:

<perch:before>
<table class="table table-bordered">
</perch:before>
<tr>
    <th>
        <perch:shop id="addressFirstName" /> <perch:shop id="addressLastName" />
        <perch:if exists="addressCompany"><br /><perch:shop id="addressCompany" /></perch:if>
    </th>
    <td>
        <perch:if exists="address_1">

        <div>
            <perch:label for="address_1">Address 1*</perch:label>
            <perch:input type="text" id="address_1" required="true" label="Address 1" value="<perch:shop id="address_1" />" />
            <perch:error for="address_1" type="required"><span class="error">Please add the first line of your address</span></perch:error>
        </div>
        </perch:if>

        <perch:if exists="address_2"><perch:shop id="address_2" /><br /></perch:if>
        <perch:if exists="city"><perch:shop id="city" /> <br /></perch:if>
        <perch:if exists="county"><perch:shop id="county" /> <br /></perch:if>
        <perch:if exists="postcode"><perch:shop id="postcode" /> <br /></perch:if>
        <perch:if exists="country_name"><perch:shop id="country_name" /></perch:if>
    </td>
    <td>
        <a href="/shop/addresses/<perch:shop id="addressID" />/">Edit</a>
    </td>
</tr>
<perch:after>
</table>
</perch:after>

Now viewing my profile page as a logged in member, this does display the table and an edit button.

I have created a new page 'address_edit' page within the shop, with a location of /shop/address-edit and then a route of shop/addresses/[i:addressID]

The address_edit page contains:

<?php
    perch_shop_edit_address_form(perch_get('addressID'));
    ?>

At the moment, from the profile.php I can click on the link from the rendered table (address template) and this will bring me to an edit page, which then displays the edit.html template from shop/addresses folder.

However, as soon as I change details and update (submit), the details, whilst changed on screen, are not being changed within the DB. So as soon as I return to the profile page, no details have been updated.

On a further note, the above is nowhere near where I ideally want to get to, but I am trying to be logical about one step at a time.

Surely it is possible to build a 'single' profile page that picks data from multiple sources (member details and member addresses etc etc) and can save them to the correct places from a 'single' form, i.e. the profile page has a single submit button and any changed detail on the page would be submitted to either the correct members table or the addresses table.

Any help in pointing me in the correct direction is appreciated.

FYI, there are no DEBUG errors.

Here is the diagnostics:


Perch Runway: 3.0.8, PHP: 5.6.30, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_blog (5.5.1), perch_events (1.9.5), perch_forms (1.9), perch_shop_orders (1.2.2), perch_shop_products (1.2.2), perch_shop (1.2.2), perch_members (1.6.2), perch_twitter (3.7) App runtimes: <?php $apps_list = [ 'perch_blog', 'perch_twitter', 'perch_events', 'perch_forms', 'perch_members', 'perch_shop', ]; PERCH_LOGINPATH: /admin PERCH_PATH: /home/auk/public_html/admin PERCH_CORE: /home/auk/public_html/admin/core PERCH_RESFILEPATH: /home/auk/public_html/admin/resources Image manipulation: GD Imagick PHP limits: Max upload 12M, Max POST 12M, Memory: 64M, Total max file upload: 12M F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7 Resource folder writeable: Yes DOCUMENT_ROOT: /home/auk/public_html HTTP_HOST: anticoagulationuk.org REQUEST_URI: /admin/core/settings/diagnostics/ SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
Andrew Kennedy

Andrew Kennedy 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

FYI, there are no DEBUG errors.

What debug output do you get after submitting the form?

Hi Drew,

This morning I had another go at things. I'm not sure why, but I stepped back even further and took my templates back to original and hey-presto , it worked !!!

I have no idea why MY template didn't work, but it seems that some small anomoly has tripped it up. So sorry, for wasting your time, especially as I was getting so frustrated with it and just couldn't understand why it was not working.

Ok, after further testing, it seems that the edit file will trip up if I comment out first_name, last_name and I think the IMPORTANT one company from the edit.html file.

This will then not trigger the perch:success message.

Yes, if company is not included in the edit.html template then it fails.

Ok, that's fine, I know to leave it in and hide it if needs be.

Just one quick question though. During the whole sign-up member/shop process I have customer_create which allows member details and address to be saved. The firstname is used to set-up a member etc, but also this is saved against the address.

So now, when I am editing my profile, I want to use profile.html to drive and change any details with the members name as this makes sense, but these changes should also be pushed/sent to the address first_name, last_name as well, as otherwise, if I do not hide the input boxes on the edit.html template they can potentially enter two different names.

Hope the above makes sense.

Potentially, you see, we can have an edited name for the member profile and yet when they purchase goods, they can have a different name agains the billing and shipping address, which doesn't make sense. Surely your membership name should drive or be driven by the first_name last_name which was entered in at membership creation, which at that point MUST have initially been submitted to the billing and/or shipping address tables.

Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you commenting the inputs out?

I was just literally using:

<!--<div>
    <perch:label for="company">Company</perch:label>
    <perch:input type="text" id="company" label="Company" />
</div>-->

Works fine for first_name, last_name, but not for the above.

Any ideas how I can submit say first_name and last_name from the profile.html template into both the members app and the shop app, as having repetition/replication of this data will lead to confusion.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That will output HTML comments but won't remove the item from the template.

You need to use template comments if you want to comment out a template item.

<!--*    *-->

Ok, so that explains why it failed.

Any ideas how I can submit say first_name and last_name from the profile.html template into both the members app and the shop app, as having repetition/replication of this data will lead to confusion.

Thanks