Custom Control - Product weight


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

By BORNXenon - Fri 9 May 2014
Hi,

I am currently evaluating eCommerce systems and have narrowed it down to Kartris and nopCommerce.
The one thing that I really like in Kartris over nopCommerce is the Custom Control feature.
We sell Polycarbonate sheet both in stock sizes and cut-to-size. I have created a custom control that looks up a price from a CSV file based on user input and this works well, however, I don't see anywhere where I can pass the weight of the custom product. Obviously the weight is needed for shipping purposes but the only place I can see that I can set the weight is within the Product version in the Admin section.

How can I overwrite the weight in the same way as the price?

Cheers

Chris
By Paul - Fri 9 May 2014
I think at present this isn't supported. But the customcost functionality is implemented in the BasketBLL.vb. Looking in there I think it's not a huge job to add support for customweight too, the code would be very similar to custom cost, only simpler as no need to convert currencies or format them.

I will add this to the feature list, I agree it would be a useful feature to have. But I think if you've done the custom control already, your skills are probably up to the job - I think from looking at the code it shouldn't be a huge job.
By BORNXenon - Fri 9 May 2014
Thanks Paul, I'll check out BasketBLL.vb and report back.

Cheers

Chris
By BORNXenon - Sat 10 May 2014
Just want to say that thanks to Paul pointing me in the right direction I have managed to implement the custom weight alongside custom price.
There are actually three files that require editing and for anyone wishing to accomplish the same thing, here are the edits required (changes highlighted):

File name: KartrisClasses.vb
Line No: 783- 789
Code:

''' <summary>

''' Returns the computed weight from the selected options in the control

''' </summary>

''' <value></value>

''' <returns></returns>

''' <remarks></remarks>

Public MustOverride ReadOnly Property ItemWeight As Decimal




File name: ProductVersions.ascx.vb
Line No: 602
Code:


''' <summary>

''' Handles add to basket button clicks forcustom product versions

''' </summary>

''' <remarks></remarks>

Protected SubbtnAddCustomVersions_Click(ByVal sender As Object, ByVal e As System.EventArgs)Handles btnAddCustomVersion.Click

Dim UC_CustomControl AsKartrisClasses.CustomProductControl =phdCustomControl.FindControl("UC_CustomControl")

If UC_CustomControl IsNot Nothing Then

IfUC_CustomControl.ComputeFromSelectedOptions() = "success" Then

Dim objMiniBasket As Object =Page.Master.FindControl("UC_MiniBasket")

Dim objBasket As BasketBLL =objMiniBasket.GetBasket

objMiniBasket.AddCustomItemToBasket(litHiddenV_ID.Text,ddlCustomVersionQuantity.SelectedValue,

UC_CustomControl.ParameterValues & "|||" &UC_CustomControl.ItemDescription & "|||" &UC_CustomControl.ItemPrice & "|||" & UC_CustomControl.ItemWeight)

End If

End If

End Sub



File name: BasketBLL.vb
Line No: 1302-1303
Code:


'Handle the pricedifferently if basket item is from a custom product

Dim strCustomControlName AsString = ObjectConfigBLL.GetValue("K:product.customcontrolname",objItem.ProductID)

If NotString.IsNullOrEmpty(strCustomControlName) Then

Try

Dim strParameterValuesAs String = FixNullFromDB(drwBasketValues("CustomText"))

'Split the custom textfield

Dim arrParameters AsString() = Split(strParameterValues, "|||")

' arrParameters(0)contains the comma separated list of the custom control's parameters values

' we don't use thisvalue when loading the basket, this is only needed when validating the price inthe checkout

' arrParameters(1)contains the custom description of the item

If NotString.IsNullOrEmpty(arrParameters(1)) Then

objItem.VersionName= arrParameters(1)

End If

' arrParameters(2)contains the custom price

objItem.Price =arrParameters(2)

'just set the optionprice to 0 just to be safe

objItem.OptionPrice =Math.Round(0, CurrencyRoundNumber)

' arrParameters(3) contains the custom weight

objItem.Weight = arrParameters(3)

Catch ex As Exception

'Failed to retrievecustom price, ignore this basket item

objItem.Quantity = 0

End Try

End If



Implementing other custom features such as custom SKU's can be accomplished in the same way. Obviously other changes are required in any custom control created such as declaring the ItemWeight properties but if you've got this far, that bit is a doddle!