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 2 of 2

Thread: custom code

  1. #1
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation custom code

    Hi, I am displaying a section of products as deals of the week in my website.

    and it is working fine.

    But i have a small issue here.

    This is my full code.

    C#/VB.NET Code:
    <%
    Set conn Server.createobject("ADODB.CONNECTION")

    Conn.open "Driver={SQL Server};" 
                
    "Server=xxx.xxx.xxx;" _
                
    "Database=xxxx;" _
                
    "Uid=xxxxx;" _
                
    "Pwd=xxxx"
    Dim SQLpID1pName1pPrice1pImg1pID2pName2pPrice2pImg2pURL1pURL2
    Set rs 
    Server.CreateObject("ADODB.Recordset")
    SQL "SELECT TOP 2 p.*, pv.Price AS SalePrice  FROM dbo.Product p with (nolock) left join dbo.productvariant pv  with (NOLOCK) on p.ProductID = pv.ProductID left join dbo.ProductManufacturer pm  with (NOLOCK) on p.ProductID = pm.ProductID "
    SQL SQL " WHERE pm.ManufacturerID = 2 and p.Deleted = 0 and pv.Deleted = 0 and pv.Price > 0"
    SQL SQL " ORDER BY NewID()"
    rs.open SQLconn

    Dim rCount
    rCount 
    0

    While Not rs.EOF
    rCount 
    rCount 1
      
    'response.write(rs("ProductID") & " " & rs("SalePrice") & "<br /><br />")
      if rCount =1 then
        pName1 = rs("Name")
        pID1 = rs("ProductID")
        pImg1 = rs("ImageFilenameOverride")
        pPrice1 = AddCommas(rs("SalePrice"))
        pURL1 = "p-" & pID1 & "-" & replace(StripName(pName1)," ","-") & ".aspx"
      else
        pName2 = rs("Name")
        pID2 = rs("ProductID")
        pImg2 = rs("ImageFilenameOverride")
        pPrice2 = AddCommas(rs("SalePrice"))
        pURL2 = "p-" & pID2 & "-" & replace(StripName(pName2)," ","-") & ".aspx"
      end if
      rs.MoveNext
    Wend

    function AddCommas(price)
        dim temp
        if len(price) > 3 then
            temp = "," & right(price,3)
            temp = Left(price, len(price)-3) & temp
            AddCommas = temp
        else
            AddCommas = price
        end if
    end function

    function StripName(ProductName)
    dim i
    dim newString
    dim validChars
    validChars = "1234567890-qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM "

    '
    Do while len(ProductName) > 0
    '    if instr(validChars, Left(ProductName,1)) > 0 then 
    '        
    newString newString Left(ProductName,1)
    '    end if
    '    
    '    if len(ProductName) > 1 then
    '        
    ProductName right(ProductNamelen(ProductName) - 1)   
    '    else
    '        
    ProductName ""
    '    end if 
    '
    Loop
    '
    '
    StripName newString
        
        ProductName 
    Replace(ProductName,"(","")
        
    ProductName Replace(ProductName,")","")
        
    ProductName Replace(ProductName,"_","")
        
    ProductName Replace(ProductName,",","")
        
    ProductName Replace(ProductName,".","")
        
    ProductName Replace(ProductName,"|","")
        
    ProductName Replace(ProductName,"+","")
        
    ProductName Replace(ProductName,"=","")
        
    ProductName Replace(ProductName,";","")
        
    ProductName Replace(ProductName,":","")
        
    ProductName Replace(ProductName,"&","")
        
    ProductName Replace(ProductName,"/","")
        
    ProductName Replace(ProductName,"\","")
        ProductName = Replace(ProductName,"
    [","")
        ProductName = Replace(ProductName,"
    ]","")
        ProductName = Replace(ProductName,"
    {","")
        ProductName = Replace(ProductName,"
    }","")
        ProductName = Replace(ProductName,"
    *","")
        ProductName = Replace(ProductName,"
    ^","")
        ProductName = Replace(ProductName,"
    %","")
        ProductName = Replace(ProductName,"
    $","")
        ProductName = Replace(ProductName,"
    #","")
        
    ProductName Replace(ProductName,"@","")
        
    ProductName Replace(ProductName,"!","")
        
    ProductName Replace(ProductName,"~","")
           
       
    StripName ProductName 
    end 
    function


    %>
    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head>
        <
    title>Deals of the Week</title>
    </
    head>
    <
    body style="margin: 0 0 0 0; BACKGROUND-IMAGE: url(skins/skin_3/trimages/deals-background.jpg); BACKGROUND-COLOR: transparent">
    <
    table id="tblMain" cellpadding="0" cellspacing="0" border="0" style="height: auto; width: auto;">
        <
    tr>
            <
    td valign="top" align="center" style="padding-top: 15px; padding-left: 3px; padding-right: 3px;">
                <!-- 
    product#1 -->
                
    <div align="center"><a target="_parent" href="<%=pURL1 %>"><img width="150px" height="150px" src="images/Product/icon/<%=pID1 %>.jpg" style="border: groove 4; border-color:Maroon;"></a> </div>
                <
    div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial"><a target="_parent" href="<%=pURL1 %>"><%=pName1 %></a></span> </div>
                <
    div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial">Sale Price: $<%=pPrice1 %></span> </div>
                
                <!-- 
    end product #1 -->
                
    <div align="center">&nbsp;</div>
                <!-- 
    Product #2 -->
                
    <div align="center"><a target="_parent" href="<%=pURL2 %>"><img width="150px" height="150px" src="images/Product/icon/<%=pID2 %>.jpg" style="border: groove 4; border-color:Maroon;"></a> </div>
                <
    div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial"><a target="_parent" href="<%=pURL2 %>"><%=pName2 %></a></span> </div>
                <
    div align="center"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Arial">Sale Price: $<%=pPrice2 %></span> </div>
                <!-- 
    end product #2 -->
            
    </td>
        </
    tr>
    </
    table>

    </
    body>
    <%
    rs.close
    conn
    .close
    Set rs 
    Nothing
    Set conn 
    Nothing
     
    %>
    </
    html

    with this code i will be able to show two products from the manufacture ID 2.

    But the problem is
    Code:
    <img width="150px" height="150px" src="images/Product/icon/<%=pID1 %>.jpg" style="border: groove 4; border-color:Maroon;">
    in this line to the image source, i gave the source as src="images/Product/icon/<%=pID1 %>.jpg"
    which will return the images of those product which have product ID as image name.

    But there are some products which has a different name than product ID.

    So i am looking for some modification like it should look for ImageFilenameOverride first if no ImageFilenameOverride then consider Product ID as image name.

    please help me with this.

    Thanks
    Last edited by ASPAlfred; 04-26-2010 at 06:53 PM.
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  2. #2
    webopius is offline Senior Member
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    440

    Default

    Um, you might want to remove that password and related connection information from your example.

    Secondly, if this is running within your store, I'd recommend using the standard ASPDotNetStorefront XML system and creating an XMLpackage template for this using the standalone feature to allow the package to run independently (<package allowengine=”true”>).

    This way, you can avoid all that code that connects to the DB and take advantage of all the inbuilt functions that handle items such as the ImageFilenameoverride that you need.

    If the page is outside of your store, then I'd suggest looking at the WSI interface.