THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 Multi network eshop

(11-09-2018 08:41:43)


Hello,
I will like to have one main shop on domain.com and I will like to have a subdomain for it like shop1.domain.com ,
Is this possible?

Requirements:
   - All modules need to be shared
  - Database shared
  - Different configuration ( templates, maibe hooks and loops)

If you have/propose a different approach  I'm open

Br. ,
Lucian

Last edited by lucian.criste (11-09-2018 08:44:17)

Offline

#2 Re: Multi network eshop

(11-09-2018 09:19:16)


You can do it with a couple of simple modules. The basic idea is to associate a template to a domain (or subdomain), then listen to kernel events to set the template related to the current domain when a request is submitted.

To switch the current front template, you can use the TemplateSwitcher module : https://github.com/roadster31/TemplateS … stener.php

Then in your module create a listener which listens to KernelEvents::REQUEST or KernelEvents::CONTROLLER events, something like :

<?php
namespace YourModule\Listener;

use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use TemplateSwitcher\Event\TemplateSwitcherEvent;

class KernelListener implements EventSubscriberInterface
{
    /** @var RequestStack */
    protected $requestStack;

    /** @var Container */
    protected $dispatcher;

    /**
     * KernelListener constructor.
     * @param RequestStack $requestStack
     * @param EventDispatcherInterface $dispatcher
     */
    public function __construct(RequestStack $requestStack, EventDispatcherInterface $dispatcher) {
        $this->dispatcher = $dispatcher;
        $this->requestStack = $requestStack;
    }

    /**
     * @param FilterControllerEvent $event
     */
    public function controller(FilterControllerEvent $event)
    {
        $request = $this->requestStack->getCurrentRequest();

        $serverName = $request->getHost();

        // Find the template related to the current server name (e.g., domain)
        $frontTemplateName = ...

        // Set the front template for the current user using the TemplateSwitcher module
        $this->dispatcher->dispatch(
            TemplateSwitcherEvent::SWITCH_TEMPLATE_EVENT,
            new TemplateSwitcherEvent($frontTemplateName)
        );
    }

    /**
     * @inheritDoc
     */
    public static function getSubscribedEvents()
    {
        return [
            KernelEvents::CONTROLLER => ['controller', 192],
        ];
    }
}

This way, you can share modules and data between several templates and domains.


OpenStudio Toulouse

Offline

#3 Re: Multi network eshop

(11-09-2018 11:38:12)


Thanks for the quick response!
I will try to implement this , if i get block somewhere I will ask you again to help me .