Redirect dependant on previous page

Hi there, been driving myself mad trying to create a redirect dependant on the last page visited by the viewer.

I am trying to design part of a multistage checkout process. Once a customer had added their product in a product page I would like them to be redirected to the next stage of the process.

This is what I have so far - keeps jumping through stage one into stage 2 regardless of wether view has looked at product page or not.

SITE:

import {memory} from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;

let previousPageURL;

$w.onReady( function () {
previousPageURL = memory.getItem( “page” );
memory.setItem( “page” , wixLocation.url);
});

PAGE:

import wixLocation from ‘wix-location’ ;
import wixWindow from ‘wix-window’ ;

$w.onReady( function () {
let previousPageURL;
if (wixWindow.referrer !== “/product-page/1-page-website” ) {
wixLocation.to( “/copy-of-stage-1-1” );
}
}) ;

This is what I have so far - keeps jumping through stage one into stage 2 regardless of whether view has looked at the product page or not.not.

Hi There!

I’ve had troubles with the wixWindow.referrer too. So I recommend trying to use this code instead on your page:

import wixLocation from 'wix-location'; 
import wixWindow from 'wix-window';
import {memory} from 'wix-storage';

let previousPageURL = memory.getItem("page");

if (previousPageURL === '/product-page/1-page-website') {
    wixLocation.to('/copy-of-stage-1-1')
    }

Let me know if this works for you!

Hi Quin, thanks for the quick reply! Unfortunately this doesn’t seem to work either, no redirect taking place. Could there be an error in my code used on the site section?

import {memory} from ‘wix-storage’ ; import wixLocation from ‘wix-location’ ; let previousPageURL;$w.onReady( function () { previousPageURL = memory.getItem( “page” ); memory.setItem( “page” , wixLocation.url);});

What’s not working? What error code do you get? What’s your site URL? Any screenshots?

Hi Ahmad, thanks for the reply!

The page is not redirecting as it should, no error code being shown. I have included all appropriate screenshots and codes below in an effort to make it as clear as possible, please let me know if anything else is needed :slight_smile:

