Preserving language session ID from one domain to the next - session

I have two multi-lingual web sites. The main site and the shop site. On the main site detail page there is a "find in store" button. When the button is pressed, no matter what the language was set to on the main page, the shop page will open the product detail page in the default language (expected).
Is there a way to pass the session setting for language when redirecting to the shop site?
<?php
if (!session_id()) session_start();
if (!isset($_SESSION['languageID'])) {
$_SESSION['languageID'] = 1;//default value
}
?>
<?php
if (array_key_exists('german_x', $_POST)) {
$_SESSION['languageID'] = 1;
} else if (array_key_exists('english_x', $_POST)) {
$_SESSION['languageID'] = 2;
} else if (array_key_exists('french_x', $_POST)) {
$_SESSION['languageID'] = 3;
} else if (array_key_exists('spanish_x', $_POST)) {
$_SESSION['languageID'] = 4;
}
?>
The URL of the find in store button looks like this:
<input type="submit" name="goToShop" value="Find in store" />

Didn't get any answers, so I got creative. Maybe not the best or conventional way to go, but here is what I did, maybe it will help someone else:
Some of the language content is done with includes. I created an html page with a link to the detail page, that had the language session set in the desired language. So, while the English session was running, it would call detail_en.php, while Spanish it would call detail_es.php etc.
This is what the link looks like:
<input type="submit" name="goToShop" value="<?php echo $row_rscontent13['description15']; ?>" />

Related

How to 'enable' and 'disable' buttons

I have two buttons in view that redirect to
own website
Customer Website
I am using 'codeigniter'. In this, I want to keep a condition the user can click on the "own website" button only one time. Then, that button should be disabled, i.e, only the "customer website" button should work.
To do this, I want to check if the customer id is present in the database. If yes, (i.e, there is customer id inserted) then, the "own website" button should be disabled.
If you're simply wanting to conditionally set HTML on load of page, you can do so with the below code (change it to apply to your db etc), but if you want to do it dynamically you will need to use a client side language to watch for events.
View Code:
// View - Own Site
<button class="button" id="own-button" data-customerId="<?= $customerId ?>" disabled="<?= $disabled ?>">Click Me!</button>
// View - Customer Site
<button class="button" id="customer-button">Click Me!</button>
CodeIgniter:
function index() {
$data["customerId"] = "1"; // Just an example
$data["disabled"] = $this->getButtonStatus($data["customerId"]);
$this->load->view("ownsite/index", $data);
}
// get current button status i.e. is there anything in the DB
private function getButtonStatus($customerId) {
if(!$customerId) {
return FALSE;
}
$this->load->database();
$disabled = $this->db->select("customerId")
->where("customerId", $customerId)
->get("myTable");
return $disabled->num_rows() > 0 ? TRUE : FALSE;
}

Magento 1.9 vertical menu issue

i've stumbled on a relatively known issue, but i cant find the solution.
I am using magento 1.9 CE
I have found some code to show a vertical menu of the current categorie with its children, and on the homepage the root category and everything works fine except 1 little detail. The subcategories don't load in the order of the backend. It's important that the same order as how it is setup in teh backend loads. I have tried allot of variations, like getCChildrenCategories but then it results in a blnak page. I also found menu's that do work, but then when i visit the homepage, i get an error and the page turns blank.
This is the code i am using at the moment.
<section class="block-layered-nav custom-left-menu" role="navigation">
<div class="block-content">
<?php
echo "<dl id='narrow-by-list2'>";
$_category = $this->getCurrentCategory();
$subcatid = $_category->getId();
$parentCategory = Mage::getBlockSingleton('catalog/navigation')->getCurrentCategory()->parent_id;
$name = $_category->getName();
$root_category = Mage::getModel('catalog/category')->load($subcatid);
$subcategories = $root_category->getChildren();
if($subcategories != "")
{
echo "<span class='h3'>Categorie</span><ol>";
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a></li>';
}
}
else
{
echo "<span class='h3'>Categorie</span><ol>";
$root_category = Mage::getModel('catalog/category')->load($parentCategory);
$subcategories = $root_category->getChildren();
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a>';
}
}
echo "</ol>";
?>
</div>
</section>
Any help would be much appreciated. All i know is that, somewhere in this code its not calling the categories the right way, i also tried:
$currentCat = Mage::registry('current_category');
but this results in a blank homepage.
Here is a link to the dev enviremont: http://dev.smoldersbv.nl/schroeven-en-bouten.html
If you hover over the main navigation you see a different order, the correct order, then on the left menu.
This is normal $this->getCurrentCategory() get the current category = the category you are currently browsing.
On the home page you are not in a category, like on any other cms pages or even on the contact us page, ... (and there are lots more). So you have nothing in the current category which is obvious.
Problem solved,
The way of the requests where wrong therefor this menu is unable to produce the order of the backend so i ended up using a whole different mockup.
thnx for looking anyway.

