PHP Magento Tips

Hide Price, Add to cart, Wishlist, Compare and Reviews for Non registered customers in Magento

Rate this posting:
{[['']]}


Sometimes store owners wants to hide price for non-registered customer and encourage them to invite for registration into their store. Because without registering into store, customer can not see the catalog prices.

This can be done very easily in Magento. Here i created one extension for it.

Step 1: Create Module Initialization file. Create file in app/etc/modules/Vijay_Hideprice.xml and add below code in it.

<?xml version="1.0"?>
<config>
    <modules>
        <Vijay_Hideprice>
            <active>true</active>
            <codePool>community</codePool>
        </Vijay_Hideprice>
    </modules>
</config>

Step 2: Create Module Configuration file. Create file in app/code/community/Vijay/Hideprice/etc/config.xml and add below code in it.

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Vijay_Hideprice>
            <version>1.0.0</version>
        </Vijay_Hideprice>
    </modules>
    <global>
        <blocks>
            <rating>
                <rewrite>
                    <entity_detailed>Vijay_Hideprice_Block_Entity_Detailed</entity_detailed>
                </rewrite>
            </rating>
            <catalog>
                <rewrite>
                    <layer_view>Vijay_Hideprice_Block_Layer_View</layer_view>
                </rewrite>
            </catalog>
        </blocks>
        <helpers>
            <vijay_hideprice>
                <class>Vijay_Hideprice_Helper</class>
            </vijay_hideprice>
        </helpers>
    </global>
    <frontend>
        <layout>
            <updates>
                <vijay_hideprice>
                    <file>vijay/hideprice.xml</file>
                </vijay_hideprice>
            </updates>
        </layout>
    </frontend>
    <default>
        <priceconfig>
            <module_config>
                <active>1</active>
            </module_config>
            <priceareas>
                <price>0</price>
                <addtocart>0</addtocart>
                <wc>0</wc>
                <review>0</review>
            </priceareas>
        </priceconfig>
    </default>
</config>
 
Step 3: Create adminhtml.xml file. Create file in app/code/community/Vijay/Hideprice/etc/adminhtml.xml and add below code in it.

<?xml version="1.0"?>
<config>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <priceconfig>
                                        <title>Hide Price Configuration</title> 
                                    </priceconfig>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>

Step 4: Create system.xml file. Create file in app/code/community/Vijay/Hideprice/etc/system.xml and add below code in it.

<?xml version="1.0"?>
<config>
     <tabs>
        <vijayhideprice translate="label">
            <label>Vijay Hide Price</label>
            <sort_order>150</sort_order>
        </vijayhideprice>
    </tabs>
    <sections>
        <priceconfig translate="label" module="adminhtml">
            <label>Hide Price For Non Registered</label>
            <tab>vijayhideprice</tab>
            <sort_order>10</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <priceareas>
                    <label>Hide Price Configuration</label>
                     <sort_order>52</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>            
                    <fields>
                        <price translate="label comment">
                            <label>Show Price</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>53</sort_order>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                              <comment>Yes to show price for non register user</comment>
                        </price>
                        <addtocart translate="label comment">
                            <label>Show Add to cart</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>54</sort_order>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                             <comment>Yes to show addtocart for non register user</comment>
                        </addtocart>
                        <wc translate="label comment">
                            <label>Show Wishlist and Compare</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>55</sort_order>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Yes to show  compare and wishlist for non register user</comment>
                        </wc>   
                         <review translate="label comment">
                            <label>Show Reviews</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>56</sort_order>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Yes to show review for non register user</comment>
                        </review>                     
                    </fields>
            </priceareas>
            </groups>
            <groups>
                 <module_config translate="label">
                     <label>Hide Price For Non Register Users</label>
                     <sort_order>50</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <active translate="label comment">
                            <label>Enable Module</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>51</sort_order>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment><![CDATA[
    <script type="text/javascript">
        document.observe("dom:loaded",function(){
            if($('priceconfig_module_config_active').value == 0){
                 Element.up($('priceconfig_priceareas')).hide();
            }
        });
        Event.observe('priceconfig_module_config_active', 'change', function(){
            if(this.value == 1){
                Element.up($('priceconfig_priceareas')).show();
            }else if(this.value == 0){
                Element.up($('priceconfig_priceareas')).hide();
            }
        })
    </script>]]>
