You can disable the checkout button by adding the following to the quote object (in the event your use for your observer sales_quote_save_before
):
$quote->setHasError(true);
$quote->addErrorInfo(
'error',
'checkout',
null,
Mage::helper('checkout')->__('The maximum order qty is %d', 500),
null
);
This will display the error message in the cart and remove the buttons. This solution is also used by the catalog_inventory module when a product qty is over the available qty.
First of all I want to say that this may be bad for business.
It's not a good idea to disable the button.
If you don't want guest users to be able to order just disable the guest checkout from System->Configuration->Checkout->Checkout Options->Allow Guest Checkout.
Then, the users will see the checkout page but they will be forced to login or create an account to perform the checkout process.
But if you insist here is how you can do it.
You can override the method: Mage_Checkout_Block_Onepage_Link::isDisabled
.
Add this in the config.xml
of one of your modules under the <global>
tag.
<blocks>
<checkout>
<rewrite>
<onepage_link>[Namespace]_[Module]_Block_Onepage_Link</onepage_link>
</rewrite>
</checkout>
</blocks>
Then create the file [Namespace]/[Module]/Block/Onepage/Link.php
with this content
<?php
class [Namespace]_[Module]_Block_Onepage_Link extends Mage_Checkout_Block_Onepage_Link {
public function isDisabled() {
if (parent::isDisabled()) {
return true;
}
return !Mage::getSingleton('customer/session')->isLoggedIn();
}
}
Now you have to make sure that only logged in customer can access the checkout page. Because if you only disable the button they will be able to use the direct link.
observe the event controller_action_predispatch_checkout_onepage_index
.
You can do that by adding this in the same config.xml as above inside the <frontend>
tag:
<events>
<controller_action_predispatch_checkout_onepage_index>
<observers>
<[namespace]_[module]>
<class>[Namespace]_[Module]_Model_Observer</class>
<method>checkCustomerLogin</method>
</[namespace]_[module]>
</observers>
</controller_action_predispatch_checkout_onepage_index>
</events>
And create the following file [Namespace]/[Module]/Model/Observer.php
:
<?php
class [Namespace]_[Module]_Model_Observer {
public function checkCustomerLogin() {
if(! Mage::helper('customer')->isLoggedIn()){
Mage::getSingleton('checkout/session')->addError(Mage::helper('checkout')->__('Only logged in customers can checkout'));
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart/'));
}
}
}
Best Answer
if you want to know in which file you need to hide the text "Proceed to checkout" , you can use Magento template path hints here : system> configuration > Advanced > Developer ....
than switch to current store under Current configuration scope
than enable template path hints under Debug , than you can see from which file the text "Proceed to checkout" is coming from....
you can see below links for more information :
https://stackoverflow.com/questions/24273443/in-magento-1-9-0-0-how-can-i-enable-template-path-hint
http://support.magerewards.com/article/1534-how-do-i-turn-on-template-path-hints