How to make variant price show on search page

This forum is where we'll mirror posts that are of value to the community so they may be more easily found.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

How to make variant price show on search page

Post by AbleMods » Wed Feb 20, 2008 9:09 pm

Introduction
When a product price is shown in the search page for a product that has variants, the value displayed is always pulled from the main product record. This is true even when the product variants price(s) are different from the main product record price.
This creates a problem of sorts. You can't clear the price field from the main product record - that just makes it display "$0.00" as the price. You could set an initial price on the product record itself, but then you're forced to remember to change it if you ever update the pricing on your variants.
Meanwhile, your visitors can be misled when the price they see on the search window doesn't match any of your variant prices.

This modification changes the product price display control so that the first variants price is displayed instead of the main product price. This one modification affects both the Product Finder and Advanced Search features.

This modification assumes AC7 RC2.

How it works
When the price control is used on the search page or advanced search page, it is not provided the necessary _ProductVariantId value like it is on a specific product page. That gives us a way to tell if the control is used on the search page. We just replace the display value with the price of the first variant defined for the product.

Code Changes
First, make a backup of your ~/ConLib/Utility/ProductPrice.ascx and .ascx.cs files.

Edit the ~/ConLib/Utility/ProductPrice.ascx.cs file and look for this code near the start of the Page_PreRender function:

Code: Select all

            if (!_Product.UseVariablePrice)
            {
and replace it with this code:

Code: Select all

            if (!_Product.UseVariablePrice)
            {
                // If the provided product has variants but the specific variant wasn't given,
                // set the display price to be the price of the first variant selection.
                if (_ProductVariantId == 0 && _Product.Variants.Count > 0)
                {
                    _ProductVariantId = _Product.Variants[0].ProductVariantId; 
                }
Save it.

Testing
In the Admin side of your store, edit a product you know has some variants. Set the main product record price to something obvious like 999.99. Save it.
Now go into the store side and search for that product. Once the correct product is displayed, you should NOT see the price as 999.99. It should be the price of your first variant choice selection.
Click the product and then click your first variant choice - that price is what you should have seen on the previous search screen.

Conclusion
Earning a customers trust is a key factor in their decision to purchase from your store. That trust comes from a variety of sources, including consistency with the information you give them. This modification improves that consistency by ensuring the product price on the search screen will always align with the actual prices for that product.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

joebeazelman
Lieutenant (LT)
Lieutenant (LT)
Posts: 78
Joined: Wed Mar 05, 2008 11:27 am

Re: How to make variant price show on search page

Post by joebeazelman » Sun Jun 29, 2008 11:16 am

This used to work on the last release, but no longer works on ac7_b9381. I get the following error message:

[[ConLib:CategoryGridPage4]] d:\ac7_b9381\ConLib\Utility\ProductPrice.ascx.cs(188): error CS0103: The name '_ProductVariantId' does not exist in the current context

Post Reply