</comment>
                        </active>
                    </fields>    
                 </module_config>
            </groups>
            
         </priceconfig>
 </sections>
</config>

Step 5: Create file in app/code/community/Vijay/Hideprice/Block/Entity/Detailed.php and add below code in it.

<?php

class Vijay_Hideprice_Block_Entity_Detailed extends Mage_Rating_Block_Entity_Detailed

{

    public function __construct()

    {

        parent::__construct();        

        $this->setTemplate('vijay/hideprice/rating/detailed.phtml');

    }

}

Step 6: Create file in app/code/community/Vijay/Hideprice/Block/Layer/View.php and add below code in it.

<?php
class Vijay_Hideprice_Block_Layer_View extends Mage_Catalog_Block_Layer_View
{
    /**
     * Get all layer filters
     *
     * @return array
     */
    public function getFilters()
    {
        $filters = array();
        if ($categoryFilter = $this->_getCategoryFilter()) {
            $filters[] = $categoryFilter;
        }
        
        $filterableAttributes = $this->_getFilterableAttributes();
        
        foreach ($filterableAttributes as $attribute) {
            if (Mage::helper('vijay_hideprice')->isEnabled()) {
                if (!Mage::helper('vijay_hideprice')->isAllowedToSeePrices()) {
                    if ($attribute->getAttributeCode() == 'price'){
                        continue;
                    }
                }
            }
            $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
        }

        return $filters;
    }
}

Step 7:  Create file in app/code/community/Vijay/Hideprice/Helper/Data.php and add below code in it.

<?php
class Vijay_Hideprice_Helper_Data extends Mage_Core_Helper_Abstract
{
    const GENERAL_IS_ENABLED = 'priceconfig/module_config/active';
    const CAN_SEE_PRICE = 'priceconfig/priceareas/price';
    /**
     * @param null|int|Mage_Core_Model_Store $store
     *
     * @return bool
     */
    public function isEnabled($store = null)
    {
        $isConfigEnabled = Mage::getStoreConfigFlag(self::GENERAL_IS_ENABLED, $store);
        $isModuleEnabled = $this->isModuleEnabled();
        $isModuleOutputEnabled = $this->isModuleOutputEnabled();
        return $isConfigEnabled && $isModuleEnabled && $isModuleOutputEnabled;
    }
    public function isAllowedToSeePrices($store = null)
    {
        $canSeePrice = Mage::getStoreConfigFlag(self::CAN_SEE_PRICE, $store);
        return $canSeePrice;
    }
}

