logo
Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
bart  
#1 Posted : Thursday, April 4, 2013 12:25:21 PM(UTC)
bart

Rank: Administration

Reputation:

Groups: Administration
Joined: 10/8/2008(UTC)
Posts: 190
Man

Was thanked: 1 time(s) in 1 post(s)
Hi,

In this post I will explain how to do a Google e-commerce implementation within Sienn.
The requirement for this is that Google analytics is already available on the website, so we can use the same accountnumber for this.
The Google analytics implementation has to be done the new way, the old way will not work

Also in Google analytics itself you need to enable e-commerce but from what I understand it is just a checkbox(not that familiar with Google analytics).

Basically you will send the order information in the response page, so we have to make sure the shopsession isn't cleared after ordering.

In UserEscape stock adjustment we have to comment the lines which are clearing the shopsession
Code:
'pbw.Set_CustomerId_cookie(session, -1, "")
'pbw.Shop_Set_cookie(Session, "")
'pbw.Set_PaymentType_cookie(Session, "")
(almost at the bottom)

now we need to create a control which does the javascript request to google.
This control looks like this:
Code:
DIM skufield as string = par(0)
DIM namefield as string = par(1)

Dim Cid as string = pbw.get_Cid_currentdomain
Dim CustomerId as integer = pbw.get_customerid_cookie(session)
Dim ErrString as string = ""
Dim ShopSettingIndex as integer = pbw.UserEscape_Shop_Settings_Index("SOURCESHOP24", Cid, False, pbw.Get_RunSource_CreateAssembly, pbw.Get_RunSource_RunFromAssembly(), Server, Request, Session, Constring, "", "", Response, errstring)
Dim Orderid As String = pbw.Get_Orderid_cookie(session)
Dim SHOPTABELNAAMKLANT as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPTABELNAAMKLANT",constring)
Dim SHOPKLANTVELDNAAMPLAATS as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPKLANTVELDNAAMPLAATS",constring)
Dim SHOPORDERTABELNAAM as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPORDERTABELNAAM",constring)
Dim SHOPORDERVELDSHOPSTRING as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPORDERVELDSHOPSTRING",constring)
Dim Shopstring as string = ""
Using Con As New SqlConnection(pbw.get_constring)
  Try
    Dim Query As String = ""
    Query &= " Select "
    Query &= SHOPORDERVELDSHOPSTRING
    Query &= " from "
    Query &= SHOPORDERTABELNAAM 
    Query &= " where Id=@Id"
    Dim Com As New SqlCommand(Query, Con)
    Com.Parameters.AddWithValue("@Id", Orderid)
    Con.open()
    Dim Reader As SqlDataReader = Com.ExecuteReader()
    while Reader.Read()
      Shopstring = Reader(0)
    end while
  Catch ex As Exception
    'response.write(ex.tostring)
  Finally
    Con.close()
  End Try
End Using

pbw.Shop_Set_cookie(session, Shopstring)
Dim StoreName as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPMAILNAAM",constring)
Dim TotalAmount as decimal = getTotalAmount(Shopstring)
Dim vatperc as decimal = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPBTWPERCHOOG",constring)
Dim TotalAmountexvat as decimal = TotalAmount / (1 + (vatperc/100))
Dim vat as decimal = TotalAmount  - TotalAmountexvat 
dim ordercosts as decimal = getordercosts(TotalAmount)

Dim CustomerCity as string = ""
Using Con As New SqlConnection(pbw.get_constring)
  Try
    Dim Query As String = ""
    Query &= " Select "
    Query &= SHOPKLANTVELDNAAMPLAATS 
    Query &= " from "
    Query &= SHOPTABELNAAMKLANT 
    Query &= " where Id=@Id"
    Dim Com As New SqlCommand(Query, Con)
    Com.Parameters.AddWithValue("@Id", CustomerId)
    Con.open()
    Dim Reader As SqlDataReader = Com.ExecuteReader()
    while Reader.Read()
      CustomerCity = Reader(0)
    end while
  Catch ex As Exception
