2017-02-21 59 views
1

當前試圖圍繞Prestashop,1.6.1.11進行挖掘。我理解了一點,但我不會說我有經驗。Prestashop 1.6.1.11如果用戶未登錄顯示(This。)

我正在檢查用戶是否已登錄,我已經在其他地方找到了使用.tpl文件的示例。但是,如果用戶沒有登錄,我需要採取行動。我發現的線程與其相反。

例如如果用戶未登錄顯示元素。

我發現這條線{if $logged} ..... {/if},上的Prestashop論壇,但該線程是很舊,我不知道,因爲它的歷史可以追溯到1.5版本舉起。我可能會在這裏表現出我的經驗不足,但你直到你問起才知道。

作爲一個背景,我試圖實現的具體內容是顯示一個完整的寬度/高度圖像,並在中心內層疊頂部的登錄元素。

我想基本上是給用戶唯一一個與互動元素,並使用登錄。

我希望我已經解釋自己不夠好,任何幫助表示讚賞。我會繼續尋找,如果我找到有用的東西,我會在這裏發佈。

編輯

Link to Prestashop thread.

My Own Prestashop question.

回答

1

所以一些挖後,我能夠使用以下方法來得到我所追求的功能。

<!-- Check Login --> 
<div id="check-log"> 
    {if $is_logged} 

    <a href=".." id="Logout" />Logout</a> 

    {else} 

    <a href=".." id="Login" />Login</a> 

    {/if} 
</div> 

此代碼應該被放置在header.tpl主題文件中。


此變量/classes/controller/FrontController.php類中定義的方法中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) 
)); 
+1

我已經編輯你的問題,以增加更多的信息。但是你的模板中使用的變量應該是'$ is_logged'而不是'$ logged'。 –

+0

@FlorianLemaitre感謝您的幫助,我確實嘗試在我的搜索中找到該文件以便提前查看它,但是在查找它時找到了它。再次感謝這是寶貴的學習材料。 – Beaniie

+0

然而,在附註中,'$ logged'看起來完全正常且沒有問題。你能幫我理解爲什麼嗎? – Beaniie