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
Printable View
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
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.
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.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>
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)
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.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 }?>
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.
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.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;
}
?>
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)
Replace it withPHP 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; ?>
Another Way to Hide Price for Not Logged in User (Using Event to Set Price Equals to Zero) :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 }?>
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
And on phtml we can also check :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);
}
}
}
PHP Code:
if($_product->getFinalPrice() == 0 || $_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 :)
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
I think you should use ready extension than try yourself, this should work well enough http://kamtechco.net/products/magent...extension.html
I now coding so its no a issue i dont mind chopping and changing i just need to find the right files
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 ?
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
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!
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.
Hi! You can read this article about how to hide prices in Magento: https://www.itoris.com/blog/magento/...n-magento.html
Client authorizations - Computer Definition. The approval given to clients that empowers them to get to explicit assets on the system, for example, information documents, applications, printers and scanners.
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
The approval given to clients that empowers them to get to explicit assets on the system, for example, information records, applications, printers and scanners. Client consents likewise assign the sort of access; for instance, can information just be seen (perused just) or would they be able to be refreshed (perused/compose)