Magento: Category Lock/Warning or T&C

I wonder if there is a way to add a Warning/Advisory or Terms & Conditions (preferably) to a category or a landing page to warn users about adult content. On the shop I'm working on there is an "Adult Section" Category for Erotic Toys, Lingerie, cosplay, etc. and I need to warn users about such content before they access the section in case they're less than 18.
I've searched the web and only found paid extensions which I cannot afford. Does anyone know how to do this?
I'm using Magento CE 1.7.
Thanks,
EDIT:
Ok, so I've been trying to figure out how to do this and I just figured that the best way to do it would be to just create a Category Landing Page and adding a java script for T&C redirect to the page I want it to.
This is the code I would use for the Category Landing Page with blank content would be this.
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_collectionSize = $_categories->count() ?>
<div>
<?php $i=0; foreach ($_categories as $_category): ?>
<?php
$layer = Mage::getSingleton(‘catalog/layer’);
$layer->setCurrentCategory(Mage::getModel(‘catalog/category’)->load($_category->getId()));
$helper = Mage::helper(‘catalog/category’);
?>
Then I found a code snippet that would redirect the user to a page of my liking after clicking accept but I'm not sure how to implement it and/or if this is the best choice. Here's the code.
<form action="url-to-go-to" method="GET" onsubmit="return checkCheckBox(this)">
I accept: <input type="checkbox" value="0" name="agree">
<input type="submit" value="Continue">
<input type="button" value="Exit" onclick="document.location.href='BACKTOWHAT.html';">
</form>
<script type="text/javascript">
<!--
function checkCheckBox(f){
if (f.agree.checked == false )
{
alert("Please tick the box to continue");
return false;
} else
return true;
}
-->
</script>
Now I was thinking that it would be best to just create a simple CMS page and point the category on the top menu to that page and once they have agreed and clicked on continue, they could be taken to the actual category by simply pointing the 'onclick' to the URL of the actual category.
Not sure if this is the best way but it's the only way I could come up. The other way I thought of would've required me to take the "agreements" during checkout that already comes with magento and make an extension that would allow me to place it on any page and call the "Agreement ID" from the Sales/Terms and Conditions tab but I don't know how to actually do that, it was just a thought.
If anyone has a better solution, I'd be happy to hear it.
I would add some sort of JavaScript that shows a div over the top of the whole page, that will create a session cookie when you accept to watch the category. Otherwise, make a back() in the history navigation. This way you don't need another page, just JS.
On another note, could you please post the extensions you found that do this?

Update multilingual content with AJAX in Yii

Refer to my code below, when user click on en button, the content will be changed to English, while clicking tw button, the content will be changed to Chinese.
However, the page will be refreshed each time when user click either en or tw button. I want to ask how can I implement AJAX content update in this case?
The result is when user click either en or tw button, the page won't be refreshed to change the content language.
Thanks
I have refer to Yii docs here, but seem that it is not appropriate for my case
C:\wamp\www\website\protected\views\site\index.php
<?php
$lang = isset($_GET["lang"]) ? $_GET["lang"] : "en_uk";
$lang = $lang == "en" ? "en_uk" : "zh_tw";
Yii::app()->setLanguage($lang);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="submit" value="en" name="lang" />
<input type="submit" value="tw" name="lang" />
</form>
<div class="main">
<?php echo Yii::t(Yii::app()->controller->id, "Causeway Bay"); ?>
</div>
Best practice is to reload the page in these cases, because usually you have to update so much, that it is just not worth it.
That said, CHtml's ajaxSubmitButton is the cleanest way to implement this, because you can map every event of your call very easily. It looks something like this:
<?php
echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/changeLanguage')),
array(
'error'=>'js:function(){
alert("error");
}',
//if you add a return false in this, it will not submit.
'beforeSend'=>'js:function(){
alert("beforeSend");
}',
'success'=>'js:function(data){
alert("success, data from server: "+data);
}',
'complete'=>'js:function(){
alert("complete");
}',
//'update'=>'#where_to_put_the_response',
)
);
?>
You don't have to use every parameter of course. The update parameter can update a HTML tag instantly.
EDIT:
This can be done easily if you use the controller's renderPartial method, for instance in your site controller if you have the action responsible for the index.
public function actionIndex(){
//get variables, etc
if(Yii::app()->request->isAjaxRequest) {
$lang = $_POST['nameOfSubmit'];
}else {
//...
}
//if the 3rd parameter is true, the method returns the generated HTML to a variable
$page = $this->renderPartial('_page', array(/*parameters*/ ), true);
echo $page;
}
And then, in your view file you can simply have
<?php echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/index')),
array('update'=>'#content_div',));?>
and
<?php echo CHtml::ajaxSubmitButton('tw', CHtml::normalizeUrl(array('site/index')),
array('update'=>'#content_div',));?>

