interchange / interchange6-schema

DBIC schema for Interchange 6
8 stars 7 forks source link

Multistore setup #27

Open racke opened 10 years ago

racke commented 10 years ago

Add support for multiple stores to the schema. This is subject to research and discussion.

Regards Racke

mrmaloof commented 9 years ago

What may I do to help in here?

hexfusion commented 9 years ago

I think we need to think about what multi-store is in the dancer world. Basically if the template is build with a solid theme-able CSS infrastructure. Once we move the pages to the DB you could in theory have a single database and single app do multistore. Schema would need some work because you can't define the same navigation route twice. I would also think about perhaps having a separate plackup per store. Just so you can restart one at a time and not force restart on all. Just ideas is what we need now on how this is going to work. I don't have a clear vision personally.

mrmaloof commented 9 years ago

What we've done in our schema in IC5 is add a 'storeid' column to tables like transactions, orderline, products, etc. Then we set IC variable STOREID for each catalog. We use the domain name of the site for the storeid value.

In Dancer world we don't have a notion of a catalog.cfg or a sub configuration. We could just glean the storeid from the request and set a $storeid variable in our app and then use it through out. I'm thinking one app for multiple stores. (I don't care about restarting since we only start when an instance is created view AWS autoscaling group.)

I'm messing around with "hook before_template_render" to set the view based on the site. So we may have something like....

app/views/bottlenose_product_1 app/views/bottlenose_product_2 www/storeid1.com/views www/storeid2.com/views

Each site cold have a custom view or we could fallback on our predesigned templates.

hexfusion commented 9 years ago

Try setting up a nginx and plackup multi-domain test on a basic dancer app. Then with your hook before_template_render get your host and put it into session.

# check if host exists
my $host = session 'host';

unless ( $host ) {
    # set host in session
    $host = session host => request->host;
}

if ( !$host eq  request->host ) {
    # something bad is going on maybe kill the session?
};
mrmaloof commented 9 years ago

Cool! Thanks Sam. I have something like that going but now I’m stuck on having a per site layouts/main.tt but a common index.tt. It seems like layouts is a special directory in views. I can specify a per site views location but then I’d have repeated index.tt files for each site. I need per site layouts but the other templates like index.tt or product_view.tt to be common. Any ideas on how to do that? And I know this has nothing to do with Schema. Sorry for talking about it here.

hexfusion commented 9 years ago

Well I believe you can do something like this.

get '/' => sub {
    template 'home', { layout => 'site1' };
};
racke commented 9 years ago

Actually it is the third parameter:

get '/' => sub {
    template 'home', { .....} , { layout => 'site1' };
};
mrmaloof commented 9 years ago

On Dec 4, 2014, at 9:04 AM, Stefan Hornburg (Racke) notifications@github.com wrote:

Actually it is the third parameter:

get '/' => sub { template 'home', { .....} , { layout => 'site1' }; }; But doesn’t layouts have to be in views directory? So if I had a structure like so….

bottlenose/views/home.tt bottlenose/views/layouts/main.tt site1/views/layouts/site1.tt site1/public

I’d like site1 to use its layout to display the common template home.tt.

I see where I could just put various layouts for different sites inside the bottlenose directory structure but can I do it the way I specified above where I have a “root directory” for each site where we would redefine or override the default settings from bottlenose?

http://www.bottlenose-wine.com/ Bill Carr, President at Bottlenose (413) 584-0400 http://www.bottlenose-wine.com http://www.bottlenose-wine.com/  Download vCard http://www.bottlenose-wine.com/vcard/BillCarr.vcf

hexfusion commented 9 years ago

But then your multi app right?

racke commented 9 years ago

Actually for multisite it would be really useful to have Dancer2 implementation :-/

mrmaloof commented 9 years ago

On Dec 4, 2014, at 10:05 AM, Stefan Hornburg (Racke) notifications@github.com wrote:

Actually for multisite it would be really useful to have Dancer2 implementation :-/

I’m using Dancer2

http://www.bottlenose-wine.com/ Bill Carr, President at Bottlenose (413) 584-0400 http://www.bottlenose-wine.com http://www.bottlenose-wine.com/  Download vCard http://www.bottlenose-wine.com/vcard/BillCarr.vcf

hexfusion commented 9 years ago

Issue being that our IC6 plugin infrastructure is in Dancer1. I know work has begun on this for Dancer2 but ...

SysPete commented 9 years ago

Adding Plack::Middleware::Static to your app.psgi would allow you to rewrite paths for things beneath /public. Here's a guess (nasty quick untested hack):

#!/usr/bin/env perl
use FindBin;
use lib "$FindBin::Bin/../lib";
use Dancer2;
use MyApp;
use Plack::Builder;

my @sites = (qw/ example.com banana.com /);
builder {
    enable "Plack::Middleware::Static",
      root => 'public/',
      path => sub {
        my ( $path_info, $env ) = @_;
        ( my $http_host = $env{HTTP_HOST} ) =~ s/:.+//;
        if ( my ($match) =
            grep { $_ eq $http_host || $_ =~ /\.${http_host}$/ } @sites )
        {
            s|(^/site/)|$1/$match/|;
            return 1;
        }
        else {
            return 0;
        }
      },
      pass_through => 1;
    dance;
};

For views handled by D2 you need to do magic in before_template hook.

SysPete commented 9 years ago

You could also do static file rewrites in nginx/apache/...

SysPete commented 8 years ago

This is currently being worked on in branch topic/multistore_gh27

racke commented 8 years ago

:+1:

Excellent news!

SysPete commented 8 years ago

This is progressing. It is now possible to deploy the new schema and populate stores with initial fixtures (countries, currencies, states, roles, ...). Now need to fix the huge pile of code I've broken getting this far.