Step 8: Create front end layout file. Create file in app/design/frontend/base/default/layout/vijay/hideprice.xml and add below code in it.

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <!-- Blocks for hiding the price of the product from the end user starts -->
        <reference name="catalog_product_price_template">
            <action method="addPriceBlockType" ifconfig="priceconfig/module_config/active">
                <type>simple</type>
                <block>catalog/product_price</block>
                <template>vijay/hideprice/price.phtml</template>
            </action>
            <action method="addPriceBlockType" ifconfig="priceconfig/module_config/active">
                <type>grouped</type>
                <block>catalog/product_price</block>
                <template>vijay/hideprice/price.phtml</template>
            </action>
            <action method="addPriceBlockType" ifconfig="priceconfig/module_config/active">
                <type>configurable</type>
                <block>catalog/product_price</block>
                <template>vijay/hideprice/price.phtml</template>
            </action>
            <action method="addPriceBlockType" ifconfig="priceconfig/module_config/active">
                <type>virtual</type>
                <block>catalog/product_price</block>
                <template>vijay/hideprice/price.phtml</template>
            </action>
            <action method="addPriceBlockType" ifconfig="priceconfig/module_config/active">
                <type>bundled</type>
                <block>catalog/product_price</block>
                <template>vijay/hideprice/price.phtml</template>
            </action>
        </reference>
        <!-- Blocks for hiding the price of the product from the end user ends -->
    </default>
    <catalog_category_default>
        <reference name="product_list">
            <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                <template>vijay/hideprice/list.phtml</template>
            </action>
            <action method="addReviewSummaryTemplate" ifconfig="priceconfig/module_config/active">
                <type>default</type>
                <template>vijay/hideprice/summary.phtml</template>
            </action>
            <action method="addReviewSummaryTemplate" ifconfig="priceconfig/module_config/active">
                <type>short</type>
                <template>vijay/hideprice/summary_short.phtml</template>
            </action>
        </reference>
    </catalog_category_default>
    <catalog_category_layered>
        <reference name="product_list">
            <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                <template>vijay/hideprice/list.phtml</template>
            </action>
        </reference>
    </catalog_category_layered>
    <catalog_product_view>
        <reference name="product.info.addtocart">
            <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                <template>vijay/hideprice/addtocart.phtml</template>
            </action>
        </reference>
        <reference name="product.info">
            <reference name="product.reviews">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/review/product/view/list.phtml</template>
                </action>
            </reference>
        </reference>
    </catalog_product_view>
    <catalog_product_view>
        <reference name="product.info.addto">
            <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                <template>vijay/hideprice/addto.phtml</template>
            </action>
        </reference>
    </catalog_product_view>
    <catalog_product_view>
        <reference name="content">
            <reference name="product.info">
                <action method="addReviewSummaryTemplate" ifconfig="priceconfig/module_config/active">
                    <type>default</type>
                    <template>vijay/hideprice/summary.phtml</template>
                </action>
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/view.phtml</template>
                </action>
            </reference>
        </reference>
        <reference name="product.info.upsell">
            <action method="addReviewSummaryTemplate" ifconfig="priceconfig/module_config/active">
                <type>default</type>
                <template>vijay/hideprice/summary.phtml</template>
            </action>
        </reference>
        <reference name="right">
            <reference name="catalog.product.related">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/related.phtml</template>
                </action>
            </reference>
        </reference>
    </catalog_product_view>
    <catalog_product_compare_index>
        <reference name="catalog.compare.list">
            <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                <template>vijay/hideprice/compare/list.phtml</template>
            </action>
        </reference>
    </catalog_product_compare_index>
    <tag_product_list translate="label">
        <reference name="content">
            <reference name="tag_products">
                <reference name="search_result_list">
                    <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                        <template>vijay/hideprice/tag/list.phtml</template>
                    </action>
                </reference>
            </reference>
        </reference>
    </tag_product_list>
    <review_product_list translate="label">
        <reference name="content">
            <reference name="product.info">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/view.phtml</template>
                </action>
            </reference>
            <reference name="product.info.addtocart">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/addtocart.phtml</template>
                </action>
            </reference>
            <reference name="product.info.addto">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/addto.phtml</template>
                </action>
            </reference>
            <reference name="product_review_list.count">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/review/product/view/count.phtml</template>
                </action>
            </reference>
            <reference name="product.info.product_additional_data">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/review/product/view/list.phtml</template>
                </action>
            </reference>
        </reference>
    </review_product_list>
    <catalogsearch_result_index translate="label">
        <reference name="content">
            <reference name="search_result_list">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/list.phtml</template>
                </action>
            </reference>
        </reference>
    </catalogsearch_result_index>
    <catalogsearch_advanced_result translate="label">
        <reference name="content">
            <reference name="search_result_list">
                <action method="setTemplate" ifconfig="priceconfig/module_config/active">
                    <template>vijay/hideprice/list.phtml</template>
                </action>
            </reference>
        </reference>
    </catalogsearch_advanced_result>
</layout>

Step 9: Now, as per the layout.xml, add .phtml file accordingly.

Create folder inside app/design/frontend/base/default/template/vijay/hideprice and add all .phtml files in it.

You can download all .phtml files from  Github.

Download Complete Module from https://github.com/vijayrami/Hideprice_AddtoCart_Wishlist_Non_Registered_Customer/
0 Comments On "Hide Price, Add to cart, Wishlist, Compare and Reviews for Non registered customers in Magento"

Back To Top