Combining PHP and Miva Merchant
For a long time, Miva Merchant developers have had to deal with the "exclusive or" situation of handling a certain task within the shopping cart framework, or externally via a PHP script. It's not uncommon to see users question how they can run PHP from within, say, a product description or a category header. The standard answer has always been, "you can't". At the most technical level, this is still true; Miva's virtual machine can't run PHP code.
We recently faced this challenge ourselves, when a client wanted to implement captchas on his website. (Catchas are those annoying but nifty little form elements that help avoid spam, by requiring the user to enter the letters shown in a graphic.) The request left us with two options; figure out how to use existing PHP code from a third-party, or reinvent the wheel on the client's nickel.
The good news is that the site, KaTom, was already using one of our favorite Miva modules - Merchant Optimizer from Phosphor Media. Merchant Optimizer makes a physical, static HTML file of all the product and category pages on a Miva Merchant store. So we thought, even though Miva Merchant can't process PHP code, maybe the static file could? Our first thought was to request that Phosphor Media customize Merchant Optimizer for us, so that the output pages all ended with .php instead of .html. The problem with that, however, is that KaTom already has really good search engine positions on their existing .html pages.
Our final solution was to use an Apache directive to run all of the .html pages through the PHP processor. This is done with a little bit of code in the main directory's .htaccess file:
<Files *.html> ForceType application/x-httpd-php </Files>Then, we put the PHP code into the category footers, just like coders have always said doesn't work. And if you run the page dynamically (via merchant.mvc), indeed, it doesn't. But once Merchant Optimizer generates the page, voila! the php code is run. It works beautifully. The main caveat is that we had to remove our comments from the php code, because the MvCall command uses by Merchant Optimizer didn't like them. To see this in action, see a sample page at KaTom. It's such a neat trick, that we did a similar thing on MyPaperShop.com, who also uses Merchant Optimizer. Their homepage shows the latest 3 links from their weblog within the "Read our Weblog" box in the right-hand column. It calls out to Wordpress, to a customized template, to bring back the 3 most recent links in simple HTMl with no header/footer or other information. We also changed the Apache directive to:
<Files index.html> ForceType application/x-httpd-php </Files>The change makes the site only use PHP for index.html, not for any other .html pages. This was simply done for performance reasons, because none of the other pages needed it. We've already got half a dozen other potential uses for this trick...hopefully you can find some too. If you try it, let us know what you accomplished.






