Public & regitered view

  • Posts: 447
  • Thank you received: 20
9 years 7 months ago #227815

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.4.45
-- Browser(s) name and version -- : 43.04

Hi

I have a site that currently has restricted views, so registered only can see the products and they have to register or login. However the client has now added a category and a range of products that are for normal public access. This part works fine. But when accessing the restricted categories it still shows the new public category list of products regardless of which product listing I view when it should be asking people to login or register.

Dave B)

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 7 months ago #227853

Hi,

I don't understand one thing, how is set the restriction ? On a menu or on the products directly ?
If it is on the menu, so if you create another menu able to list all the products even the ones which should be restricted so yes customers will be able to reach them.

What you have to do is set the access level on the products, or manage the categories to not allow the listing of the restricted products in the public menu.

Example:
Product category
- restricted products
- public products.

Set a menu on the "restricted products" category with the access level, and another menu on the "public category" that way the restricted products can't be reached by the public menu.

Please Log in or Create an account to join the conversation.

  • Posts: 447
  • Thank you received: 20
9 years 7 months ago #227992

Sorry perhaps I haven't been to clear.

The site had already been set up and people had to login or register an account before they could see the products.

Now there is a range of products which can be seen by everyone without registration. This range though is also showing up in all of the other categories.

Screenshot 1 shows how the site was originally set up. So if a client visited a product category they had to register or login.

Screenshot 2 shows the same category but the the option to register etc is not available but the product I have activated shows instead which is not correct. The Leisurewear category and product has been set up as public.

The product/listing.php view was modified to allow for the registration/login option to take place with the following code. Not sure if this needs to be ammended?

<?php $user = JFactory::getUser();if($user->guest && empty($this->rows)){ echo '<a class="btn btn-primary" href="/register">Please Register</a> or <a class="btn btn-primary"  href="/login">Go To Login</a>'; } ?>

Thanks

Dave B)

Attachments:
Last edit: 9 years 7 months ago by davec.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #228018

Hello Dave,

The code you are using will only display the "Please Register" message if :
- You are a guest user
- No products are available for you

If you have even 1 product available your message won't be displayed, so if you want to display your message for guest users even if some products are accessible you can use that code instead :

<?php $user = JFactory::getUser();if($user->guest){ echo '<a class="btn btn-primary" href="/register">Please Register</a> or <a class="btn btn-primary"  href="/login">Go To Login</a>'; } ?>

Please Log in or Create an account to join the conversation.

  • Posts: 447
  • Thank you received: 20
9 years 7 months ago #230036

Hi Mohamed

I don't require a message for the guest user on a particular category. What I am trying to achieve is this.

One category is public and anyone can buy products from that category without registering and use a quick checkout process.

The other categories require registration to see the prices and place orders.

Now when I switch on the public/guest category it appeas on all pages. So if I go to the /shop/male-female-clothing for instance which currently requires registration all of the products for the public category are displayed. It should have the Please Register or Go To Login message for that particular category. The products for the public category should only show under that menu item, elswhere the register message should still apply. Not really sure if this can be achieved?

For the public category the settings are as follows;

Access level on the products is set to all. The category is set to all.

The menu is set to public.

The other menu items are also set to public and the restrictions are set on the product categories as Registered, Administrator and Super Administrator and the same has been applied to the products themselves.

Thanks

Dave

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #230142

Hello Dave,

It should have the Please Register or Go To Login message for that particular category

Do you only want you error message ? or your error message on top of your product listing ?
Note that in that situation the solution will be to directly edit the "Listing_div" file of the product view of your front-end template via "Hikashop->Display->Views".

The products for the public category should only show under that menu item

What do you exactly mean by that ? can you give me more information about it through some screenshots for example ?

Thanks.

Last edit: 9 years 7 months ago by Mohamed Thelji.

Please Log in or Create an account to join the conversation.

  • Posts: 447
  • Thank you received: 20