Target : When visitors of the site come from the specific product page ( https://www.elevatedmediadesign.com/product-page/creation ) I would like them to be redirected to the next stage of the order process ( https://www.elevatedmediadesign.com/stage2 )

Code used:

Hi Ahmad, thanks for the reply!

The page is not redirecting as it should, no error code is shown. I have included all appropriate screenshots and codes below in an effort to make it as clear as possible, please let me know if anything else is needed :slight_smile:

import wixLocation from 'wix-location'; 
import wixWindow from 'wix-window';
import {memory} from 'wix-storage';

let previousPageURL = memory.getItem("page");

if (previousPageURL === 'https://elevatedmediadesign.com/product-page/creation') {
    wixLocation.to('https://elevatedmediadesign.com/stage2')
    }	

SITE

import {memory} from'wix-storage';
import wixLocation from'wix-location';
let previousPageURL;
$w.onReady(function () 
{  previousPageURL = memory.getItem("page"); 
 memory.setItem("page", wixLocation.url);});	

Thanks again for the help, it is hugely appreciated :slight_smile:

P.s the overall goal is to create a multistage checkout process.

Hello Alex,

here you have just a some kind of another idea for your check-out-process…
https://russian-dima.wixsite.com/meinewebsite/blank-13

It’s just a simple example, you can work on it and some much better.
For example a one-page check-out by using anchors and so on.
You can also put all the 5 Stage-Boxes over eachother (overlapping-mode) and hide/show each of the active stage.

You will not be redirected anywehere ----> no page-loadings = no waste of time.

Everything works on just one page :wink:

But well it’s just an idea. :grin:

Why not using the Multi-State box ? Aren’t you aware of it? You can have as many stats as you want, each of them will represent a stage.

Yes of course, did not think about it, damn xD :rofl:

So there is one more better possibilitie :grin: without struggling with …

import {memory} from'wix-storage';

and

import wixLocation from'wix-location';

Just making life a little bit easier :wink:

Working with state-boxes should be easy for everyone…

https://russian-dima.wixsite.com/meinewebsite/multistate-boxes

Yes of course :joy::joy:

Most of people aren’t aware of it, and don’t know how to use it, I use it all the time, it’s such a powerful tool, just if it didn’t lose the dynamic height a week ago :triumph:

Lost for ever or temporarily?

Who knows :unamused: Maybe forever

Thanks guys, multi state boxes look great and potentially the solution! Just unsure of the code I would need to use - any pointers? :slight_smile:

Link updated.
Sorry, forgot to show the code.

https://russian-dima.wixsite.com/meinewebsite/multistate-boxes

All options for multistate-boxes you can see here…

https://www.wix.com/corvid/reference/$w.MultiStateBox.html

So… Tried this code


$w.onReady(function () {   });
 export function EmptyFullStateBox_viewportLeave(event) {
    {$w("#EmptyFullStateBox").changeState("Maintenance");}
}

Didn’t have much luck and then wondered if there were is a coding possibility for when a specific product is added to the cart? Working on a test page here - https://www.elevatedmediadesign.com/blank

Thanks again for all the help :slight_smile:

Still not having much luck with this, any thoughts?

Show what you have right now. Some ready code?
Pics? What is your issue?

You wanted to create a multistage checkout-process, what are you waiting for? :grin:

You already have got some examples and some ideas and all relevant stuff, what do you need more?

Hi russian-dima, thanks for the reply - apologies for the delay!

Think I am fairly close now with this code here - https://www.elevatedmediadesign.com/testpage

The button on stage three links to the cart page as I couldn’t figure out how to display this in the Multi-State Box.

My remaining questions are around the navigation of states. Is it possible for the states to change depending on which item was added to the cart or if the view has just come from the relevant product page?

$w.onReady( function () {
$w( " #Stage1button " ).onClick(() => {
$w( ’ #Stage1box ’ ).changeState( “Stage1complete” );
$w( ’ #Stage2box ’ ).changeState( “Stage2active” );
$w( ’ #progressBar1 ’ ).value = 20 ;
} );
});
$w.onReady( function () {
$w( " #Stage2button " ).onClick(() => {
$w( ’ #Stage2box ’ ).changeState( “Stage2complete” );
$w( ’ #Stage3box ’ ).changeState( “Stage3active” );
$w( ’ #progressBar1 ’ ).value = 40 ;
} );
});
$w.onReady( function () {
$w( " #Stage2button " ).onClick(() => {
$w( ’ #Stage2box ’ ).changeState( “Stage2complete” );
$w( ’ #progressBar1 ’ ).value = 60 ;
} );
});

Thanks again!

Hello Alex,

looks good, well done.

Is it possible for the states to change depending on which item was added to the cart or if the view has just come from the relevant product page?
First at all there is a question if you use your own cart-system or the one of wix?
Do you use the app → WixStores?
If so, then you have to look, which possibilities are given to it.

https://www.wix.com/corvid/reference/wix-stores.html

https://www.wix.com/corvid/reference/wix-stores-backend.html

When you found the value of the item which was added to the cart, you just make an if-query and ask depending on which item was selected to show the related state of the multi-state-box.

Thanks! Slowly (very slowly) getting the hang of it - I’ve come up with something like this - how does this look to you?

import wixStoresBackend from ‘wix-stores-backend’

export function getCurrentCart () {
return wixStoresBackend . getCurrentCart ();
}

wixData . query ( “promise" )

. contains ( “648b35d2-0770-8f29-8c12-31f6cb06cacf” )
. then (
$w(‘#Stage2box’).changeState(“Stage2complete”);
$w(‘#progressBar1’).value = 60;
} );

Sorry here i can not really help you, because of leck of knowledge in Back-End at moment.
I am sure, another one can help.