Jump to content

Multishop module query builder


Recommended Posts

Hello guys,

While creating a multishop module, I faced some troubles with the database queries. I wonder if there is any kind of helper that ease the process of retrieving data from a table that contains a shop_id column.

What I do for now is something like:

        $qb = $this->connection
            ->createQueryBuilder()
            ->from($this->dbPrefix . 'gallery', 'g')
            ->where('g.shop_id = :id')
            ->setParameter('id', $this->context->getContext()->shop->id)
        ;

So I inject the legacy context, and retrieve the currently selected shop.

But the issue is, it does not work properly when the user selects "All shops" or an entire shop group because it will only select the default shop data.

I saw some kind of helper tools that you can plug directly in your sql query but it does not work using query builder.

Whats is the best way to do this ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...