Miva Merchant Ecommerce Blog

Add a "Buy Now" Button to Your Blog

Posted by Miva Merchant to Design & Development on May 20th, 2010

Having a blog is a great way to improve the SEO of your Store. You can run promotions, develop a following, and generate links from other sites. When promoting a product on your blog, most of the time you will want to have a button or a link that a user can click to add a product directly to the shopping cart, rather than sending them to the product page first, at which point they may abandon the product.

Today I will show you how to add a Buy Now button to your blog two different ways. You can use this on Wordpress, Blogger, Typepade, Joomla, Drupal and just about any other blog or content management system (CMS).

Using a Form

Using a form on your blog is the basic way to add a buy now button to your blog because it can be copied from your product page’s (PROD) template in Miva Merchant. You must replace the variables with hard coded values because the variables cannot be rendered outside of Miva Merchant. You will need to hardcode things like the Screen, Product Code, and action.

Default Form from Product Page (Wombat)

[code lang=“html”]
<form method="post" action="&mvt:global:sessionurl;Screen=BASK">
<input type="hidden" name="Old_Screen" value="&mvte:global:Screen;" />
<input type="hidden" name="Old_Search" value="&mvte:global:Search;" />
<input type="hidden" name="Action" value="ADPR" />
<input type="hidden" name="Store_Code" value="&mvte:store:code;" />
<input type="hidden" name="Product_Code" value="&mvte:product:code;" />
<input type="hidden" name="Category_Code" value="&mvte:global:category_code;" />
<div class="product-attributes"><mvt:item name="product_attributes" param="product:id" /></div>
<label for="product-quantity">Quantity:</label>
<input type="text" name="Quantity" value="1" class="product-quantity-input textfield" id="product-quantity" />
<mvt:item name="buttons" param="AddToBasket" />
</form>

Revised Form With Hardcoded Values

[code lang=“html”]
<form method="post" action="http://www.MyDomain.com/mm5/merchant.mvc?Screen=BASK">
<input type="hidden" name="Action" value="ADPR" />
<input type="hidden" name="Store_Code" value="MM" />
<input type="hidden" name="Product_Code" value="123" />
<input type="hidden" name="Category_Code" value="modules" />
<input type="hidden" name="Quantity" value="1" />
<input type="submit" value="Buy Now" />
</form>

Since we are in a blog or CMS of some kind, our Miva Merchant tokens cannot be rendered, so I have hardcoded them. This form is going to take a user to a basket page, add 1 product to their cart (code: 123), for the store code of MM.

These are all important to pass through the form or else it will not work. I removed the attributes section since this mock product of mine doesn’t have any, but if your product has attributes you can pass the values in a hidden field just the same.

Using a Link

A link is even easier than a form because you don’t need to deal with having a form, but instead you can easily make text or an image clickable link. All you have to do is take the same information from the hidden fields and attach it to the end of a link.

[code lang=“html”]
<a href="http://www.MyDomain.com/mm5/merchant.mvc?Screen=BASK&Store_Code=MM&Action=ADPR&Product_Code=123&Quantity=1">Buy Now</a>

The link above should be self explanatory, but all it’s doing is linking to the BASK page and passing the parameters necessary to add the “123” product to the cart.

How to Do It Using SEO Short Links

By default, the .htaccess file that Miva Merchant writes to use SEO short links doesn’t allow you to pass parameters. That means anything after /BASK.html would be ignored in the url. There is a fix for that. We are going to add a little bit of code to the default htaccess that is going to allow us to pass query strings in the URL without them being ignored.

Default .htaccess Code

### Begin - Inserted by Miva Merchant

DirectoryIndex /mm5/merchant.mvc?Screen=SFNT

RewriteEngine On

RewriteRule 
^mm5/admin.mvc? - [L]

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [L]

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]

### End - Inserted by Miva Merchant 

Updated .htaccess Code

DirectoryIndex /mm5/merchant.mvc?Screen=SFNT

RewriteEngine On

RewriteRule 
^mm5/admin.mvc? - [L]
RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^page/([^/]+)/PROD/([^/]+)$ /mm5/merchant.mvc?Store_code=$1&Screen=PROD&Product_code=$2&%{QUERY_STRING}

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^page/([^/]+)/CTGY/([^/]+)$ /mm5/merchant.mvc?Store_code=$1&Screen=CTGY&Category_code=$2&%{QUERY_STRING}

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^page/([^/]+)/PROD/([^/]+)/([^/]+)$ /mm5/merchant.mvc?Store_code=$1&Screen=PROD&Category_code=$2&Product_code=$3&%{QUERY_STRING}

RewriteCond 
%{REQUEST_FILENAME} !-s
RewriteRule 
^page/([^/]+)/([^/]+)$ /mm5/merchant.mvc?Store_code=$1&Screen=$2&%{QUERY_STRING} 

Now that our .htaccess is ready for us to pass some query strings at the end of our SEO links, the new link will look something like this:

<a href="http://www.MyDomain.com/BASK.html?Store_Code=MM&Action=ADPR&Product_Code=123&Quantity=1">Buy Now</a> 

Be careful about overwriting your .htaccess file in the admin, since whenever you change your SEO settings, it will overwrite the code that is in between the “Inserted by Miva Merchant” comments.

Demo - Buy Now

This is a demo Buy Now button that adds a Miva Merchant License to your cart. Notice that it can be used with absolute URLs allowing you to use them on different websites (ads, PR, etc.).

Buy One Now

follow Alex Hackbart

Want more? Follow Alex on Twitter!

Join the Discussion

Norm September 09, 2011

I see, I supspoe that would have to be the case.

Leave a Comment

Notify me of follow-up comments?