9 years 7 months ago #230165

Hi Mohamed

In the first screenshot I have an error message that appears when you go to that category. All categories except for one (leisurewear) require registration which is approved by admin.

A new category has been added called Leisurewear. This is a public category and can be viewed by anyone and orders can be placed as well.

If I activate just one product it appears on all of the other category pages and the error message disappears. The product from the leisurewear category should only appear in the Leisurewear category. Please note that at this point I have not published the leisurewear category or Joomla menu items

Screenshot 2 is the same category as screenshot 1 but as you can see the error message has gone and has been replaced by the one product I have published. I do not want Leisurewear products showing in the categories that require registration.

If this is possible I would then like to offer the option of guest checkout.

Thanks

Dave

Attachments:
Last edit: 9 years 7 months ago by davec.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #230235

Hello Dave,

Then a solution can just be to directly use that kind of code through the "listing" file of the "Product" view of your front-end template via "Hikashop->Display->Views":

<?php 
	$user = JFactory::getUser();
	if($user->guest){ 
		$categoryToDisplay = ID_OF_THE_CATEGORY_TO_DISPLAY;
		$newRows = array();
		//We check if a displayed product is on the public category
		foreach($this->rows as $displayedProduct){
			foreach($displayedProduct->categories as $productCategory){
				if($productCategory->category_id == $categoryToDisplay){
					$newRows[] = $displayedProduct;
				}
			}
		}
		//We prevent un-authorized product to display
		$this->rows = $newRows;
		//We displau error message if no products are available
		if(empty($this->rows))
			echo '<a class="btn btn-primary" href="/register">Please Register</a> or <a class="btn btn-primary"  href="/login">Go To Login</a>';
	}
?>
Note that you'll have to replace the "ID_OF_THE_CATEGORY_TO_DISPLAY" by the category of the ID that is public.

Please Log in or Create an account to join the conversation.

  • Posts: 447
  • Thank you received: 20
9 years 6 months ago #231397

Hi Mohamed

I have addedd the code as suggestedd but I still get products appearing on the other pages.

Category Access is set as Guest. I set one product as Guest. The menu items are also set as Guest. The code for the product listig div is below.

