Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Limit Groups to certain manufactures
 
bsboard
Jr. Member
 
Total Posts:  15
Joined:  2008-03-18
 

I am running a B2B implementation of magento, which is working quite well. I have been able to reduce the checkout to only 3 steps (billing address, shipping address, order review) and have blocked the site access to logged in users only. However, now I have another hurdle.

What I need, is to be able to limit manufactures to certain users. Essentially what I would like to do is when I create a user (because users are not allowed to register themselves) have checkboxes for all the manufactures in the database. Then I could select which manufactures this user should have access to.

Then when the user browses the site, they don’t see any products from that manufacture. I really don’t care if the filtering is done on database query, or display only. (by that, i mean if a page has 10 products, but 3 are removed because of this manufacture restriction, i don’t mind if there are only 7 products on the page). It could even set the quantity to zero, or remove the ‘add to cart’ button. Just some way to stop the user from purchasing those products.

Does anyone have any ideas of where to start? I am not simply looking for handouts, and will be spending a lot of time trying to do this myself. Any help I could get from community members along the way would be fantastic, and I’ll post my progress here for everyone.

Again, at first If anyone can point me in the direction of where to start, what files I should be looking at, or a plan of action of what needs to be modified, it would be much appreciated.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
bsboard
Jr. Member
 
Total Posts:  15
Joined:  2008-03-18
 

Ok, here is my plan of action thus far (let me know what you think). I found in this thread that you can add attributes to a user via the eav_attribute table. Since most users will be able to access everything, I plan on making a ‘manufacture_blacklist’ field. If ‘panasonic’ is in this field, then the user cannot see any panasonic products. This can be just a comma seperated list, and I can use string functions to check if a given manufacture is displayed in this list.

From what I understand adding it to that table will make it show up in the admin area, so that handles adding/updating/deleting the restrictions for each user. Now I just have to figure out how to make it work. I am thinking while I am looping over products, i can compare the current products manufacture to the blacklist, and display accordingly. My question is, where is this looping located? How do I access the user blacklist field from here?

 
Magento Community Magento Community
Magento Community
Magento Community
 
bsboard
Jr. Member
 
Total Posts:  15
Joined:  2008-03-18
 

Alright, I added a row to the eav_attribute table which then gave a blacklist attribute to each user, and automatically made it manageable via the backend. Below is the specific data I added tot he table (first value auto-generated)

581    1    manufacture_blacklist    \N    \N    text    \N    \N    text    Manufacturer Blacklist    \N    \N    1    1    0    0    \N    0    0    0    1    0    1 1 0

Next step was to make it useful. In the catalog.xml file, I had to add some code to make my new attribute available on the category list pages. I followed the information in this thread. I added the following under each catalog/product_list block

<action method="addAttribute"><code>manufacturer</code></action>

Now that its available to me, I have to edit the list.phtml file. First step is to query for the banlist. Do this OUTSIDE of the foreach loop, because we only need to grab the data once.

<?php 
   $banList 
Mage::getSingleton('customer/session')->getCustomer()->getManufacture_blacklist();
   
$banList explode(','$banList);
   foreach(
$banList as $key=>$val)
      
$banList[$key] trim(strtolower($val));
?>

Now we have an array of banned manufactures. Inside the foreach loop, we just need to check if the product is banned, and if so, continue the loop (and therefore not display anything). The beginning of my foreach loop looks like this:

<?php foreach ($_productCollection as $_product): ?>
   <? 
if(in_array(strtolower($_product->getAttributeText('manufacturer')), $banList)) continue;?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
bsboard
Jr. Member
 
Total Posts:  15
Joined:  2008-03-18
 

Ok, so that is all working, but I still need help (not that I expect any, as it seems I always talk to myself on this forum).

Ideally I would like to filter the manufactures list in the “Shop By” filtering to not show blacklisted item. No sense in having “Panasonic” show up if clicking it will pull up an empty page (because no items will be shown). I would also LOVE to be able to filter on the query side rather then display side, or have some way of having the pagination be correct on product lists. Not a deal breaker, but if anyone can point me in a direction to accomplish that, i’d be appreciative.

later

 
Magento Community Magento Community
Magento Community
Magento Community
 
oldskool73
Jr. Member
 
Total Posts:  9
Joined:  2008-06-25
 

hi, there’s at least one person (me) reading, and I found your snippets handy, I’m currently trying to limit my catalog to only display items to certain pre-approved groups.

I’ve added a simpe check in /app/code/local/Mage/Catalog/Helper/Product.php (& Catalog.php) in the ‘canShow’ function to prevent them being shown to some groups, seems to work for my needs, is there perhaps a similar ‘canShow’ function you could use for the list view items to prevent them showing up?

p.s. ... I saw in your first comment you’d already restricted catalog access to registered users, how did you go about it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
bsboard
Jr. Member
 
Total Posts:  15
Joined:  2008-03-18
 

thanks for the tip on the ‘canShow’, I’ll check that out when I get a chance.

As for the restricted catalog access, heres what I did: In the /template/page folder, insert the following code to all files, right after the body tag

if (Mage::app()->isInstalled() && !Mage::getSingleton('customer/session')->isLoggedIn()) 
      
{
         ?>
         
<form action="//index.php/customer/account/loginPost/" method="post" id="login-form">
         <
div class="wrapper">
            <
div class="middle col-1-layout">
               <
div class="content">
                  <
h1 id="logo">
                     <
a href="http://www.your_url.com//"><img alt="Magento Commerce" src="full_path_to_logo.gif"/></a>
                  </
h1>    
                  <
br style='clear:both;'/>
                  <
fieldset class='group-select'>                       
                     <
h4 class='legend'>Login to Site</h4>
                     <
p>Please enter your Site account details below.</p>
                     <
ul class="form-list">
                        <
li>
                           <
label for="email"><?php echo $this->__('Email Address'?> <span class="required">*</span></label><br/>
                           <
input name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" title="<?php echo $this->__('Email Address') ?>" id="email" type="text" class="input-text required-entry" style="width:250px;"/>
                        </
li>
                        <
li>
                           <
label for="pass"><?php echo $this->__('Password'?> <span class="required">*</span></label><br/>
                           <
input name="login[password]" type="password" class="input-text required-entry validate-password" id="pass" style="width:250px;"/>
                        </
li>
                     </
ul>
                     <
class="required"><?php echo $this->__('* Required Fields'?></p>
                     <
div class="button-set">        
                        <
button class="form-button" type="submit" name="send" id="send2"><span><?php echo $this->__('Login'?></span></button>
                     </
div>                     
                  </
fieldset>
               </
div>
            </
div>
         </
div>
         </
form>
         <
script type="text/javascript">
            var 
dataForm = new VarienForm('login-form'true);
         
</script>
      <?php
      }
      
else
      
{

so essentially, on the display side I check if they are logged in. If not, i display a login form which posts to the usual login page. If they are logged in, then it hits the else statement and displays the page as normal.

Hope this helps, and glad to know somebody cares!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top