Magento Expert Forum - Improve your Magento experience

Results 1 to 10 of 10

User Permismissions?

  1. #1

  2. #2
    Administrator david's Avatar
    Join Date
    Nov 2012
    Posts
    260
    Thanks
    23
    Thanked 40 Times in 33 Posts

    Smile

    There are 2 solution for what you need:

    1. Use ready magento extensions

    You can try these extensions

    http://kamtechco.net/products/magent...extension.html

    or

    http://www.magentocommerce.com/magen...gistered-users

    2. Do it yoursefl (in the case you are magento developer)

    While we are at it we will also hide the ‘Add to Cart’ buttons everywhere (for guest users). There is no point in hiding the price everywhere and then allowing them to add product to the cart.
    In magento by default price is shown on following places
    • Category list page (where all the product of a category are listed).
    • Product view page (where product details are shown).
    • Compare pop up (where two or more products are compared side by side).

    Override the default magento files.
    Since in this case we only need to override view files (phtml). We need only a very basic module. For module development refer to module development series.
    Price on various places is shown from price.phtml which is located at ‘/app/design/frontend/base/default/template/catalog/product/price.phtml’.

    To override this we need to add the following code in default tags of our frontend layout file.

    HTML Code:
    <default>
    
    			        <reference name="catalog_product_price_template">
    
    			            <action method="addPriceBlockType"><type>simple</type><block>catalog/product_price</block><template>hideprice/price.phtml</template></action>
    
    			            <action method="addPriceBlockType"><type>grouped</type><block>catalog/product_price</block><template>hideprice/price.phtml</template></action>
    
    			            <action method="addPriceBlockType"><type>configurable</type><block>catalog/product_price</block><template>hideprice/price.phtml</template></action>
    
    			            <action method="addPriceBlockType"><type>virtual</type><block>catalog/product_price</block><template>hideprice/price.phtml</template></action>
    
    			            <action method="addPriceBlockType"><type>bundled</type><block>catalog/product_price</block><template>hideprice/price.phtml</template></action>
    
    			        </reference>
    
    			 </default>
    Then copy the default ‘price.phtml’ and place it in the specified location (in our case ‘hideprice/price.phtml’). And the place the following code on top of it.

    PHP Code:
    <?php 

                
    if(!Mage::getSingleton('customer/session')->isLoggedIn()){

                
        echo '<span class="login_for_price"><b>Login to See Price</b></span><br>';

                
        return;

                }

                
    ?>

    This basically hides price for guest users everywhere (since we used override in default tags).
    Now to hide the ‘Add to Cart’ button on category list page. Use the following code to override the default ‘/app/design/frontend/base/default/template/catalog/product/list.phtml’. Add this to your module’s layout file.
    For default

    HTML Code:
    <catalog_category_default>
    
    			         <reference name="product_list">
    
    			             <action method="setTemplate"><template>hideprice/list.phtml</template></action>
    
    			         </reference>
    
    			</catalog_category_default>
    
    			And for layered navigation
    
    			<catalog_category_layered>
    
    			         <reference name="product_list">
    
    			             <action method="setTemplate"><template>hideprice/list.phtml</template></action>
    
    			         </reference>
    
    			</catalog_category_layered>

    Now copy the default ‘list.phtml’ to your module. Replace the following code (around line number-109)


    PHP Code:
    <?php if($_product->isSaleable()): ?>

                                        <button type="button" title="<?php echo $this->__('Add to Cart'?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>

                                    <?php else: ?>

                                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock'?></span></p>

                <?php endif; ?>

    With this.
                
                <?php 

                        if
    (!Mage::getSingleton('customer/session')->isLoggedIn()){

                
                echo '<span class="login_for_details" style="float:left"><b>Login to Add to Cart</b></span>';

                
                }

                
                else{

                
        ?>

                    <?php if($_product->isSaleable()): ?>

                        <button type="button" title="<?php echo $this->__('Add to Cart'?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>

                    <?php else: ?>

                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock'?></span></p>

                    <?php endif; ?>

                    <?php    }?>
    In the above code we just check if the user is logged in. If yes the code runs normally like the default else we display a message accordingly.
    Now to hide the ‘Add to Cart’ button on product detail page. Use the following code to override the default ‘/app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml’. Add this to your modules layout file.


    HTML Code:
    <catalog_product_view>
    
    			    <reference name="product.info.addtocart">
    
    			       <action method="setTemplate"><template>hideprice/addtocart.phtml</template></action>
    
    			   </reference>
    
    			</catalog_product_view>

    Then copy the default ‘addtocart.phtml’ to your module and add the following code on top of it.


    PHP Code:
    <?php 

                
    if(!Mage::getSingleton('customer/session')->isLoggedIn()){

                
        echo '<span class="login_for_details" style="float:left"><b>Login to Add to Cart</b></span>';

                
        return;

                }

                
    ?>
    Similarly to hide the ‘Add to Cart’ on compare page. Default page is at ‘/app/design/frontend/base/default/template/catalog/product/compare/list.phtml’. We use following code in our module’s layout xml file.

    HTML Code:
    <catalog_product_compare_index>
    
    			    <reference name="catalog.compare.list">
    
    			        <action method="setTemplate"><template>hideprice/compare/list.phtml</template></action>
    
    			    </reference>
    
    			</catalog_product_compare_index>

    Then copy the default ‘compare/list.phtml’. look for the following code, it is found in two places line numbers (67 & 118)


    PHP Code:
    <?php if($_item->isSaleable()): ?>

                    <p><button type="button" title="<?php echo $this->__('Add to Cart'?>" class="button btn-cart" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item?>', true)"><span><span><?php echo $this->__('Add to Cart'?></span></span></button></p>

                <?php else: ?>

                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock'?></span></p>

                <?php endif; ?>
    Replace it with


    PHP Code:
    <?php 

                        if
    (!Mage::getSingleton('customer/session')->isLoggedIn()){

                
                echo '<span class="login_for_details" style="float:left"><b>Login to Add to Cart</b></span>';

                
                }

                
                else{

                
        ?>

                    <?php if($_product->isSaleable()): ?>

                        <button type="button" title="<?php echo $this->__('Add to Cart'?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>

                    <?php else: ?>

                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock'?></span></p>

                    <?php endif; ?>

                    <?php    }?>
    Another Way to Hide Price for Not Logged in User (Using Event to Set Price Equals to Zero) :

    To do this We use two events :-



    HTML Code:
    <catalog_product_get_final_price>
    
    			           <observers>
    
    			             <hideprice_catalog_price_observer>
    
    			               <type>singleton</type>
    
    			               <class>Wsc_Postcode_Model_Observer</class>
    
    			               <method>hidePrice</method>
    
    			             </hideprice_catalog_price_observer>
    
    			           </observers>
    
    			         </catalog_product_get_final_price>

    And,

    HTML Code:
    <catalog_product_collection_load_after>
    
    			  <observers>
    
    			    <hprice_catalog_price_observer>
    
    			      <type>singleton</type>
    
    			      <class>Wsc_Postcode_Model_Observer</class>
    
    			      <method>hidePriceCatalog</method>
    
    			    </hprice_catalog_price_observer>
    
    			  </observers>
    
    			</catalog_product_collection_load_after>

    => catalog_product_get_final_price event is used to set final price equal to zero on product while catalog_product_collection_load_after event is used to set final price on catalog page.

    And after that we simply check if user is not logged in (Observer.php) and set final price equals to zero


    PHP Code:
    public function hidePrice($observer){

                
                $event $observer->getEvent();

                
                $product $event->getProduct(); 

                
                if(!Mage::getSingleton('customer/session')->isLoggedIn()){

                
                    $product->setFinalPrice(0);

                
                    $product->setPrice(0);

                
                }

                
                 

                    
    }

                
         

                    public 
    function hidePriceCatalog($observer){

                
            $products $observer->getCollection();

                
         

                        if
    (!Mage::getSingleton('customer/session')->isLoggedIn()){

                
                foreach$products as $product )

                
                {

                
                    $product->setFinalPrice(0);

                
                    $product->setPrice(0);

                
                }

                
            }

                
        
    And on phtml we can also check :


    PHP Code:
    if($_product->getFinalPrice() == || $_product->getPrice() == 0){

                
           echo '<span class="login_for_price"><b>Login to See Price</b><br></span>';

                
           return;

                
       

    That’s all that is required to hide the ‘price’ and ‘add to cart’ button on most of the pages. This is just a basic customization it can be further enhanced to hide other details as well as to hide details from other group of users.

    As always, I would recommend you use ready extension

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I feel like a total NOOB
    ‘/app/design/frontend/base/default/template/catalog/product/price.phtml’.
    I cant seem to locate this file price.phtml.
    I got the same solution on google but this seems to be an older version of magento and not 1.7

  4. #4
    Junior Member rocker's Avatar
    Join Date
    Mar 2013
    Posts
    106
    Thanks
    3
    Thanked 11 Times in 9 Posts

    Default

    I think you should use ready extension than try yourself, this should work well enough http://kamtechco.net/products/magent...extension.html

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I now coding so its no a issue i dont mind chopping and changing i just need to find the right files

  6. #6
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I got the prices off struggling with the add to cart thing.
    after list.phtm is changed should i see the add to cart button at all ?

  7. #7
    Junior Member
    Join Date
    Mar 2014
    Location
    Nashua , United States
    Posts
    102
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Thumbs up

    Quote Originally Posted by JPEG View Post
    Is there anyway i can setup like user permissions.
    I want to be able to hide the prices from guests
    and be viewed by registered users
    Hi,

    You can use the below Magento hide price extension, using this you can restrict the users to view the price of the products.
    Its easy to install and configure in your site.

    http://www.modulebazaar.com/en/magen...extension.html

  8. #8
    Junior Member Amasty's Avatar
    Join Date
    May 2013
    Posts
    397
    Thanks
    1
    Thanked 4 Times in 3 Posts

    Default

    David is right, that can done manually. But if you don't want to code yourself, here are ready-made solutions, like this Hide Price extension. It will help you to hide the prices from particular customer groups, such as not-logged in users.
    Hope that helps!

  9. #9
    Junior Member
    Join Date
    Feb 2015
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    JPEG, any news? Have you coded the feature by yourself?

    Would like to add that you can also use Catalog Permissions extension and can not only hide prices for certain users, but also show different items, prices, categories to specific customers in your Magento store by assigning advanced permissions.

  10. #10
    Junior Member IToris's Avatar
    Join Date
    Jan 2017
    Posts
    207
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi! You can read this article about how to hide prices in Magento: https://www.itoris.com/blog/magento/...n-magento.html

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •