Hello,
Before starting OpenCart project in more detail, I need help in one thing and I could not find answer to this using search:
Store will have 3 languages: english, german, spanish.
Let's say there is 3 categories - cat1, cat2, cat3.
Cat1 should be visible to all languages.
Cat2 should be visible only if end user has selected german as language.
Cat3 should be visible only to end users who have selected spanish as language.
Is this possible out-of-the-box, and if, how? What files should I start looking to code it, if not built-in?
P.S. It is completely OK to show restricted categories and/or products to whatever geo-location the user comes from. I mean, english language user can change the language to german and see cat2 for german users.
Before starting OpenCart project in more detail, I need help in one thing and I could not find answer to this using search:
Store will have 3 languages: english, german, spanish.
Let's say there is 3 categories - cat1, cat2, cat3.
Cat1 should be visible to all languages.
Cat2 should be visible only if end user has selected german as language.
Cat3 should be visible only to end users who have selected spanish as language.
Is this possible out-of-the-box, and if, how? What files should I start looking to code it, if not built-in?
P.S. It is completely OK to show restricted categories and/or products to whatever geo-location the user comes from. I mean, english language user can change the language to german and see cat2 for german users.
Seems this would be pretty easy to do just by always having the language code + Category ID to use in a conditional.
for 1.5.2.1 open catalog/controller/common/header.php and find this line:
Directly below it add this:
Now find this line:
Directly below it add this:
Now open: catalog/view/theme/your_theme/template/common/header.tpl and find this code:
Replace entire code above with this:
The following will only display category's that have a language code of 'en' and a category id of 45 (YOU NEED TO OBTAIN YOUR CATEGORY ID's by turning SEO URL off and looking at your browser bar, or opening up database in PHP My Admin to look at the table.) Tested and works fine. It's up to you to format your conditional. This is for parent categories only. If you want to conventionalize children categories as well then you simply just set up another inside the children array.
for 1.5.2.1 open catalog/controller/common/header.php and find this line:
Code: Select all
protected function index() {
Code: Select all
$this->data['language_check'] = $this->language->get('code');
Code: Select all
'children' => $children_data,
Code: Select all
'id' => $category['category_id'],
Code: Select all
<?php if ($categories) { ?>
<div id="menu">
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<div>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
Code: Select all
<?php if ($categories) { ?>
<div id="menu">
<ul>
<?php foreach ($categories as $category) { ?>
<!--Start Category Conditional -->
<?php if($language_check == "en" && $category['id'] == 45){ ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<div>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
</li>
<!--End Category Conditional -->
<?php } ?>
<?php } ?>
</ul>
</div>
<?php } ?>
Last edited by Avvici on Thu May 24, 2012 8:32 pm, edited 1 time in total.
While this subject may bring its interest to others, a module should rather be developed in case multiple category IDs would be involved in the template loop. Besides, from a module, if the condition is false from the validation, the customer can still be redirected to the previous path IDs and if no path IDs are to be found then to redirect to the home page. 

Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Get on it then.straightlight wrote:While this subject may bring its interest to others, a module should rather be developed in case multiple category IDs would be involved in the template loop. Besides, from a module, if the condition is false from the validation, the customer can still be redirected to the previous path IDs and if no path IDs are to be found then to redirect to the home page.

Who is online
Users browsing this forum: Semrush [Bot] and 101 guests