I'm trying to remove the notice in the cart about how the customer must have a subtotal of say $20 in their cart however I still want the restriction there for when the customer tries to go into the cart (I personally think we shouldn't remove the notice but the order comes down from up high)
At the moment, this is my code
$messages = $this->getMessagesBlock()->getMessages();
unset($messages[1]);
$this->getMessagesBlock()->setMessages($messages);
echo $this->getMessagesBlock()->getGroupedHtml();
I've been testing the code by going into the cart with 1 item and using the update cart button when they new qty is something stupid like 99999999999999
from the var dump i did of $this->getMessagesBlock()
there is a protected piece of data called _messages, using getMessages()
return an array of 2 items, one is the error about the qty at index 0, the other is an notice about the minimum purchase.
I tried using unset($messages[1]);
to remove the notice as a test to see if I could remove it. If it worked, I would later fix it up to search for the notice and remove it no matter where in the array it is.
I called setMessages($messages)
and did another var dump. I can see it's been put back into $this->getMessagesBlock()
so i thought it would work, however nothing appeared.
I did a var_dump
of $this->getMessagesBlock()->getGroupedHtml()
and it shows an empty string.
I'm wondering what i could be doing wrong here or if there is a better way to just remove the message i don't want.
this is what is vardumped from $messages
array (size=2)
0 =>
object(Mage_Core_Model_Message_Error)[196]
protected '_type' => string 'error' (length=5)
protected '_code' => string 'The requested quantity for "6899WSAND" is not available.' (length=56)
protected '_class' => string '' (length=0)
protected '_method' => string '' (length=0)
protected '_identifier' => null
protected '_isSticky' => boolean false
1 =>
object(Mage_Core_Model_Message_Notice)[820]
protected '_type' => string 'notice' (length=6)
protected '_code' => string '' (length=0)
protected '_class' => string '' (length=0)
protected '_method' => string '' (length=0)
protected '_identifier' => null
protected '_isSticky' => boolean false
$message[1]
does not unset the object variables, just the array it returned. So you can't do it this way.