response.write(ex.tostring)
  Finally
    Con.close()
  End Try
End Using
Dim JS as string = ""
js &= "<script>"
js &= " _gaq.push(['_addTrans', " '
js &= "   '" & OrderId & "', " '           // transaction ID - required
js &= "   '" & StoreName & "',  " '// affiliation or store name
js &= "   '" & Decimal.Round(TotalAmountexvat, 2) & "',  " '         // total - required
js &= "   '" & Decimal.Round(vat, 2) & "',  " '          // tax
js &= "   '" & ordercosts & "',  " '         // shipping
js &= "   '" & CustomerCity & "', " '       // city
js &= "   '', " '     // state or province
js &= "   ''  " '            // country
js &= " ]); " '
  Dim Articletable as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPTABELNAAM",constring)
  Dim PriceField as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPVELDNAAMPRIJS",constring)
  for i as integer = 1 to shopstring.split("#").length -1
    Dim Id as string = pbw.Shop_Get_Product_Property(pbw.Get_Parameter_Value(shopstring, i), 1)
    Dim Amount as integer = CInt(pbw.Shop_Get_Product_Property(pbw.Get_Parameter_Value(shopstring, i), 2))
    Dim price as string = pbw.Shop_Get_Product_Property(pbw.Get_Parameter_Value(shopstring, i ), 3)
    Dim SKUCode as string = ""
    Dim productname as string = ""
      using Con As New SqlConnection(constring)
        Try
            Dim strQuery As String = "SELECT " & PriceField
            strQuery &= " ," & skufield 
            strQuery &= " ," & namefield 
            strQuery &= " from " & Articletable  & ""
            strQuery &= " where Id=@Id "
            Dim Com As New SqlCommand(strQuery, Con)
            Com.Parameters.AddWithValue("@Id", Id)
            con.open
            Dim Reader As SqlDataReader = Com.ExecuteReader()
            while Reader.Read()
              If price = "" or price = "0"
                price = Reader(0)
              end if
              SKUCode = Reader(skufield)
              productname = Reader(namefield)
            End While
        Catch ex As Exception
          response.write(ex.tostring)
        Finally
            con.close
        End Try
      end using
    
    
    Dim  priceexvat as decimal = price / (1 + (vatperc/100))
    
    js &= " _gaq.push(['_addItem', " '
    js &= "   '" & OrderId & "',  " '          // transaction ID - necessary to associate item with transaction
    js &= "   '" & SKUCode & "',  " '          // SKU/code - required
    js &= "   '" & productname & "',   " '      // product name
    js &= "   '', " '   // category or variation
    js &= "   '" & Decimal.Round(priceexvat, 2) & "', " '          // unit price - required
    js &= "   '" & Amount & "'  " '             // quantity - required
    js &= " ]); " '
  next    
    
    js &= " _gaq.push(['_trackTrans']); " '
    js &= "</script>"
    
controlplace.controls.add(New literalcontrol(js))

pbw.Set_CustomerId_cookie(session, -1, "")
pbw.Shop_Set_cookie(Session, "")
pbw.Set_PaymentType_cookie(Session, "")


