Forum

Thread tagged as: Question, Problem, Shop

Shop Addresses Add Edit and Delete

Hi I am trying to allow members to add a new addresses for say different branches (This is a trade only shop) and want them to be able to set a title e.g. Bristol Branch.
I am using an id of title which works and changes in my address list if i use the standard edit form from perch_shop_customer_addresses(); but this is only good for editing later. I want to take them to an add address page using perch_shop_form('addresses/add.html');.
but what it seems to do by default is use the first line of address as the id title and id addressTitle. I think it may be to do with this

    <perch:input type="submit" value="Update" class="btn btn-primary" />
    <perch:input type="hidden" id="addressID" />
    <perch:input type="hidden" id="r" value="/shop/addresses" />

but I'm unsure what to put instead. This is off the standard edit form and I am using it in my add address form. Also I would like an option to delete an address.

William Chicken

William Chicken 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You could be conflicting with our internal address titles. Can you use a different ID for your title?

Yep, just checked and that works ) Something else I couldn't figure out was why/how when a customer who already has a member account but is only going through the checkout for the first time has no addresses listed but on return has two listed. One with the default title and one with the shipping title.
These addresses are taken from the member account so will be added to the first order which is ok but it would be better if they were there to edit or chose from beforehand.
I believe it's because I'm attempting to work things backwards slightly due to already having signed up customers as opposed to new shop customers. So is there a way of triggering this behaviour maybe with a shop setup option of sorts so they will appear when the customer goes through checkout for the first time?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Unless I'm missing something, that's completely within your control. You can present the user with the option to add an address at almost any point.

Ok, Is there a way to access the member address that the client has already signed up with to fill out the shop address billing form automatically?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Was that not your complaint, that that was happening and you didn't want it?

Not quite. Sorry if I'm not explaining well, it's tricky. There are 3 issues in this thread - Address Titles, Members v Shop Addresses and Delete Address Option.

The first time through the cart it doesn't show the address the member registered with. It seems to need to go through once for these to be automatically created. So case scenario -
Customer adds their main (sign up) address for the first delivery and names it Main.
The next time they go in there are now 3 addresses the same. One with a title of Main, one with a title of Default and with a title of Shipping. They now have 3 of the same address to choose from but can't delete any of these. Clutter and confusion is the main issue here.
But if I put in the standard form to add shipping and billing addresses for the first time though the checkout. They will have to enter both manually even though the address is already on the system, but in the members db not the shop. I just want to make it more streamlined for the customer.
I hope that explains it better )

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which version of Shop are you using?

I updated this morning.
I've been trying out different solutions and I have an issue with my add address template. Fixing this may help with one solution. I'm using the same form as the edit address one but it doesn't quite act the same.
The first thing is the country select box. It just has a tick in it.
The second is the addressTitle id. I changed it like you suggested but it doesn't talk to the order address form. So my title gets ignored. Using the id of title works but only from the edit form. The add form doesn't work the same.
Could you suggest some changes.
Add-address.html

<perch:form id="address" method="post" app="perch_shop">

    <fieldset>
        <legend>Address</legend>
            <div>
            <perch:label for="title">Address Title</perch:label>
            <perch:input type="text" id="title" required="true" label="Address title" placeholder="eg.Branch Name"/>
            <perch:error for="title" type="required">Please add a Title</perch:error>
        </div>

        <div>
            <perch:label for="first_name">First name</perch:label>
            <perch:input type="text" id="first_name" required="true" label="First name" />
            <perch:error for="first_name" type="required">Please add a name</perch:error>
        </div>

        <div>
            <perch:label for="last_name">Last name</perch:label>
            <perch:input type="text" id="last_name" required="true" label="Last name" />
            <perch:error for="last_name" type="required">Please add a name</perch:error>
        </div>

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

        <div>
            <perch:label for="address_1">Address 1</perch:label>
            <perch:input type="text" id="address_1" required="true" label="Address 1" />
            <perch:error for="address_1" type="required">Please add the first line of the address</perch:error>
        </div>

        <div>
            <perch:label for="address_2">Address 2</perch:label>
            <perch:input type="text" id="address_2" label="Address 2" />
        </div>

        <div>
            <perch:label for="postcode">Postal code</perch:label>
            <perch:input type="text" id="postcode" label="Postal code" />
        </div>

        <div>
            <perch:label for="city">City</perch:label>
            <perch:input type="text" id="city" label="City" />
        </div>

        <div>
            <perch:label for="county">State or County</perch:label>
            <perch:input type="text" id="county" label="County" />
        </div>

        <div>
            <perch:label for="country">Country</perch:label>
            <perch:input type="select" options="<perch:shop id="country_list" />" value="GB" id="country" label="Country" />
        </div>

    </fieldset>

        <div>
            <perch:input type="submit" value="Update" class="btn btn-primary" />
            <perch:input type="hidden" id="addressID" />
            <perch:input type="hidden" id="r" value="/shop/addresses" />
        </div>

    <perch:success>
        <p>Thanks!</p>
        <p><a href="/shop/confirm">Back to order</a></p>
    </perch:success>

