Promoted products


https://forum.kartris.com/Topic6942.aspx
Print Topic | Close Window

By Supermac - Thu 14 Sep 2017
Promotion applied to products is showed in product's detail page but customers can't know if there's a promotion on product 'til they enter the product detail because during navigation in parent categories promotions are not evidentiated.
So I modified a product template UC to obtain this result.

In aspx page I added a placeholder like the following:
<asp:placeHolder ID="phPromo" runat="server" Visible="false">
<div id="promosticker">
<p> PROMO </p>
</div>
</asp:placeHolder>

With CSS I modeled promosticker div to appear like a ribbon at the upper left corner of the user control.
In UC's codebehind I added a function to load event that verifies if product is listed in A part of active and running promotions and, depending on that, switches placeholder's visibility on or off.
phPromo.Visible = isPromoted(litProductID.text)

And this is the function:
Public Shared Function isPromoted(ByVal idprod As Integer) As Boolean
Dim promosso As Boolean = False
Dim cn = New SqlConnection(ConfigurationManager.ConnectionStrings("KartrisSQLConnection").ConnectionString)
Using cn
cn.Open()
dim strsql as string = "SELECT PP_itemID FROM tblKartrisPromotionParts " &
" Left Join tblKartrisPromotions ON tblKartrisPromotionParts.Prom_ID=tblKartrisPromotions.Prom_ID " &
" WHERE prom_live = 1 AND pp_partNo ='a' AND pp_ItemType='p' AND GETDATE() >=PROM_startdate AND GEtdate() <= PROM_EndDate " &
" And pp_ITEMID = " & idprod
dim cmd2 = New SqlCommand(strsql, cn)
dim rd as sqlDataReader = cmd2.ExecuteReader()
If rd.HasRows Then
promosso = True
End If
End Using
Return promosso
End Function


I post it here if it can be useful to someone or improved by anyone.
When I'll have time I'll extend the verify to product's parent category (so every product belonging to a promoted category will be evidentiated with the ribbon)
By Supermac - Mon 18 Sep 2017
Here it is!
When category is promoted it will results in all items belonging to category marked with the ribbon.
I just have to pass the cat.ID to the function that check the promotion, this is the way:
dim catID as string = "" & Request.QueryString("CategoryID")
phPromo.Visible = isPromoted(litProductID.text, catID)


And this is the function modified:
Public Shared Function isPromoted(ByVal idprod As Integer, byval optional catID as string = "") As Boolean
Dim promosso As Boolean = False
dim partToCheck as string = ""
Dim cn = New SqlConnection(ConfigurationManager.ConnectionStrings("KartrisSQLConnection").ConnectionString)
Using cn
cn.Open()
if catID <> "" then
partToCheck = " AND pp_ItemType='c' AND pp_ITEMID = " & catID
else
partToCheck = " AND pp_ItemType='p' AND pp_ITEMID = " & idprod
end if
dim strsql as string = "SELECT PP_itemID FROM tblKartrisPromotionParts " &
" Left Join tblKartrisPromotions ON tblKartrisPromotionParts.Prom_ID=tblKartrisPromotions.Prom_ID " &
" WHERE prom_live = 1 AND pp_partNo ='a' " & partToCheck & " AND GETDATE() >=PROM_startdate AND GEtdate() <= PROM_EndDate "
dim cmd2 = New SqlCommand(strsql, cn)
dim rd as sqlDataReader = cmd2.ExecuteReader()
If rd.HasRows Then
promosso = True
End If
End Using
Return promosso
End Function
By Supermac - Tue 19 Sep 2017
I used isPromoted() function even to switch on/off visibility of a label in category's template to notice the users that a promo is applied to the category.
Simply use 0 as product ID and the current category ID as function's parameters in CategoryTemplate.ascx.vb.