Exemple #1
0
    /**
     * Load list of groups and shops, and cache it
     *
     * @param bool $refresh
     */
    public static function cacheShops($refresh = false)
    {
        if (!is_null(self::$shops) && !$refresh) {
            return;
        }
        self::$shops = array();
        $from = '';
        $where = '';
        $employee = Context::getContext()->employee;
        // If the profile isn't a superAdmin
        if (Validate::isLoadedObject($employee) && $employee->id_profile != _PS_ADMIN_PROFILE_) {
            $from .= 'LEFT JOIN ' . _DB_PREFIX_ . 'employee_shop es ON es.id_shop = s.id_shop';
            $where .= 'AND es.id_employee = ' . (int) $employee->id;
        }
        $sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.physical_uri, su.virtual_uri
				FROM ' . _DB_PREFIX_ . 'shop_group gs
				LEFT JOIN ' . _DB_PREFIX_ . 'shop s
					ON s.id_shop_group = gs.id_shop_group
				LEFT JOIN ' . _DB_PREFIX_ . 'shop_url su
					ON s.id_shop = su.id_shop AND su.main = 1
				' . $from . '
				WHERE s.deleted = 0
					AND gs.deleted = 0
					' . $where . '
				ORDER BY gs.name, s.name';
        if ($results = Db::getInstance()->executeS($sql)) {
            foreach ($results as $row) {
                if (!isset(self::$shops[$row['id_shop_group']])) {
                    self::$shops[$row['id_shop_group']] = array('id' => $row['id_shop_group'], 'name' => $row['group_name'], 'share_customer' => $row['share_customer'], 'share_order' => $row['share_order'], 'share_stock' => $row['share_stock'], 'shops' => array());
                }
                self::$shops[$row['id_shop_group']]['shops'][$row['id_shop']] = array('id_shop' => $row['id_shop'], 'id_shop_group' => $row['id_shop_group'], 'name' => $row['shop_name'], 'id_theme' => $row['id_theme'], 'id_category' => $row['id_category'], 'domain' => $row['domain'], 'domain_ssl' => $row['domain_ssl'], 'uri' => $row['physical_uri'] . $row['virtual_uri'], 'active' => $row['active']);
            }
        }
    }