Cart Quantity Error on Uninitialized Cart

* Moved remaining product quantity logic from class to the existing standalone function. Class function now calls standalone function rather than the other way around.

* Global cart was being accessed to in the standalone function even though it may not have been initialized.