And I'm using the following functions in the functions part, If you like, you can place them in the global functions.
Code:
function getTotalAmount(Byval Shopstring  as string) as decimal
  Dim Constring as string = pbw.get_Constring()
  Dim Cid As string = pbw.get_Cid_currentdomain()
  Dim Server as HttpServerUtility = httpcontext.current.server
  Dim Request as HttpRequest = httpcontext.current.Request
  Dim Session as SessionState.HttpSessionState = httpcontext.current.Session
  Dim Response as HttpResponse = httpcontext.current.Response
  Dim ErrString as string = ""
  Dim ShopSettingIndex as integer = pbw.UserEscape_Shop_Settings_Index("SOURCESHOP24", Cid, False, pbw.Get_RunSource_CreateAssembly, pbw.Get_RunSource_RunFromAssembly(), Server, Request, Session, Constring, "", "", Response, errstring)
  Dim Articletable as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPTABELNAAM",constring)
  Dim PriceField as string = pbw.get_config_value(Cid,ShopSettingIndex,"SHOPVELDNAAMPRIJS",constring)
  Dim TotalAmount as decimal = 0
  for i as integer = 1 to shopstring.split("#").length -1
    Dim Amount as integer = CInt(pbw.Shop_Get_Product_Property(pbw.Get_Parameter_Value(shopstring, i), 2))
    Dim price as string = pbw.Shop_Get_Product_Property(pbw.Get_Parameter_Value(shopstring, i ), 3)
    If price = "" or price = "0"
      Dim Id as string = pbw.Shop_Get_Product_Property(pbw.Get_Parameter_Value(shopstring, i), 1)
      using Con As New SqlConnection(constring)
        Try
            Dim strQuery As String = "SELECT " & PriceField
            strQuery &= " from " & Articletable  & ""
            strQuery &= " where Id=@Id "
            Dim Com As New SqlCommand(strQuery, Con)
            Com.Parameters.AddWithValue("@Id", Id)
            con.open
            Dim Reader As SqlDataReader = Com.ExecuteReader()
            while Reader.Read()
                price = Reader(0)
            End While
        Catch ex As Exception
        Finally
            con.close
        End Try
      end using
    end if
    TotalAmount += Amount * Price
  next
  Return TotalAmount
end function

function getordercosts(Byval ShopTotaalprijs as decimal) as decimal
  Dim ordercosts as decimal = 0
  Try
   Dim Constring as string = pbw.get_Constring()
   Dim Cid As string = pbw.get_Cid_currentdomain()
   Dim Server as HttpServerUtility = httpcontext.current.server
   Dim Request as HttpRequest = httpcontext.current.Request
   Dim Session as SessionState.HttpSessionState = httpcontext.current.Session
   Dim Response as HttpResponse = httpcontext.current.Response
   Dim Errorstring As String
   Dim Type as string ="BESTELFORMULIER" 
   Dim UserEscapeIndex As Integer = pbw.UserEscape_Shop_UserEscape_Index("SOURCESHOP25", pbw.Get_Cid_currentdomain, False, pbw.Get_RunSource_CreateAssembly, pbw.Get_RunSource_RunFromAssembly(), Server, Request, Session, pbw.Get_Constring, "", "", Response, Errorstring)
   If Not pbw.UserEscape_Shop_Calculate_AdditionalCosts("SOURCESHOP05", UserEscapeIndex, cid, False, pbw.Get_RunSource_CreateAssembly, pbw.Get_RunSource_RunFromAssembly(), Server, Request, ShopTotaalprijs, type, ordercosts, Session, constring, "", "", response, Errorstring) Then
     Dim pinc As String = ""
     Dim bzkindex = 0
     bzkindex = pbw.UserEscape_Shop_AdditionalCosts_Index("SOURCESHOP06", UserEscapeIndex, cid, False, pbw.Get_RunSource_CreateAssembly, pbw.Get_RunSource_RunFromAssembly(), Server, Request, Session, ShopTotaalprijs, type, constring, "", "", response, Errorstring)
     pbw.Get_Config(cid, bzkindex, "SHOPBEZORGKOSTEN", pinc, constring)
     ordercosts = Microsoft.VisualBasic.Conversion.Val(pinc)
     If ordercosts < 0 Then
       ordercosts = 0
     End If
   End If
  Catch ex As Exception
    ordercosts= 0
  End Try
  return ordercosts
end function



Now the only thing left is adding the control to the order successfully completed text.
Quote:

<here is your thank you text, thank you for ordering etc...>

{!$Control.36.xx.Id.<Field which contains the name of the article>$!}


That's all you need to do. I created the control universal as much as possible so there is very little change you have to modify it.

The results you can see tomorrow, because Google updates this statistics once a day.

If there are any questions or problems, please let me know.

Regards

Bart

Edited by user Tuesday, April 23, 2013 9:57:48 AM(UTC)  | Reason: added someting about the google analytics implementation

Wanna join the discussion?! Login to your Sienn Forum forum account. New Registrations are disabled.

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.