How can I Disable the "add to cart" when user is not logged in.
-
Have you tried googling for same? You will get so many answers for same. Try this, excellencemagentoblog.com/blog/2013/02/14/…– Pallavi SinhaCommented Jul 25, 2016 at 8:10
-
Do you wat to hide Add to cart button OR just redirect to Login page if not logged in while adding to cart ?– Anil SutharCommented Jul 25, 2016 at 9:00
-
i want to Redirect to Login page if not logged in while adding to cart– Harshil ParekhCommented Jul 25, 2016 at 9:15
-
try free module magentocommerce.com/magento-connect/…– AbdulCommented Jul 25, 2016 at 10:17
2 Answers
Please check with below module, which is provide to not login user hide product price.
https://github.com/Tartilas/Magento-hideprice
Also if you want to do via pragmatically than check with below event. Using below event to set price equals to zero
first event :
<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>
second event :
<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>
simply check if user is not logged in (Observer.php) and set final price equals to zero
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 :
if($_product->getFinalPrice() == 0 || $_product->getPrice() == 0){
echo '<span class="login_for_price"><b>Login to See Price</b><br></span>'; return; }
I hope its work for you.
In Magento version 2 you can disable checkout for guest user from admin panel->store->configuration->sales->checkout.
-
-
You mention magento version in tag also mention in description because now magento 2 is released and developer used magento 2 for development. Commented Jul 26, 2016 at 7:58
-
-