first commit
This commit is contained in:
45
bundles/External/ZNZBundle/Query/Product.php
vendored
Normal file
45
bundles/External/ZNZBundle/Query/Product.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace External\ZNZBundle\Query;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use External\ZNZBundle\Util\ZNZUtil;
|
||||
use KupShop\KupShopBundle\Context\LanguageContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Contexts;
|
||||
|
||||
class Product
|
||||
{
|
||||
public const STORES_CACHE_KEY = 'store_StoreIdsZNZ';
|
||||
|
||||
public static function getInStoreField($useVariations = true, $qb = null): string
|
||||
{
|
||||
$storeIds = static::getStoreIds(
|
||||
Contexts::get(LanguageContext::class)->getActiveId()
|
||||
);
|
||||
|
||||
if ($qb && !empty($storeIds)) {
|
||||
if ($qb->isAliasPresent('pv') || empty($qb->getQueryPart('select'))) {
|
||||
$qb->leftJoin('pv', 'stores_items', 'znz_si', 'znz_si.id_product = p.id AND pv.id <=> znz_si.id_variation AND znz_si.id_store IN (:storeIds)')
|
||||
->setParameter('storeIds', $storeIds, Connection::PARAM_INT_ARRAY);
|
||||
|
||||
return 'COALESCE(znz_si.quantity, 0)';
|
||||
}
|
||||
}
|
||||
|
||||
return $useVariations ? 'COALESCE(pv.in_store, p.in_store)' : 'p.in_store';
|
||||
}
|
||||
|
||||
private static function getStoreIds(string $languageId): array
|
||||
{
|
||||
static $znzUtil;
|
||||
|
||||
if (!$znzUtil) {
|
||||
$znzUtil = ServiceContainer::getService(ZNZUtil::class);
|
||||
}
|
||||
|
||||
return $znzUtil->getActiveStoreIds($languageId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user