Forum

Thread tagged as: Shop

Perch Shop, having trouble advancing beyond the register customer screen...

Following the flow in the running demo, I have a checkout button on the cart page that advances to checkout which looks like this:

<?php   include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');?>
<?php

    if (!perch_member_logged_in()) {
        PerchSystem::redirect('/register');
    }

    if (perch_shop_cart_has_property('terms_agreed')) {
        perch_shop_checkout('manual', [
            'return_url' => '/shop/result',
            'cancel_url' => '/shop',
            ]);
    }

    perch_layout('global.head', array(
            'title'           => perch_page_title(true),
            'section_heading' => 'shop',
        ));
        perch_layout('global.headwer');
?>
        <!-- Page Title
        ============================================= -->
        <section id="page-title">

            <div class="container clearfix">
                <h1>Checkout</h1>
                <ol class="breadcrumb">
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Shop</a></li>
                    <li class="active">Checkout</li>
                </ol>
            </div>

        </section><!-- #page-title end -->

        <!-- Content
        ============================================= -->
        <section id="content">

            <div class="content-wrap">

                <div class="container clearfix">

                    <div class="row clearfix">

<?php       


    // Show the cart with a non-interactive template
    perch_shop_cart([
        'template'=>'cart/cart_static.html'
    ]);

    // Show the order addresses
    perch_shop_order_addresses();

    // Display the form with the T&Cs checkbox
    perch_shop_form('checkout/confirm.html');

?>

                </div>

            </div>

        </section><!-- #content end -->

<?php perch_layout('global.footer'); ?>
    </div><!-- #wrapper end -->

    <!-- Go To Top
    ============================================= -->
    <div id="gotoTop" class="icon-angle-up"></div>

<?php perch_layout('global.footer.scripts'); ?>
</body>
</html>

Without being logged in, it correctly goes to /register:

<?php   include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');?>
<?php

    if (perch_member_logged_in()) {
        PerchSystem::redirect('/checkout');
    }

    perch_layout('global.head', array(
            'title'           => perch_page_title(true),
            'section_heading' => 'shop',
        ));
    perch_layout('global.header');
?>
        <!-- Page Title
        ============================================= -->
        <section id="page-title">

            <div class="container clearfix">
                <h1>Checkout</h1>
                <ol class="breadcrumb">
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Shop</a></li>
                    <li class="active">Checkout</li>
                </ol>
            </div>

        </section><!-- #page-title end -->

        <!-- Content
        ============================================= -->
        <section id="content">

            <div class="content-wrap">

                <div class="container clearfix">

                    <div class="row clearfix">

<?php
    PerchSystem::set_var('shipping_weight', perch_shop_get_shipping_weight());
    perch_shop_registration_form(); 

?>


                    </div>
                </div>

            </div>

        </section><!-- #content end -->

<?php perch_layout('global.footer'); ?>
    </div><!-- #wrapper end -->

    <!-- Go To Top
    ============================================= -->
    <div id="gotoTop" class="icon-angle-up"></div>

<?php perch_layout('global.footer.scripts'); ?>
</body>
</html>

which displays the customer create form which contains the same fields and continue button as in the demo...

But upon submitting the form with the billing shipping addresses, the form does not advance to /checkout...

and I'm stuck on that page with just the form's success message...

What is supposed to move the user forward to the next screen?

Monty Lewis

Monty Lewis 2 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

That's really up to you, what were you expecting to happen based on your code?

So I'm using nest running demo as a guide... and when I enter my billing and shipping address into the /shop/register page on the nest running demo site, it advances me to /shop/checkout...

