Пример #1
0
    public static function getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang, Shop $shop = null, $use_shop_context = true)
    {
        global $cookie;
        if (!Module::isInstalled('agilemultipleseller')) {
            return parent::getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang, $shop, $use_shop_context);
        }
        $isSeller = (intval($cookie->profile) == Configuration::get('AGILE_MS_PROFILE_ID') or intval($cookie->profile) == 0);
        if (!$isSeller) {
            return parent::getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang, $shop, $use_shop_context);
        }
        require_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/agilemultipleseller.php";
        require_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/SellerInfo.php";
        if (intval($cookie->profile) > 0) {
            $id_seller = $cookie->id_employee;
        } else {
            $sellerinfo = new SellerInfo(SellerInfo::getIdByCustomerId($cookie->id_customer));
            $id_seller = $sellerinfo->id_seller;
        }
        $exclude = AgileMultipleSeller::getSpecialCatrgoryIds();
        $selectedCat = explode(',', str_replace(' ', '', $selectedCat));
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT c.`id_category`, c.`level_depth`, cl.`name`, IF((
			SELECT COUNT(*)
			FROM `' . _DB_PREFIX_ . 'category` c2
			WHERE c2.`id_parent` = c.`id_category`
		) > 0, 1, 0) AS has_children, ' . ($selectedCat ? '(
			SELECT count(c3.`id_category`)
			FROM `' . _DB_PREFIX_ . 'category` c3
			WHERE c3.`nleft` > c.`nleft`
			AND c3.`nright` < c.`nright`
			AND c3.`id_category`  IN (' . implode(',', array_map('intval', $selectedCat)) . ')
		)' : '0') . ' AS nbSelectedSubCat
		FROM `' . _DB_PREFIX_ . 'category` c
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON c.`id_category` = cl.`id_category`
		LEFT JOIN `' . _DB_PREFIX_ . 'category_owner` co ON c.id_category=co.id_category
		WHERE `id_lang` = ' . (int) $id_lang . '
		AND c.`id_parent` = ' . (int) $id_parent . '
		' . (empty($exclude) ? '' : 'AND c.id_category NOT IN (' . $exclude . ')') . '
		AND (IFNULL(co.id_owner,0) = ' . $id_seller . ' OR IFNULL(co.id_owner,0)=0)
		ORDER BY `position` ASC');
    }