Coder Social home page Coder Social logo

Comments (8)

ccamarillo avatar ccamarillo commented on July 17, 2024 1

Thank you SO MUCH @daftspunk
We are getting a lot of the multisite feature - we're using it to host two different e-commerce sites with different everything. We had to make some utilities for the Twig templates in mail templates, and we had to do some other things to separate users, because we were not comfortable turning on Mulltiiste for users or email templates. Is that wise?

I'll let you know how it goes with the next upgrade.

from october.

daftspunk avatar daftspunk commented on July 17, 2024

Hi @ccamarillo

Each site uses its own file cache, configured in our plugin's Plugin.php

Can you share the code used here? It is possible that this code is not running for the combiner URLs and would cause this outcome.

from october.

ccamarillo avatar ccamarillo commented on July 17, 2024

Here's where we specify our two different caches for the two different sites:
Plugin.php

public function boot()
    {

        $siteCode = \OakleySI\OakleySI\Classes\Multisite::getSiteCode();

        // CACHE
        if ($siteCode == 'ess-direct') {
            $cacheDriver = 'ess';
        } else {
            $cacheDriver = 'oakley';
        }

        // Once you have the cacheDriver, set the configuration
        config(['cache.default' => $cacheDriver]);
        ...
        }

And then the cache.php config:

return [
  'stores' => [
    'ess' => [
      'driver' => 'file',
      'path' => storage_path('framework/cache/ess'),
    ],
    'oakley' => [
      'driver' => 'file',
      'path' => storage_path('framework/cache/oakley'),
    ],
    ...
  ]
]

We've established a workaround - avoid using the combiner to load our scripts and stylesheets - load one at a time. Thanks @daftspunk

from october.

ccamarillo avatar ccamarillo commented on July 17, 2024

The reason we have two caches is because with just one, one site would overwrite the files and the other site's files would disappear from the cache.

from october.

daftspunk avatar daftspunk commented on July 17, 2024

Thanks, may I ask what are the contents of the OakleySI\OakleySI\Classes\Multisite::getSiteCode() method?

from october.

ccamarillo avatar ccamarillo commented on July 17, 2024
public static function getSiteCode() {
        $installedOnDomains = env('INSTALLED_ON_DOMAINS', false);

        $user = \Auth::getUser();
        if ($user) {
            if ($user->customer_group === null) {
                return self::getSiteCodeFromUrl();
            }
            $siteCode = $user->customer_group->code;
            return $siteCode;
        } else if (!$installedOnDomains) {
            // get first segment after domain name
            $url = \Request::url();
            $urlParts = explode('/', $url);
            if (count($urlParts) < 4) {
                return 'ess-direct'; // fall back to this site if no code exists in url segment / such as when running in console or admin
            } else {
                $siteCode = $urlParts[3];
                return $siteCode;
            }
        } else {
            return self::getSiteCodeFromUrl();
        }
    }

We are using OFFLINE Mall customer groups to allow users to access one site or another. If they are logged in, we look at the OFFLINE Mall customer group to identify what site they have access to. If they come to the site and are not logged in, we determine which cache to use based on the URL segments or domain. Customer groups and Sites share codes... that is how I am managing access to these sites. We will redirect from one site to another if the user tries to access the wrong site based off their customer group.

I suppose if there is some other method we could use to determine which cache to use, I'm all ears on that. There may be a mismatch between what site id is actually loading and what I am determining here? Thank you.

from october.

ccamarillo avatar ccamarillo commented on July 17, 2024

Also, here is getSiteCodeFromUrl():

private static function getSiteCodeFromUrl() {
        // get the beginning of the url, including protocol and domain name
        $url = \Request::root();
        $site = \System\Models\SiteDefinition::where('app_url', $url)->first();
        if (!$site) {
            return 'ess-direct'; // fall back to this in admin
        }
        $siteCode = $site->code;
        return $siteCode;
    }

from october.

daftspunk avatar daftspunk commented on July 17, 2024

In v3.6, we've added the ability to enable multisite in the system combiner:

// config/multisite.php
'features' => [
    'system_asset_combiner' => true, // ← set to true
    // ...
],

Once enabled, a different cache key is used for each site, and the active site is set when the combiner first loads to ensure custom configuration will also apply.

Hopefully this will resolve the original issue by itself.

To preserve the current solution, the boot method should hook the site.changed event when the change becomes available later in the app lifecycle.

public function boot()
{
    Event::listen('site.changed', function($id) {
        $siteCode = \Site::getSiteCodeFromContext();

        // CACHE
        if ($siteCode == 'ess-direct') {
            $cacheDriver = 'ess';
        } else {
            $cacheDriver = 'oakley';
        }

        // Once you have the cacheDriver, set the configuration
        config(['cache.default' => $cacheDriver]);
    });
}

v3.6 should be released soon.

I hope this helps!

from october.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.