</perch:form>
<!-- <perch:showall/> -->

I am calling it with..

<?php perch_shop_form('addresses/add.html'); ?>

Where as the edit address is called with...

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

Just an aside if I take them to shop/address/some-random-number. It show the edit form and works well for creating new addresses. ?

I've just realised I can just use <?php perch_shop_edit_address_form(); ?> to add addresses as well as edit them so this kind of solves my problem. Also maybe I'm being overly picky about the titles as first line will always be different and will allow them to differentiate between them. It still would be good to be able to let customers delete additional addresses though if this is possible.

I've totally solved the issues I was having by taking it all apart and starting again.

When I initially set up my member registration form I didn't get my default tag to work first time ( The default tag or type="default" makes it so customers will have to wait to be accepted - status pending). Because of this I submitted the form again before realising I should have edited the form by clicking on the link and saving it.
I now had two forms listed which was giving me two addresses the same but stopping them from showing up on first pass through the checkout, probably due to the conflict.

Anyway, I can now use my original register form, my add address form and edit form as you planned for us.
Thank you for your time, I can see now why you were confused with my issue.

It's not getting addresses again for new sign ups for whatever reason. Maybe I thought I'd fixed it but didn't delete an entry from the database. Any way here is my debug.

\Debug Message
[32] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
Matched page: /shop/confirm, so not using routes.
Using master page: /templates/pages/confirm.php
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='25da997df9e268eae711eb1319b7ccc75e75571e' AND sessionHttpFootprint='1d17425e9d1cd11d5d857bd3d1b870de6e97430c' AND sessionExpires>'2016-08-18 00:36:07' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/shop/confirm' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=186
[1] SELECT * FROM perch2_shop_cart WHERE cartID=186
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
Using template: /templates/search/search-form.html
[3] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/shop/confirm' LIMIT 1
[2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-004-007', '000-004', '000') ORDER BY pageTreePosition DESC
[3] Using template: /templates/navigation/head_item.html
Using cart from cache.
[28] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/shop/cart/cart_static.html
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=186
[1] SELECT * FROM perch2_shop_customers WHERE memberID=70
[nil] SELECT * FROM perch2_shop_addresses WHERE customerID='8' AND orderID IS NULL
Using template: /templates/shop/checkout/order_address_form.html
Using template: /templates/shop/checkout/confirm.html
[2] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/shop/confirm' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT groupID FROM perch2_navigation WHERE groupSlug='Footer' LIMIT 1
[2] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=3 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
[0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=3 AND p.pagePath='/shop/confirm' LIMIT 1
[2] Using template: /templates/navigation/footlinks.html
Request time: 0.1814
Process time: 0.1798
Memory: 3.9494

This is what happens first time through the checkout. I want it to display an address as the member is already logged in.

I also have this
[18-Aug-2016 10:35:50 Europe/Berlin] PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Applications/MAMP/bin/mamp/feed/fetchFeed.php on line 20 [18-Aug-2016 10:35:50 Europe/Berlin] PHP Warning: file_get_contents(https://www.mamp.info/feed/mac/MAMP/English/feed/home.json): failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Applications/MAMP/bin/mamp/feed/fetchFeed.php on line 20

Drew McLellan

Drew McLellan 2638 points
Perch Support

What is feed/fetchFeed.php? I don't think that's anything to do with Perch.