public function apply()
    {
        if (!isset($_SESSION) || empty($_SESSION)) {
            return $this;
        }


        foreach ($this->messageBlocks as $messageBlock) {
            foreach ($messageBlock->getMessagesByStorage() as $storageType => $messages) {
                $this->addMessagesByStorageType($storageType, $messages);
            }
        }

        foreach ($this->scheduledMessages as $storageType => $messages) {
            $this->addMessagesByStorageType($storageType, $messages);
        }

        $types = array_keys($this->getMessageTypes());
        $updatedStorages = [];

        foreach ($types as $type) {
            $storage = $this->getStorageByMessageType($type);
            if ($storage && $storage->getMessages(false)->getItems()) {
                $updatedStorages[] = $type;
            }
        }


        if ($updatedStorages) {
            Mage::getSingleton('ecomdev_varnish/cookie')->set(
                self::COOKIE_NAME, implode(',', $updatedStorages)
            );
        }

        return $this;
    }