Zend Framework fancybox confirmation dialog with ajax and posted values

I created a confirmation page for deleting an item. This works perfectly.
Now I want to appear the confirmation page in fancybox, still passing all the variables and delete the data or close the dialog.
It's important that the process still works as it does now (delete->confirmationpage->redirect/deletion) so that users with javascript disabled can perform these actions without a problem.
Now have I been reading about zend framework,ajax, json and more, but the more I read, the less I understand.
So in a nutshell, my question:
I want to pass a variable to the fancybox and if 'yes' perform the delete action or on 'no' close the dialog. This within the zend framework and jquery.
Any advice or tips are greatly appreciated!
You need to use content switching in your ajax which will then render your action appropriately, for example:
function confirmDeleteAction() {
if($this->_request->isXmlHttpRequest()) {
//This is ajax so we want to disable the layout
$this->_helper->layout->disableLayout();
//Think about whether you want to use a different view here using: viewRenderer('yourview')
}
//The normal code can go here
}
function deleteAction() {
//You probably don't want to show anything here, just do the delete logic and redirect therefore you don't need to worry where it's coming from
}
And in your fancybox, have a view that has a form and two buttons, the form should point to your delete action with the id of whatever your deleting as a get param. Set some javascript up that says something like (and this is mootools code, but you can convert it easily):
$('confirmButton').addEvent('click', function(e) {
e.preventDefault();
this.getParent('form').submit();
}
$('cancelButton').addEvent('click', function(e) {
e.preventDefault();
$('fancyBox').destroy(); //I'm not sure it has an id of fancyBox, never used it
}
Came across the question today and figured I could give it a fresh look. For Zend Framework the solution is really simple:
This is how the action looks:
public function deleteAction()
{
$this->_helper->layout()->disableLayout();
$this->view->news = $this->newsService->GetNews($this->_getParam('id'));
if($this->getRequest()->isPost())
{
if($this->getRequest()->getPost('delete') == 'Yes')
{
$this->newsService->DeleteNews($this->_getParam('id'), $this->view->user->username, $this->view->translate('deleted: ').'<strong>'.$this->view->pages[0]['title'].'</strong>');
$this->_helper->flashMessenger(array('message' => $this->view->translate('The page is deleted'), 'status' => 'success'));
$this->_helper->redirectToIndex();
}
elseif($this->getRequest()->getPost('delete') == 'No')
{
$this->_helper->flashMessenger(array('message' => $this->view->translate('The page is <u>not</u> deleted'), 'status' => 'notice'));
$this->_helper->redirectToIndex();
}
}
}
The delete.phtml
<div>
<h2><?php echo $this->translate('Delete news'); ?></h2>
<?php
foreach($this->news as $news)
{
?>
<p>
<?php echo $this->translate('You are now deleting <strong>\'').$news['title'].$this->translate('\'</strong>. Are you sure about this?'); ?>
</p>
<p>
<?php echo $this->translate('<strong>Note! </strong>This action is inreversable, even for us!'); ?>
</p>
<form action="<?php echo $this->baseUrl(false).'/news/index/delete/'.$news['id']; ?>" method="post">
<?php
}
?>
<input class="submit deleteYes" type="submit" name="delete" value="<?php echo $this->translate('Yes'); ?>" />
<input class="submit deleteNo" type="submit" name="delete" value="<?php echo $this->translate('No'); ?>" />
</form>
And this is how the link to delete a file looks (within a foreach loop with my database results)
<a class="deleteConfirmation" href="<?php echo $this->baseUrl(false).'/news/index/delete/'.$news->id; ?>">delete</a>
This works like you would expect; when you click on delete the user goes to the delete confirmation page and redirects the user back to the index after the form is submitted. But I wanted the confirmation in a dialog (in my case I use fancybox). To achieve this, add the following jquery to your index:
$('.deleteConfirmation').fancybox({
// Normal fancybox parameters
ajax : {
type : "POST"
}
});

Resources