Forum

Thread tagged as: Problem, Runway, Shop

Perch Shop - Registration page not redirecting to checkout on live site

HI,

I have been working on developing a shop installation on a client site (local XAMPP installation) and little by little, it is all coming together and I finally have some form of working site with roughly the feature set I require.

However, uploading all the files and DB to the live server I have come across a few issues. Most of which I have managed to work around but for some reason if I try to purchase an item, I get redirected to the registration page, but then, upon completion of the registration, the page does not redirect back to the checkout page.

Initially, I jumped at the notion that it must be to do with differences in the 'server' set-up, but given my workflow, I do not believe this is the case.

Currently, the user selects a product and is sent to the cart page. From here they select 'checkout' and this happily redirects the non-logged in user to the registration page:

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

Once the registration form is filled out, submission should redirect the user back to the checkout page using:

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

as the user will now be registered and logged in.

On submission, I can see that a new member has been created, but a blank registration page is returned.

No Debug messages are shown, just a plain html page.

If I add:

if (perch_member_logged_in()) {
        echo 'IS THIS TRIGGERED';
    PerchSystem::redirect('/shop/checkout');
}

I will see the message, meaning that the if statement is being fired.

I suppose the other point is, if it was a server issue, why would one redirect work and the other not.

All very odd.

My diagnostic report is as below:


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

Thanks

Andrew Kennedy

Andrew Kennedy 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

echo 'IS THIS TRIGGERED'; 
PerchSystem::redirect('/shop/checkout');

If you think about the fundamentals of what you're doing with HTTP here, it should be clear that this will never work. A redirect uses an HTTP Location header and a 30x status code. If you echo anything to the page, you're going to start the response body, which will be necessity end the response header section and so any headers you try to set after that point will be invalid.

If you're going to redirect, you need to do that before you send any response body to the browser.

Forget the echo part, that was just purely me trying something to see if the if statement was working, but yes, this will never work.

Redirect does not work though irrespective of this.

Any ideas why the solution will redirect from checkout to registration, but not vice-versa.

Have reverted to using the NEST templates and installed these on the live server. Everything is ok (so the redirect issue must be to do with my personalised templates ??), but it fails at the 'Pay Now' stage.

DEBUG throws up this:

Array
(
    [type] => 2
    [message] => array_merge(): Argument #1 is not an array
    [file] => /home/auk/public_html/admin/addons/apps/perch_shop/lib/PerchShop_Cart.class.php
    [line] => 494
)

Still a little worried why everything will work locally, but not on the server. Doesn't make for a great development environment, but I presume this could be stricter rules on the server ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the difference between your two environments?

Hi Drew,

My XAMPP set-up is:

Server: 127.0.0.1 via TCP/IP
Server type: MariaDB
Server version: 10.1.10-MariaDB - mariadb.org binary distribution
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.4
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: f59eb767fe17a6679589b5c076d9fa88d3d4eac0 $
PHP extension: mysqli Documentation
PHP version: 7.0.4

Live Server:

Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.6.35 - MySQL Community Server (GPL)
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
cpsrvd 11.64.0.29
Database client version: libmysql - 5.1.73
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 5.6.30

Let me know what other information might be useful.

I've been playing around a bit.

Removing the line

 perch_shop_form('checkout/confirm.html');

from checkout.php removes the Array error as mentioned earlier.

So this leads me to think that within confirm.html, either 'cart-property' is not being sent back, or that the 'Pay Now' button is not triggereing.

Comment removed as talking rubbish !

Definately an issue with the confirm.html template, just not sure why.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, let us know when you have more information.

Still testing, but as soon as confirm.html is contained within checkout.php, the previous error appears.

Array
(
    [type] => 2
    [message] => array_merge(): Argument #1 is not an array
    [file] => /home/auk/public_html/admin/addons/apps/perch_shop/lib/PerchShop_Cart.class.php
    [line] => 494
)

Evidently,

if (perch_shop_cart_has_property('terms_agreed')) {

is not being triggered.

Tried changing the name of the property and a few other elements, but the checkout.php still gives the above error and as such does not progress.

My checkout.php template is:

<?php

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

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

    perch_shop_cart([
        'template'=>'cart/cart_static.html'
    ]);

    perch_shop_form('checkout/confirm.html');

Ok, I've cracked it and here is the solution for anybody else who finds themselves in this postion.

I have no idea WHY this is working, especially as my local version of Runway / Shop app work fine, but rearranging the checkout template has resolved the issue. I guess the DEBUG error was just one of those classic cases of not really telling me anything useful.

After much fiddling and removal / moving and rearranging of the code, this checkout.php file works for me:

<?php

if (!perch_member_logged_in()) {
    PerchSystem::redirect('/shop/register');
} else {
    if (perch_shop_cart_has_property('terms')) {
        perch_shop_checkout('manual', [
            'return_url' => '/shop/result',
            'cancel_url' => '/shop/',
        ]);
    }
}

perch_shop_cart([
        'template'=>'cart/cart_static.html'
]);

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

Hopefully this will be of use to others.