Search code examples
phpsmartyprestashopprestashop-1.6

Prestashop 1.6.1.11 If user not logged show (This.)


Currently trying to dig my way around Prestashop, 1.6.1.11. I understand it a little bit but I wouldn't say I'm experienced.

I'm after a way to check if the user is logged in, which I have found examples for this elsewhere using .tpl files. However I need to action a response if the user is not logged in The thread I found is the reverse of which.

e.g. If user is not logged show element.

I found this line {if $logged} ..... {/if} , on the prestashop forums, but the thread is rather old and I'm not sure if this holds up as it dates back to version 1.5. I may be showing my inexperience here, but you don't know until you ask.

As a bit of background as to what it is specifically that I'm trying to achieve is to display a full width / height image with a sign-in element layered over top within the center.

I want to essentially give the user only one element to interact with and use to sign in.

I hope I have explained myself well enough, any help is appreciated. I'll keep looking and if I find anything useful I'll post it here.

Edit

Link to Prestashop thread.

My Own Prestashop question.


Solution

  • So after some digging, I was able to use the following to get the function I desired.

    <!-- Check Login -->
    <div id="check-log">
      {if $is_logged}
    
        <a href=".." id="Logout" />Logout</a>
    
      {else}
    
        <a href=".." id="Login" />Login</a>
    
      {/if}
    </div>
    

    This code should be placed within the header.tpl Theme file.


    This variable is defined in class /classes/controller/FrontController.php in method init():

    $this->context->smarty->assign(array(
        // Useful for layout.tpl
        'mobile_device'       => $this->context->getMobileDevice(),
        'link'                => $link,
        'cart'                => $cart,
        'currency'            => $currency,
        'currencyRate'        => (float)$currency->getConversationRate(),
        'cookie'              => $this->context->cookie,
        'page_name'           => $page_name,
        'hide_left_column'    => !$this->display_column_left,
        'hide_right_column'   => !$this->display_column_right,
        'base_dir'            => _PS_BASE_URL_.__PS_BASE_URI__,
        'base_dir_ssl'        => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__,
        'force_ssl'           => Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'),
        'content_dir'         => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__,
        'base_uri'            => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__.(!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''),
        'tpl_dir'             => _PS_THEME_DIR_,
        'tpl_uri'             => _THEME_DIR_,
        'modules_dir'         => _MODULE_DIR_,
        'mail_dir'            => _MAIL_DIR_,
        'lang_iso'            => $this->context->language->iso_code,
        'lang_id'             => (int)$this->context->language->id,
        'language_code'       => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code,
        'come_from'           => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))),
        'cart_qties'          => (int)$cart->nbProducts(),
        'currencies'          => Currency::getCurrencies(),
        'languages'           => $languages,
        'meta_language'       => implode(',', $meta_language),
        'priceDisplay'        => Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer),
        'is_logged'           => (bool)$this->context->customer->isLogged(),
        'is_guest'            => (bool)$this->context->customer->isGuest(),
        'add_prod_display'    => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
        'shop_name'           => Configuration::get('PS_SHOP_NAME'),
        'roundMode'           => (int)Configuration::get('PS_PRICE_ROUND_MODE'),
        'use_taxes'           => (int)Configuration::get('PS_TAX'),
        'show_taxes'          => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')),
        'display_tax_label'   => (bool)$display_tax_label,
        'vat_management'      => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
        'opc'                 => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
        'PS_CATALOG_MODE'     => (bool)Configuration::get('PS_CATALOG_MODE') || (Group::isFeatureActive() && !(bool)Group::getCurrent()->show_prices),
        'b2b_enable'          => (bool)Configuration::get('PS_B2B_ENABLE'),
        'request'             => $link->getPaginationLink(false, false, false, true),
        'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'),
        'quick_view'          => (bool)Configuration::get('PS_QUICK_VIEW'),
        'shop_phone'          => Configuration::get('PS_SHOP_PHONE'),
        'compared_products'   => is_array($compared_products) ? $compared_products : array(),
        'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
        'currencySign'        => $currency->sign, // backward compat, see global.tpl
        'currencyFormat'      => $currency->format, // backward compat
        'currencyBlank'       => $currency->blank, // backward compat
    ));
    
    // Deprecated
    $this->context->smarty->assign(array(
        'id_currency_cookie' => (int)$currency->id,
        'logged'             => $this->context->customer->isLogged(),
        'customerName'       => ($this->context->customer->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
    ));