Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI: Add Special Properties to Variants #221 #227

Merged
merged 2 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Libraries/Hotcakes.Commerce/Catalog/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public Variant()
/// </summary>
public decimal Price { get; set; }

/// <summary>
/// The Custom Property to add further variant details
/// </summary>
public string CustomProperty { get; set; }

/// <summary>
/// These are the options that define the variant.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Hotcakes.Commerce/Catalog/VariantRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected override void CopyDataToModel(hcc_Variants data, Variant model)
}
model.Sku = data.Sku ?? string.Empty;
model.StoreId = data.StoreId;
model.CustomProperty = data.CustomProperty;
}

protected override void CopyModelToData(hcc_Variants data, Variant model)
Expand All @@ -76,6 +77,7 @@ protected override void CopyModelToData(hcc_Variants data, Variant model)
data.SelectionData = Json.ObjectToJson(model.Selections);
data.Sku = model.Sku;
data.StoreId = model.StoreId;
data.CustomProperty = model.CustomProperty;
}


Expand Down
11 changes: 7 additions & 4 deletions Libraries/Hotcakes.Commerce/Data/EF/HccDbContext.edmx
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@
<Property Name="RoleName" Type="nvarchar" Nullable="false" MaxLength="250" />
<Property Name="ExpirationPeriod" Type="int" Nullable="false" />
<Property Name="ExpirationPeriodType" Type="int" Nullable="false" />
<Property Name="Notify" Type="bit" Nullable="false" />
<Property Name="Notify" Type="bit" Nullable="false" />
</EntityType>
<EntityType Name="hcc_News">
<Key>
Expand Down Expand Up @@ -1551,7 +1551,8 @@
<Property Name="Sku" Type="nvarchar" Nullable="false" MaxLength="255" />
<Property Name="Price" Type="decimal" Nullable="false" Scale="10" />
<Property Name="SelectionData" Type="nvarchar(max)" Nullable="false" />
<Property Name="StoreId" Type="bigint" Nullable="false" />
<Property Name="StoreId" Type="bigint" Nullable="false" />
<Property Name="CustomProperty" Type="nvarchar(max)" Nullable="false" />
</EntityType>
<EntityType Name="hcc_Vendor">
<Key>
Expand Down Expand Up @@ -3542,6 +3543,7 @@
<Property Type="Decimal" Name="Price" Nullable="false" Precision="18" Scale="10" />
<Property Type="String" Name="SelectionData" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
<Property Type="Int64" Name="StoreId" Nullable="false" />
<Property Type="String" Name="CustomProperty" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
<NavigationProperty Name="hcc_Product" Relationship="EfModels.FK_hcc_Variants_hcc_Product" FromRole="hcc_Variants" ToRole="hcc_Product" />
</EntityType>
<EntityType Name="hcc_Vendor">
Expand Down Expand Up @@ -4364,7 +4366,7 @@
<NavigationProperty Name="hcc_ProductType" Relationship="EfModels.FK_hcc_MembershipProductType_hcc_ProductType" FromRole="hcc_MembershipProductType" ToRole="hcc_ProductType" />
<Property Type="Int32" Name="ExpirationPeriod" Nullable="false" />
<Property Type="Int32" Name="ExpirationPeriodType" Nullable="false" />
<Property Type="Boolean" Name="Notify" Nullable="false" />
<Property Type="Boolean" Name="Notify" Nullable="false" />
</EntityType>
<Association Name="FK_hcc_MembershipProductType_hcc_ProductType">
<End Type="EfModels.hcc_ProductType" Role="hcc_ProductType" Multiplicity="1" />
Expand Down Expand Up @@ -5763,6 +5765,7 @@
<ScalarProperty Name="Sku" ColumnName="Sku" />
<ScalarProperty Name="ProductId" ColumnName="ProductId" />
<ScalarProperty Name="bvin" ColumnName="bvin" />
<ScalarProperty Name="CustomProperty" ColumnName="CustomProperty" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
Expand Down Expand Up @@ -6251,7 +6254,7 @@
<EntitySetMapping Name="hcc_MembershipProductType">
<EntityTypeMapping TypeName="EfModels.hcc_MembershipProductType">
<MappingFragment StoreEntitySet="hcc_MembershipProductType">
<ScalarProperty Name="Notify" ColumnName="Notify" />
<ScalarProperty Name="Notify" ColumnName="Notify" />
<ScalarProperty Name="ExpirationPeriodType" ColumnName="ExpirationPeriodType" />
<ScalarProperty Name="ExpirationPeriod" ColumnName="ExpirationPeriod" />
<ScalarProperty Name="RoleName" ColumnName="RoleName" />
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Hotcakes.Commerce/Data/EF/hcc_Variants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public partial class hcc_Variants
public decimal Price { get; set; }
public string SelectionData { get; set; }
public long StoreId { get; set; }

public string CustomProperty { get; set; }

public virtual hcc_Product hcc_Product { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
title: "Edit Variant",
width: 500,
height: 'auto',
maxHeight: 500,
maxHeight: 600,
parentElement: '#<%=pnlEditVariant.ClientID%>',
close: function () {
<%= ClientScript.GetPostBackEventReference(lnkCancel, "") %>
Expand Down Expand Up @@ -120,8 +120,17 @@
<label class="hcLabel">Price</label>
<asp:TextBox ID="txtVariantPrice" runat="server" />
</div>

</div>
</div>
<div class="hcColumnLeft" style="width:100%">
<div class="hcForm">
<div class="hcFormItem">
<label class="hcLabel">Custom Property</label>
<asp:TextBox ID="txtVariantCustomProperty" runat="server" Width="400" Height="90" TextMode="MultiLine" />
</div>
</div>
</div>
<ul class="hcActions">
<li>
<asp:LinkButton ID="lnkSaveVariant" CssClass="hcPrimaryAction" Text="Save" OnClick="btnSave_Click" runat="server" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ protected void btnSave_Click(object sender, EventArgs e)
item.Price = Money.RoundCurrency(p);
}

item.CustomProperty = txtVariantCustomProperty.Text;

if (ucVariantImage.HasFile)
{
DiskStorage.CopyProductVariantImage(HccApp.CurrentStore.Id, ProductId, item.Bvin,
Expand All @@ -194,6 +196,7 @@ private void ShowDialog()
lblVariantDescription.Text = GetVariantDescription(variant);
txtVariantSku.Text = string.IsNullOrEmpty(variant.Sku) ? _currentProduct.Sku : variant.Sku;
txtVariantPrice.Text = (variant.Price < 0 ? _currentProduct.SitePrice : variant.Price).ToString("c");
txtVariantCustomProperty.Text = variant.CustomProperty;

ucVariantImage.ImageUrl = DiskStorage.ProductVariantImageUrlMedium(HccApp, _currentProduct.Bvin,
_currentProduct.ImageFileSmall, variant.Bvin, HccApp.IsCurrentRequestSecure());
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Issue #221
SI: SI: Add Special Properties to Variants
https://github.com/HotcakesCommerce/hotcakes-commerce-core/issues/221
*/
/* Add property to Product Choice Variants */
IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{objectQualifier}hcc_Variants' AND COLUMN_NAME = 'CustomProperty')
BEGIN
ALTER TABLE {databaseOwner}[{objectQualifier}hcc_Variants] ADD
[CustomProperty] [nvarchar](max) NOT NULL DEFAULT ''
END
GO