javascript - Prestashop set catalog mode ON/OFF if user unlogged/logged -
i'm working on prestashop module set catalog mode on or off if user unlogged or logged.
works great got problem.
i don't want unlogged users see prices @ , allowed order. solution found, when first connection (mode catalog off) unlogged user load page, catalog mod turn on, can see prices (has reload hide prices) so, first load set catalog mode on , second load display real catalog mode.
i found js script reload automatically take effect new mode obviously, loading time of page 2 times longer.
here function :
public function hookheader() { $logged = $this->context->customer->islogged(); if (!$logged) { configuration::updatevalue('ps_catalog_mode', true); } else { configuration::updatevalue('ps_catalog_mode', false); } // reload page once more echo ' <script type="text/javascript"> (function() { if( window.localstorage ) { if( !localstorage.getitem( "firstload" ) ) { localstorage[ "firstload" ] = true; window.location.reload(); } else { localstorage.removeitem( "firstload" ); } } })(); </script> '; }
hope me this. thank you.
your solution has problem. you're updating value inside database: if multiple users browsing site, value turned on/off/on/off/..., in other words it's "unstable". next customer visits site current value (can on , off).
instead, should toggle value customer. wrote override configuration
class, check if you're trying ps_catalog_mode
, check if you'er logged in , returns 0 or 1
. careful cache value using static
variables (so don't have check multiple times).
but solution has flaw too. checks key of request configuration variable everytime.
a better solution change value of during session. configuration variables held in php array during session. should change here:
https://github.com/prestashop/prestashop/blob/1.6.1.x/classes/configuration.php#l203
possibly overridding
https://github.com/prestashop/prestashop/blob/1.6.1.x/classes/configuration.php#l140
this had in mind overriding loadconfiguration
:
<?php // placed in /override/classes/configuration.php class configuration extends configurationcore { public static function loadconfiguration() { parent::loadconfiguration(); // 'global' because assume you're not runing multishop self::$_cache[self::$definition['table']][0]['global']['ps_catalog_mode'] = !context::getcontext()->customer->islogged(); } }
i wrote memeroy sure check anmes, etc. assume you're running > ps1.6
Comments
Post a Comment