Forum

Thread tagged as: Problem, Members, Shop

Add Billing Address to Existing Members For First-time Customers

I'd like to add billing and shipping address during checkout for logged in members. Been referencing Customers Functions extensively, as well as searching through forum threads without success.

I'm migrating to Perch with an existing bunch of members accessing paid content in our website. Members are not created from Shop. We don't currently store addresses of members.

Members can also purchase products in the website, which is where Perch Shop comes in.

If a member is logged in - without address stored - and goes to Shop to checkout products, using perch_shop_edit_address_form() doesn't redirect to PayPal Express, only displays default success message. It doesn't seem to set perch_shop_addresses_set() to true.

An address record is added to perch2_shop_addresses table, which is not picked up by Orders nor perch_shop_addresses_set().

I understand that Members app is only used for authentication. I don't need to store their addresses, just need to make it possible for them to checkout if they are currently logged in.

My checkout.php:

<?php include(str_replace('/', DIRECTORY_SEPARATOR, '../perch/templates/pages/merchandise.php')); ?>
<h3>Checkout</h3>

<?php
//Step 1: Initiating checkout
    if (perch_member_logged_in()) {

        if (perch_shop_addresses_set()) {
            $return_url = 'https://ttmda-perch.macky/merchandise/payment';
            $cancel_url = 'https://ttmda-perch.macky/merchandise/';

            perch_shop_checkout('paypal-express', [
            'return_url' => $return_url,
            'cancel_url' => $cancel_url,
            ]);
        }
        else {
            perch_shop_edit_address_form();

        }
    }


else {
    perch_shop_registration_form([
        'template' => 'checkout/customer_create_passwordless.html'
    ]);

}
?>


<?php
    PerchUtil::output_debug();
    perch_get_javascript();
    perch_layout('global.footer');
?>

Debug for logged in member in checkout.php:

Debug Message
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='16fdd002a6a990c677efeff38444a29e238b1ec2' AND sessionHttpFootprint='6081f17ac6a81cb9a1e3c3392979c71816ce6ccb' AND sessionExpires>'2017-03-12 00:05:45' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/merchandise/checkout.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=7
[1] SELECT * FROM perch2_shop_customers WHERE memberID=15
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='50' AND orderID IS NULL AND addressSlug='default'
[1] SELECT * FROM perch2_shop_cart WHERE cartID=7
[30] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT * FROM perch2_shop_customers WHERE memberID=15
INSERT INTO perch2_shop_addresses(addressDynamicFields,addressCreated) VALUES('{\"first_name\":\"Bing 2\",\"last_name\":\"Tay\",\"address_1\":\"1 Birdnest St\",\"address_2\":\"\",\"postcode\":\"\",\"city\":\"\",\"county\":\"\",\"country\":\"200\",\"addressID\":\"\",\"s\":\"\\/merchandise\\/addresses\",\"customer\":\"50\",\"title\":\"1 Birdnest St\"}','2017-03-11 16:05:45')
[1] SELECT * FROM perch2_shop_addresses WHERE addressID='39' LIMIT 1
No ids to log.
UPDATE perch2_shop_addresses SET addressDynamicFields='{\"first_name\":\"Bing 2\",\"last_name\":\"Tay\",\"address_1\":\"1 Birdnest St\",\"address_2\":\"\",\"postcode\":\"\",\"city\":\"\",\"county\":\"\",\"country\":\"200\",\"addressID\":\"\",\"s\":\"\\/merchandise\\/addresses\",\"customer\":\"50\",\"title\":\"1 Birdnest St\"}', addressCreated='2017-03-11 16:05:45', addressTitle='1 Birdnest St', addressSlug='1-birdnest-st', addressFirstName='Bing 2', addressLastName='Tay', addressLine1='1 Birdnest St', customerID='50', countryID='200', addressUpdated='2017-03-12 00:05:45' WHERE addressID='39'
No ids to log.
[6] 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='/merchandise/checkout.php' LIMIT 1
[2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-007-004', '000-007', '000') ORDER BY pageTreePosition DESC
[6] Using template: /templates/navigation/item.html
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=7
[250] SELECT country, countryID FROM perch2_shop_countries ORDER BY country ASC
Using template: /templates/shop/addresses/edit.html
[1] SELECT * FROM perch2_shop_customers WHERE memberID=15
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='50' AND addressID=0

Diagnostics:

SUMMARY INFORMATION

Perch: 2.8.34, PHP: 5.6.27, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34), perch_forms (1.8.3), perch_gallery (2.8.6), perch_shop_orders (1.0.12), perch_shop_products (1.0.12), perch_shop (1.0.12), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_gallery', 'perch_members', 'perch_shop', ); ?>
PERCH_LOGINPATH: /perch
PERCH_PATH: /Applications/MAMP/htdocs/ttmda-perch/perch
PERCH_CORE: /Applications/MAMP/htdocs/ttmda-perch/perch/core
PERCH_RESFILEPATH: /Applications/MAMP/htdocs/ttmda-perch/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 6a33f95eca3667f9e0c39bf5ca2980fe
Resource folder writeable: Yes
HTTP_HOST: ttmda-perch.macky
DOCUMENT_ROOT: /Applications/MAMP/htdocs/ttmda-perch
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Been also searching through forum threads with similar issues but no luck. Any pointers will be greatly appreciated.

Yan Ping Tay

Yan Ping Tay 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_shop_addresses_set() is checking if one of the customer's addresses as been chosen for this particular order.

The address gets set when the customer signs up (if they're a new customer) or if they pick an address from their stored addresses with a form (for returning customers).

I'll see if I can figure out how it should be done in your scenario.

Thanks Drew, appreciate that.

I'd tried an alternative (which doesn't work) - to silently log out the member and use customer_create_passwordless.html for everyone. Of course, it doesn't work since a duplicate member will be added, hence checkout.php will pull the first match for customerEmail which doesn't have any addresses associated.

Hi Drew, any luck?