isType('b2b')) { $storeField = 'COALESCE(('.static::getB2BInStoreField($qb->isAliasPresent('pv'))."), {$storeField})"; } return static::applyProductReservationsOnInStoreField($storeField, $useVariations); } private static function getB2BInStoreField(bool $useVariations): string { $qb = sqlQueryBuilder() ->select('COALESCE(SUM(si_shop_store.quantity), 0)') ->from('stores_items', 'si_shop_store') ->andWhere('p.id = si_shop_store.id_product') ->andWhere(Operator::equals(['si_shop_store.id_store' => self::CENTRAL_STORE_ID])); if ($useVariations) { $qb->andWhere('pv.id <=> si_shop_store.id_variation'); } return $qb->getRunnableSQL(); } }