Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 10 of 10

Thread: How to display product variant prices below the product name?

  1. #1
    doru is offline Senior Member
    Join Date
    Jan 2008
    Posts
    158

    Default How to display product variant prices below the product name?

    Hi,

    I am using ASPDSNF v9.

    I need to know how to display product prices below the product name when the user open a category on public side. The Price for products with variants of different prices will show the low to high range.

    ex:
    [product image]
    product name
    $11.95 - $26.95

    Any help would be greatly appreciated!

    Thank you,
    Doru

  2. #2
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    I have written a function that I have attached to this message. I put this in XSLTExtensionBase.cs in the Core but you could put it into app_code. This function also utilizes the cache (if enabled) so it doesn't have to do db calls all the time. (Thanks to Justin for his help on the query)

    This will pull the high and low prices of a product and it's variants. It will look at regular price and sale price. If it's a sale price, it will make the color whatever your "OnSaleForTextColor" is.

    You can call the prices by doing the following in your xmlpackage:

    Code:
    <xsl:value-of select="aspdnsf:GetProductPrice(ProductID)" disable-output-escaping="yes"/>
    ** Use this script at your own discretion. Save a copy of the file(s) before making any changes! **
    Attached Files Attached Files
    Last edited by chrismartz; 04-01-2011 at 08:09 AM.

  3. #3
    DariusL is offline Junior Member
    Join Date
    Feb 2011
    Posts
    14

    Wink Great post!!!

    Great post chrismartz - thank you very much.

  4. #4
    cwilsonbh is offline Junior Member
    Join Date
    Apr 2011
    Posts
    1

    Default AspDotNetStorefront ML 7.1: Are the instructions the same?

    Hi,

    Great post. I have V7.1 of AspDotNetStorefront ML.

    Are the instructions the same for 7.1 as 9.0? I really need to display the range of variant prices in our category pages.

    Thank you for your help!

  5. #5
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    I have only had this working in version 9. I would assume that this would work in version 7 but I am unable to test it.

  6. #6
    DotNetDevelopments is offline Senior Member
    Join Date
    Jul 2008
    Location
    Harlow / Essex / UK
    Posts
    619

    Default

    Brilliant, thanks for this. Saved us hours of work.

    Also it works perfectly for version 8, inside the App_Code and Core. Thanks again!
    =====
    Version (Code/DB): AspDotNetStorefront MSx 9.1.0.1/9.1.0.0
    Execution Mode: 64 Bit
    Dot Net Developments - E-commerce By Experience

  7. #7
    gmaniac is offline Member
    Join Date
    Jul 2010
    Location
    Missouri
    Posts
    59

    Default error

    I am having trouble either figuring out how to insert directly into the XSLTExtensionBase.cs (how would you do that?) or creating a file in the app_code. I went with the app_code (since couldn't find any information on adding into the XSLTExtensionBase.cs file), it gives me erros when I try to inherit from the XSLTExtensionBase or if I try from AspDotNetStorefrontCore. Those are probably not what you are supposed to be using. I have a pretty good understanding of what is going on, a little help would be great though

    Thank you!

  8. #8
    DotNetDevelopments is offline Senior Member
    Join Date
    Jul 2008
    Location
    Harlow / Essex / UK
    Posts
    619

    Default

    Hey GManiac,

    Sorry for the late reply. Lets see if I can help out here.

    How To Insert Code Directly Into XSLTExtensionBase.cs In The Core
    First open up XSLTExtensionBase.cs in Visual Studio or whatever you like to use.
    Word of warning - my lines maybe different so look for the code I reference around over line numbers.

    Now you can put ChrisMartz's code anywhere after line 122 (within reason) this is because this is when the class really starts.
    Code:
    public class XSLTExtensionBase
    However you want the customer information so we want to place this new code after the customer has been assigned.

    Now I like to keep the code tidy so we will find another item along the same lines.

    In my code line 3716 seems to have a nice space and around the correct area for this code.

    I suggest pasting the code before
    Code:
    public virtual string GetCustomerLevelPrice(String sVariantID, string sPrice, String sPoints)
    Now once that is done rebuild the Core and you can start to use the price to - from as ChrisMartz's said
    Code:
    <xsl:value-of select="aspdnsf:GetProductPrice(ProductID)" disable-output-escaping="yes"/>
    How To Insert Code As App_Code Outside The Core
    Why would you do this? Because you do not need to do a rebuild, you also can upgrade your version of ASPDNSF with less problems (because all your mods are outside the Core!)

    Now because we like to be tidy first create a folder inside App_Code called "custom". Just makes it easier to find in the future.

    Now create a new C# Class and lets call it pricing.cs, the reason for this name is so you know it is your custom code and it is to do with prices, now in the future you can extend your custom pricing features/abilities.

    First thing, set up your page.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Data.SqlClient;
    using AspDotNetStorefrontCore;
    using System.Text;
    
    /// <summary>
    /// Code for custom pricing and price extensions
    /// App_Code help by DotNetDevelopments
    /// </summary>
    public class pricing
    {
    
    }
    Now this code is not correct, you need to add one more thing inside the code (by inside the code I mean inside public class pricing curly brackets.)

    Add this
    Code:
    #region Basic Setup
    
        public pricing() { }
    
        #endregion
    I like to use the regions to keep it tidy, you don't need to worry about this so just leave it and hide it away.

    Now if you just pasted the code after the endregion it would not work, this is because ThisCustomer is no where to be found.

    The problem is anywhere that says
    Code:
    ThisCustomer
    The real simple fix is to do a find and replace on ThisCustomer for:
    Code:
    Customer.Current
    Problem solved!

    This code is now all ready to go!
    All you need to do now is reference it in the web.config.

    Go to the web.config file and do a search for
    Code:
    <xsltobjects defaultExtension="">
    There should be one already there
    Code:
    <add name="receipt" namespace="urn:receipt" type="ReceiptXsltExtension, app_code">
            </add>
    Under this add
    Code:
    <add name="Pricing" namespace="urn:Pricing" type="pricing, app_code">
            </add>
    Now save your web.config.
    Almost there now!

    Open up the XML package you wish to use this new code in, as we have not put this in the core we can not access it via aspdnsf:

    After your first PackageTransform you will have the next line that looks like this
    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
    Change this line to
    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" xmlns:p="urn:Pricing" exclude-result-prefixes="aspdnsf">
    All we are adding is
    Code:
    xmlns:p="urn:Pricing"
    now we can use anything inside pricing.cs by using p:
    So now to use this code all you need to do is:
    Code:
    <xsl:value-of select="p:GetProductPrice(ProductID)" disable-output-escaping="yes"/>
    All done!

    Need anything just ask!
    =====
    Version (Code/DB): AspDotNetStorefront MSx 9.1.0.1/9.1.0.0
    Execution Mode: 64 Bit
    Dot Net Developments - E-commerce By Experience

  9. #9
    gmaniac is offline Member
    Join Date
    Jul 2010
    Location
    Missouri
    Posts
    59

    Default Thank you!

    You are amazing, thank you so much works perfectly!

  10. #10
    mal247 is offline Junior Member
    Join Date
    Apr 2009
    Posts
    16

    Default I also did this at the category level

    Just create another function and use this sql:

    Code:
    using (IDataReader rs = DB.GetRS(string.Format("SELECT COUNT(VariantID) AS num_of_variants, MIN(isnull(SalePrice,Price)) AS min_price, MAX(isnull(SalePrice,Price)) AS max_price, MIN(Price) AS min_compare, MAX(Price) AS max_compare FROM productvariant pv, Productcategory pc WITH (NOLOCK) WHERE pv.ProductID=pc.ProductID and pc.CategoryID={0} AND pv.Deleted = 0 AND pv.Published = 1", catID), conn))