Sunday, August 9, 2009

How to view oscommerce/oscmax in dreamweaver

I've seen more than a few questions on how the oscommerce/oscmax template you build can be viewed in Dreamweaver's Design View or some similar HTML editor.

The short, simple answer is that it can't.

Here's why: oscommerce, oscmax, other shopping carts, or any database-driven solution for that matter - are dynamic in nature. Whether written in PHP or not, it's just a bunch of arguments that will execute based on what the visitor has done. In the case of PHP, the code needs to be processed by a PHP-enabled server that will send the appropriate HTML code to your browser. Even if you have such capabilities running locally, you still won't be able to do this with Dreamweaver because it's static.

For example, some code like the one I've posted here determines the final thing to show in the browser - the final HTML code - based on whether a customer is logged in or not. The products page code instructs to show the details relevant to the product or category you've clicked on. The server queries your database based on these conditions and sends the data to your browser. You can't do this with Dreameaver.

So you might be able to see some graphics and colors that are not dynamically generated. But with most pages, you'll see some blank tables in the good case and absolutely nothing in the worst case. Still, if you know HTML you shouldn't have trouble working in code view, and then test through your browser.

Oscmax/Oscommerce - Check if customer is logged in

Sometimes you might want to specify some processing to occur or something to only show up if the customer is logged in. So before you write anything you need to specify this login condition, or check if a login session has started.

This is much simpler to do than it seems. All you need is this line:

if ((tep_session_is_registered('customer_id')) && (!tep_session_is_registered('noaccount'))) {
your code
}

which basically tells the browser to check if the session is registered but make sure that it's an account (rather than PWA session).

In oscommerce, you don't need the "noaccount" session since there is no PWA allowed. So it would be:

if (tep_session_is_registered('customer_id')) {
your code
}

Replace "your code" with whatever code you have, and at the end don't forget to put the closing bracket or you'll get a parse error.

For example, the following code redirects a logged in customer to the new products page, and otherwise sends a user to the login page:

if ((tep_session_is_registered('customer_id')) && (!tep_session_is_registered('noaccount'))) {
tep_redirect(tep_href_link(FILENAME_PRODUCTS_NEW));
}
else {
tep_redirect(tep_href_link(FILENAME_LOGIN));
}

And in oscommerce:

if (tep_session_is_registered('customer_id')) {
tep_redirect(tep_href_link(FILENAME_NEW_PRODUCTS));
}
else {
tep_redirect(tep_href_link(FILENAME_LOGIN));
}

Enjoy!