<?php
/**
 * @package  HikaShop for Joomla!
 * @version  2.1.3
 * @author  hikashop.com
 * @copyright  (C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license  GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?> <?php
if(!$this->module && isset($this->element->category_canonical) && !empty($this->element->category_canonical)){
  $parsedCanonical = parse_url($this->element->category_canonical);
  $parsedCurrent = parse_url(JURI::base());

  if(!isset($parsedCanonical['query']))
    $endUrl = $parsedCanonical['path'];
  else
    $endUrl = $parsedCanonical['path'].'?'.$parsedCanonical['query'];

  $canonicalUrl = $parsedCurrent['scheme'].'://'.$parsedCurrent['host'].$endUrl;

  $doc = JFactory::getDocument();
  $doc->addCustomTag( '<link rel="canonical" href="'.$canonicalUrl.'" />' );
}

if(hikashop_level(2) && JRequest::getVar('hikashop_front_end_main',0) && JRequest::getVar('task')=='listing' && $this->params->get('show_compare')) {?>
<script type="text/javascript">
<!--
var compare_list = {length: 0};
function setToCompareList(product_id,name,elem) {
  var compareBtn = document.getElementById('hikashop_compare_button');
  if( compare_list[product_id] ) {
    var old = compare_list[product_id];
    compare_list[product_id] = null;
    compare_list.length--;
    if( elem == null ) elem = old.elem;
    var nn = elem.nodeName.toLowerCase();
    if( nn == 'a' )
      elem.innerHTML = "<?php echo JText::_('ADD_TO_COMPARE_LIST');?>";
    else if( nn == 'input' )
      elem.checked = false;
  } else {
    if(compare_list.length < <?php echo $this->config->get('compare_limit',5); ?> ) {
      compare_list[product_id] = {name: name, elem: elem};
      compare_list.length++;
      var nn = elem.nodeName.toLowerCase();
      if( nn == 'a' )
        elem.innerHTML = "<?php echo JText::_('REMOVE_FROM_COMPARE_LIST');?>";
      else if( nn == 'input' )
        elem.checked = true;
    } else {
      alert("<?php echo JText::_('COMPARE_LIMIT_REACHED');?>");
      elem.checked = false;
    }
  }
  if(compare_list.length == 0 ) {
    compareBtn.style.display = 'none';
  } else {
    compareBtn.style.display = '';
  }
  return false;
}
function compareProducts() {
  var url = '';
  for(var k in compare_list) {
    if( compare_list[k] != null && k != 'length' ) {
      if( url == '' )
        url = 'cid[]=' + k;
      else
        url += '&cid[]=' + k;
    }
  }
  window.location = "<?php
    $u = hikashop_completeLink('product&task=compare'.$this->itemid,false,true);
    if( strpos($u,'?')  === false ) {
      echo $u.'?';
    } else {
      echo $u.'&';
    }
  ?>" + url;
  return false;
}
do_nothing( function() {
    $$('input.hikashop_compare_checkbox').each(function(el){
    el.checked = false;
  });
});
//-->
</script>
<?php }

ob_start();
if(version_compare(JVERSION,'1.6','<')){
  $title = 'show_page_title';
}else{
  $title = 'show_page_heading';
}
$titleType = 'h1';
if($this->module){
  $title = 'showtitle';
  $titleType = 'h2';
}

if($this->params->get($title) && JRequest::getVar('hikashop_front_end_main',0) && (!$this->module || $this->pageInfo->elements->total)){
  $name = $this->params->get('page_title');
  if($this->module){
    $name = $this->params->get('title');
  }elseif($this->params->get('page_heading')){
    $name = $this->params->get('page_heading');
  }
  ?>
  <<?php echo $titleType; ?>>
  <?php echo $name; ?>
  </<?php echo $titleType; ?>>
  <?php
}

  if(($this->params->get('show_image') && !empty($this->element->file_path))|| ($this->params->get('show_description',!$this->module)&&!empty($this->element->category_description))){
    ?>
    <div class="hikashop_category_description">
    <?php
    if($this->params->get('show_image') && !empty($this->element->file_path)){
      jimport('joomla.filesystem.file');
      if(JFile::exists($this->image->getPath($this->element->file_path,false))){
      ?>
      <img src="<?php echo $this->image->getPath($this->element->file_path); ?>" class="hikashop_category_image"/>
      <?php
      }
    }
    if($this->params->get('show_description',!$this->module)&&!empty($this->element->category_description)){
      ?>
      <div class="hikashop_category_description_content">
      <?php echo JHTML::_('content.prepare',$this->element->category_description); ?>
      </div>
      <?php
    }
  ?></div><?php
  }
  if(!empty($this->fields)){?>
    <div id="hikashop_category_custom_info_main" class="hikashop_category_custom_info_main">
      <h4><?php echo JText::_('CATEGORY_ADDITIONAL_INFORMATION');?></h4>
      <table width="100%">
      <?php
      $this->fieldsClass->prefix = '';
      foreach($this->fields as $fieldName => $oneExtraField) {
        if(!empty($this->element->$fieldName)){ ?>
        <tr class="hikashop_category_custom_<?php echo $oneExtraField->field_namekey;?>_line">
          <td class="key">
            <span id="hikashop_category_custom_name_<?php echo $oneExtraField->field_id;?>" class="hikashop_category_custom_name">
              <?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
            </span>
          </td>
          <td>
            <span id="hikashop_category_custom_value_<?php echo $oneExtraField->field_id;?>" class="hikashop_category_custom_value">
              <?php echo $this->fieldsClass->show($oneExtraField,$this->element->$fieldName); ?>
            </span>
          </td>
        </tr>
      <?php }
        }?>
      </table>
    </div>
<?php }

$display_filters = $this->params->get('display_filters', -1);
if($display_filters=='-1'){
  $config =& hikashop_config();
  $display_filters=$config->get('show_filters');
}
if(hikashop_level(2) && JRequest::getVar('hikashop_front_end_main',0) && JRequest::getVar('task','listing')=='listing' && $display_filters=='1'){
   $this->setLayout('filter');
   $htmlFilter = $this->loadTemplate();
}

if(!empty($htmlFilter)&&@$_GET['task']!='category') echo $htmlFilter;

$this->setLayout('listing');

$layout_type = $this->params->get('layout_type');
if(empty($layout_type)) $layout_type = 'div';
$html = $this->loadTemplate($layout_type);
if(!empty($html)){
  if(!empty($htmlFilter)&&@$_GET['task']=='category') echo $htmlFilter;
  ?>
  <div class="hikashop_products_listing">
    <?php if(JRequest::getVar('hikashop_front_end_main',0) && JRequest::getVar('task')=='listing' && $this->params->get('show_compare')) {?>
      <div id="hikashop_compare_zone" class="hikashop_compare_zone">
        <?php
        $empty='';
        $params = new HikaParameter($empty);
        echo $this->cart->displayButton(JText::_('COMPARE_PRODUCTS'),'compare_button',$params,'#','compareProducts();return false;','style="display:none;" id="hikashop_compare_button"',0,1,' hikashop_compare_button'); ?>
      </div>
    <?php }
    echo $html; ?>
  </div>
<?php }
$html = ob_get_clean();
if(!empty($html)){ ?>
  <div id="<?php echo $this->params->get('main_div_name');?>" class="hikashop_category_information hikashop_products_listing_main">
    <?php echo $html; ?>
  </div>
<?php }
if(!$this->module){ ?>
<div class="hikashop_submodules" style="clear:both">
<?php if(!empty($this->modules)){
    jimport('joomla.application.module.helper');
    foreach($this->modules as $module){
      echo JModuleHelper::renderModule($module);
    }
  } ?><?php 
	$user = JFactory::getUser();
	if($user->guest){ 
		$categoryToDisplay = 45;
		$newRows = array();
		//We check if a displayed product is on the public category
		foreach($this->rows as $displayedProduct){
			foreach($displayedProduct->categories as $productCategory){
				if($productCategory->category_id == $categoryToDisplay){
					$newRows[] = $displayedProduct;
				}
			}
		}
		//We prevent un-authorized product to display
		$this->rows = $newRows;
		//We displau error message if no products are available
		if(empty($this->rows))
			echo '<a class="btn btn-primary" href="/register">Please Register</a> or <a class="btn btn-primary"  href="/login">Go To Login</a>';
	}
?>
</div>
<?php } ?>

Your advice appreciated

Dave

Please Log in or Create an account to join the conversation.

  • Posts: 84307
  • Thank you received: 13701
  • MODERATOR
9 years 6 months ago #231419

Hi,

That code is to filter out the products before they get displayed. If you put it at the end of the listing view file, the products will already be displayed when they get filtered.
So instead of adding the code at the end of the listing view file, you should add it at the top.

Please also note that we're far from user support here. This is completely custom development which is outside of the support we're bound to provide.
For such code customizations, please contact a third party developer to help you.

Please Log in or Create an account to join the conversation.

  • Posts: 447
  • Thank you received: 20
9 years 6 months ago #231458

Hi

well I have tried that option as well and it still does not work. Maybe this should be added as a feature/option within Hikashop.

I struggle to see why the product is showing in other categories which require registration.

Dave B)

Please Log in or Create an account to join the conversation.

Time to create page: 0.097 seconds
Powered by Kunena Forum