Post by jarvine » Wed May 23, 2012 5:31 pm

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.

Newbie

Posts

Joined
Wed May 23, 2012 5:22 pm

Post by Avvici » Thu May 24, 2012 6:35 pm

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:

Code: Select all

protected function index() {
Directly below it add this:

Code: Select all

$this->data['language_check'] = $this->language->get('code');
Now find this line:

Code: Select all

'children' => $children_data,
Directly below it add this:

Code: Select all

'id' => $category['category_id'],
Now open: catalog/view/theme/your_theme/template/common/header.tpl and find this code:

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 } ?>
Replace entire code above with this:

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 } ?>
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.
Last edited by Avvici on Thu May 24, 2012 8:32 pm, edited 1 time in total.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by straightlight » Thu May 24, 2012 7:43 pm

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Avvici » Thu May 24, 2012 8:26 pm

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. ;)
Get on it then. O0 Notice I told him that it was up to him to enhance his conditional? Therefore I did not place the }else{ in there for a return FALSE lol.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by wtbi » Wed Jul 10, 2013 11:41 pm

Hi,

I would like to hide/restrict products by language, is this possible? Alternatively I would like to have different model no's, sku's and images for each language.

Is this the best approach?

Any help would be greatly appreciated.

Newbie

Posts

Joined
Wed May 16, 2012 9:39 pm
Who is online

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