I'm trying to understand where in the code that is happening as I think I'm using the same code and it does not advance for me on my work site (https://stopherethisistheplace.com/shop). I'm a little weak on my understanding of where members and customers overlap... By looking at the code, I think it's designed to present the create_customer form if the visitor is not a member... Then when the form is filled, the member/customer is created, the code at the top of register:

    if (perch_member_logged_in()) {
        PerchSystem::redirect('/checkout');
    }

would get re-assessed and push onto the checkout page...

I think I’m wrong? If so, I don't know what causes the progression to /checkout from register...

Thanks for your help, I'm a copy-paster learner...

-- Monty

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, that's right. Once a customer registers or logs in, then that code would redirect them.

Shoot. So do you have any thoughts as to what could be wrong?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You would need to debug as normal, find out at which point the code isn't doing what you expect.If you echo something out to the page at various points in the code you can see where it is getting to, also Perch Debug will give you information as to which queries are being run and what Perch is doing internally.

ok, thanks. So it is that statement above that is getting reassessed when the form is submitted that would advance the page to /checkout, right?

I do see that the member record is being created and the new users status is active...

Rachel Andrew

Rachel Andrew 394 points
Perch Support

that statement is a PHP redirect. It will redirect to wherever you want it to. You then need to make sure that page is there, correct and won't bounce them somewhere else.

In addition to Rachel's comments have a look at the logs on your server, I've lost count of the times I've stared at blank/ wrong screens wondering what went wrong only to finally open the logs and see "PHP Error........." with some reasonably understandable message.

Are you sure that the redirect is being hit? Try changing

if (perch_member_logged_in()) {
        PerchSystem::redirect('/checkout');
    }

to

echo ('Before logged in check');
if (perch_member_logged_in()) {

       echo ('Before redirect');
        PerchSystem::redirect('/checkout');
}
echo ('After logged in check');

Which of those messages do you see in your page? It may at least give you the route being taken through the code

Thank you Kim and Rachel, ok, so adding that, the first time it shows

Before logged in check

then when the form is submitted,

Before logged in checkAfter logged in check

So I tried to load /checkout manually and it forwarded me back to /register!

I guess because of this in register.php:

    if (!perch_member_logged_in()) {
        PerchSystem::redirect('/register');
    }

So I'm not getting logged in when I complete the customer_create form?

If that's correct, am I missing something that would log in the customer wnen they fill out customer_create?

Thank you!

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's worth noting that if you echo anything before the redirect, the redirect won't happen.

However, on the following page you should be logged in and not bounced back.

Do you have any evidence that member login is working for you?

Yes, members app is creating a record from the customer_create form...

and I am able to use the members app to log in, etc...

Is there anything explicit I need to do to log the customer in that I'm missing?

Drew McLellan

Drew McLellan 2638 points
Perch Support

There shouldn't be, no.

Have you turned on debug? What does it output at the point of creating the customer?

Ah...

On register.php I get:

SELECT * FROM perch2_pages WHERE pagePath='/register.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=47
[1] SELECT * FROM perch2_shop_cart WHERE cartID=47
[36] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[0] SELECT COUNT(*) FROM perch2_members WHERE memberPassword IS NOT NULL AND memberEmail='mlewis@lewisarts.com'
[0] SELECT COUNT(*) FROM perch2_members WHERE memberPassword IS NOT NULL AND memberEmail='mlewis@lewisarts.com'
[1] SELECT * FROM perch2_members_forms WHERE formKey='register.shop' LIMIT 1
INSERT INTO perch2_members(memberAuthType,memberEmail,memberPassword,memberStatus,memberCreated,memberProperties) VALUES('native','mlewis@lewisarts.com','$P$Bz/M8ls9toVI/eNFFkQae7Kr6N0cEQ0','pending','2016-04-20 17:23:50','{\"first_name\":\"Montgomery\",\"last_name\":\"Lewis\"}')
[1] SELECT * FROM perch2_members WHERE memberID='22' LIMIT 1
No ids to log.
UPDATE perch2_members SET memberAuthID='22', memberStatus='active' WHERE memberID='22'
No ids to log.
Email or password not sent.
Array
(
)
Template file not found: /home/stophere/stopherethisistheplace.com/perchlogin/login_form.html
------------------------------ here mem ------------------------------
Array
(
    [all] => login
)
[6] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/register.php' LIMIT 1
[1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-007', '000') ORDER BY pageTreePosition DESC
[2] Using template: /templates/navigation/navigation-main.html
Using cart from cache.
[1] Using template: /templates/shop/cart/mini.html
[248] SELECT country, countryID FROM perch2_shop_countries ORDER BY country ASC
Using template: /templates/shop/checkout/customer_create.html

Tried to track down that weird missing template but I can't figure out where that's coming from...

/home/stophere/stopherethisistheplace.com/perchlogin/login_form.html

Is that trying to refer to:

/perch/templates/members/login/login_form.html

I was missing:

        <perch:input type="hidden" id="password" value="__auto__" />

from my customer_create.html.

Ouch.