Jump to content

Create Session And Check is exist in theme


Recommended Posts

hi friends,

 

i am a new to php and prestashop, now i am working in online grocery shop site.

what i need is when a customer entered into the site,first they want to select their city.

once they select their city, the page never ask to select city till the session expire.. i wrote jquery ajax for this.it works fine first time and display the session $_SESSION['city'] variable value. if i refresh the page the {if !isset($smarty.cookies.city)} condition does not work again..

 

help me..

 

header.tpl

--------------------------------

{if !isset($smarty.session.city)}
<div id="graybg">
    </div>
    <div id="city_select_div">
Select your city : <div id="mycity">MYCITY</div>
    </div>
    {/if} 
 
global.js
-----------------
$('#mycity').click(function(){
var city=$('#mycity').text();
  $(this).parent().hide();
  $(this).parent().prev().hide();
  $.ajax({
url: 'themes/default-bootstrap/city_session.php',
type: "POST",
datatype: 'json',
data: "city_value="+city,
success: function (jsonData)
{
  $('.shop-phone').append('<span>City :'+jsonData+'</span>');
}
   });
  });
-----------------------
city_session.php
------------------------
<?php
echo $_SESSION['city']=$_REQUEST['city_value'];
 
?>
Edited by mohamedali (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

i created a php file "city_session.php" in root folder with following code,

/*----------------city_session.php-------------------*/

<?php
include 'config/config.inc.php' ;
include 'init.php' ;
     Context::getContext()->cookie->city="chennai";
  //echo Context::getContext()->cookie->city;
 
?>
/*-------------------------------*/

and call it via normal jquer ajax...

globa.js

    $('#mycity').click(function(){
    var city=$('#mycity').text();
  $(this).parent().hide();
  $(this).parent().prev().hide();
  $.ajax({
url: 'city_session.php',
type: "POST",
datatype: 'json',
data: "city_value="+city,
success: function (jsonData)
{
//alert(jsonData);
  $('.shop-phone').append('<span>City :'+jsonData+'</span>');
}
   });
  });
});

/*--------------------------------*/

header.tpl

 

        {if !isset($cookie->city)}
        <div id="graybg">
    </div>
            <div id="city_select_div">
        Select your city : <div id="mycity">MYCITY</div>
    </div>
    {/if}

/*---------------------------*/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...