I got this situation that when ever the Customer Login on their account it is redirected to the Cart Page. This Always happen when the customer: Empty The Cart > Logout > Login > Cart Page - Wrong Scenario. I got no problem as the transaction is completed. The correct scenario would be: Empty The Cart > Logout > Login > Account Page. How could I code that?
By default Magento, if a customer logins, there are two cases:
+He always redirects to Dashboard
+He redirects to a page before logging (a reference page).
You can set this configuration: System > Configuration > CUSTOMERS > Customer Configuration > Login Options > Redirect Customer to Account Dashboard after Logging in > Yes/ No
You should take a look at app/code/core/Mage/Customer/controllers/AccountController.php
protected function _loginPostRedirect(): this method defines target URL and redirect customer after logging in. You override this function:
We check if cart is empty: $totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(), we will set target URL is Dashboard and don't check a reference page.