Forum

Thread tagged as: Question, Shop

Shop Customer Information

Hi,

After a customer has registered, I would like to access their details as an array using skip-template. I am not sure how to get at this information - I need email, first name, last name and both the shipping and billing addresses.

What I am trying to do is pre-populate the customer_create_passwordless form for if the customer wants to change their details after logging in.

Mike Harrison

Mike Harrison 37 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That form is for creating a customer, so you don't want to use it for a logged in user at all.

You should be able to use the standard edit form.

Ah ok - so I would just use

perch_shop_registration_form([
          'template' => 'checkout/customer_update.html'
        ]);

Still I would like to populate this with their data if possible. If they just wanted to change the delivery address country for example I don't want them to have to re-input all their other information. Is this possible?

Actually that perch_shop_registration_form doesn't seem to be right for the update form, it is not updating. Do I need something different there?

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_shop_customer_edit_form() should be good for editing the customer.

perch_shop_edit_address_form() can be used for editing a specific address.

Hi Drew,

I have tried perch_shop_customer_edit_form() using the standard template. When I make changes and hit Update I get a thanks message, but the details are not updated - when I go to select delivery options (which is on a separate page), the address and details have not changed from what was originally entered.

I am using passwordless checkout if that makes any odds?

This looks like the pertinent part of the debug message:

PDATE clocks_members SET memberProperties='{\"first_name\":\"cytvuybino\",\"last_name\":\"Person\",\"token\":\"d9f67c0722e5550aef09ebdc0ff23f4969b6d4bc\"}' WHERE memberID='1030'
1.0653  0.0048  No ids to log.
1.0655  0.0002  [0] SELECT t.tag FROM clocks_members_tags t, clocks_members_member_tags mt WHERE t.tagID=mt.tagID AND mt.memberID='1030' AND (mt.tagExpires IS NULL OR mt.tagExpires>'2016-06-07 07:52:00')
1.066   0.0004  INSERT INTO clocks_members_sessions(sessionID,sessionExpires,sessionHttpFootprint,memberID,sessionData) VALUES('0b8c8116276eb47ca747f7a22d54de2bb42cff0f','2016-06-12 07:52:39','b20ea6e704c8fa49b201030a761b57ed6b54b783','1030','{\"first_name\":\"cytvuybino\",\"last_name\":\"Person\",\"token\":\"d1d495e9ef871ffd6d302a65594eebf333c4bc35\",\"memberID\":\"1030\",\"memberAuthType\":\"native\",\"memberAuthID\":\"1030\",\"memberEmail\":\"mike@newgateclocks.com\",\"memberPassword\":null,\"memberStatus\":\"active\",\"memberCreated\":\"2016-06-07 07:47:37\",\"memberExpires\":null,\"tags\":[]}')
1.0665  0.0006  DELETE FROM clocks_members_sessions WHERE sessionExpires < '2016-06-07 07:52:39'
1.0667  0.0002  DELETE FROM clocks_members_sessions WHERE sessionID='9cdcd7b1a105cc71c5f71da42e2aea60d588061c'
1.0672  0.0004  [1] SELECT * FROM clocks_members_sessions WHERE sessionID='0b8c8116276eb47ca747f7a22d54de2bb42cff0f' AND sessionHttpFootprint='b20ea6e704c8fa49b201030a761b57ed6b54b783' AND sessionExpires>'2016-06-07 07:52:39' LIMIT 1
1.0675  0.0003  User is logged in
1.0675  0.0001  
1.0886  0.0211  [1] SELECT * FROM clocks_shop_customers WHERE customerEmail='mike@newgateclocks.com' AND customerDeleted IS NULL LIMIT 1
1.0897  0.0011  UPDATE clocks_shop_customers SET customerDynamicFields='{\"first_name\":\"cytvuybino\",\"last_name\":\"Person\",\"email\":\"mike@newgateclocks.com\",\"company\":\"erdtyf\",\"address_1\":\"Address 1\",\"address_2\":\"Address 2\",\"postcode\":\"SY2 5HA\",\"city\":\"Shrewsbury\",\"county\":\"Shropshire\",\"country\":\"236\",\"shipping_first_name\":\"uyvbiubuyv\",\"shipping_last_name\":\"Person\",\"shipping_company\":\"uybuyhhy\",\"shipping_address_2\":\"Address 2\",\"shipping_postcode\":\"SY2 5HA\",\"shipping_city\":\"Shrewsbury\",\"shipping_county\":\"Shropshire\",\"shipping_country\":\"236\"}', customerFirstName='cytvuybino', customerLastName='Person', customerEmail='mike@newgateclocks.com', customerUpdated='2016-06-07 07:52:39' WHERE customerID='845'
1.09    0.0003  No ids to log.

These values are the new ones I have entered, so it is doing something, but the changes are not persisting beyond that page.

Update - the customer details are changing but the address details are not, using that standard form.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us what you're doing?

I am trying to replicate a Shopify-esque checkout process, to prove that Perch can provide the same functionality. These are the wireframe design layouts:

Cart Stage 1

Checkout Stage 2

Delivery Options Stage 3

Payment Stage 4

At the moment when people return to the checkout page they are logged out, to facilitate them using the customer_create_passwordless form again to make any changes. This isn't ideal, so I am checking whether they are logged in, and if so to show the perch_shop_customer_edit_form instead

If you look at the checkout process here:

A Fine Pair Of Shoes

That is the process I am tasked with emulating with Shop, with the same ease of switching back through steps and making changes. As you suggested previously I think I will need to use pushState and other fanciness to achieve it, but I would really like to get it working as I am being pushed to switch over to Shopify which I don't want (they never sent me any stickers!)

Drew McLellan

Drew McLellan 2638 points
Perch Support

I meant are you able to show us the code you're using to invoke the form that isn't doing what you want it to do?

Ah ok. This is my page:

<?php

            // Include the head. You can find this in tempates/layouts/global
            perch_layout('global/head-default-meta', [
                'title' => 'Your Details | Newgate Clocks',
                'body-class' => 'checkout'
            ]);

           perch_layout('global/cart');

            // Include the header. You can find this in tempates/layouts/global
            perch_layout('global/header');

                // Main navigation
            perch_pages_navigation([
                'levels'=>2,
                'template'=>['dropdown-refill-level1.html', 'dropdown-refill-level2.html']
            ]);

                ?>
            <div class="container">
           <h2 class="pageheader">
            <?php perch_pages_title(); ?>
        </h2>
        </div>

        <div class="container">

            <?php

            if (!perch_member_logged_in()) {

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

        }

        else {

          perch_shop_customer_edit_form();

        }

        $cartdetails = perch_shop_cart([
            'skip-template' => 'true'
        ]);

        $totalitems                 = $cartdetails['total_items_discounted'];
        $totalitemstax            = $cartdetails['total_items_tax'];
        $currencysymbol           = $cartdetails['currency_symbol'];

        $totalexshipping          = number_format(($totalitems + $totalitemstax), 2);

        $totalexshippingformatted = $currencysymbol.$totalexshipping;

        PerchSystem::set_vars(array(
            'total_items_discounted_with_tax'=> $totalexshipping,
            'total_items_discounted_with_tax_formatted'=> $totalexshippingformatted
        ));

          perch_shop_cart([
            'template' => 'cart/cart-small'
          ]);
    ?>

    </div>

    <?php

    // Include the footer. You can find this in tempates/layouts/global
    perch_layout('global/footer');
Drew McLellan

Drew McLellan 2638 points
Perch Support

And it's this part that isn't working?

perch_shop_customer_edit_form()