Does a quality product matter when branding your business? Absolutely. Is it possible to do a great job branding a terrible product? it is, but I would argue that this company would not stick around for too long (at least in today's environment)
Your brand is a promise that you make to your customers. In my opinion, it is essential that a major component of that promise is an exceptional product.
There are certainly historical cases of bad products that have been well branded and have realized success ($$), but these instances are dwindling more and more with the transparency and accountability brought about by social media and optionality. If I have a bad brand experience, oh well, I'll just move right on to their competitor.
To take this one step further, I would argue that having an exceptional product should be the very first step to forming your business and your brand should be built on the cornerstone of the value that you are offering with this outstanding product.