I have a very basic shopping cart with only a few product to order some booklets and no need for payment providers in this case..
Right now I have a setup in Website application i Visual Studio with database tables for products and orders - just using Northwind database, but I think I only need tables for Product, Order and OrderDetails.
I have hightlighted to most important columns I need.
What is the best approach to use productdata from nodes in Umbraco in a .NET usercontrol with product nodes from Umbraco?
Can I update the Product table on publish and unpublish (or delete) to match the data in Umbraco?
Use product data from Umbraco nodes
I have a very basic shopping cart with only a few product to order some booklets and no need for payment providers in this case..
Right now I have a setup in Website application i Visual Studio with database tables for products and orders - just using Northwind database, but I think I only need tables for Product, Order and OrderDetails.
I have hightlighted to most important columns I need.
What is the best approach to use productdata from nodes in Umbraco in a .NET usercontrol with product nodes from Umbraco?
Can I update the Product table on publish and unpublish (or delete) to match the data in Umbraco?
/Bjarne
Hello,
It might be good to start with this old topic: http://our.umbraco.org/forum/developers/extending-umbraco/10412-Store-webshop-products-as-nodes-or-in-a-custom-table
If you want to use a custom table you can show the data with a UserControl or Razor.
If you want to manage your custom tables from Umbraco you might like this package: http://our.umbraco.org/projects/developer-tools/dewd
Jeroen
Hi Jeroen
I haven't use dewd before, but it seems the data are maintained in a custom section and setup with custom sql queries?
I have the following structure in content section and I would like that the data are maintained from here.
A few years back I had product data in the content stucture and was using the eventshandlers to add the data to a custom table something like this:
using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using System.Web.Configuration; using umbraco.cms.businesslogic.web; using umbraco.BusinessLogic; using umbraco.presentation.nodeFactory; using umbraco.cms.businesslogic.media; namespace Events { public class ProduktData : ApplicationBase { public ProduktData() { Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish); } void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e) { // kun gældende for nodes der anvender Produkt dokument typen. if (sender.ContentType.Alias == "Produkt") { // databaseforbindelse string connectionString = WebConfigurationManager.ConnectionStrings["umbracoConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); try { // opretter strenge med værdierne angivet til produktet string Navn = sender.getProperty("name").Value.ToString(); string Varenr = sender.getProperty("varenr").Value.ToString(); string Pris = sender.getProperty("price").Value.ToString(); string Kategori = sender.getProperty("kategori").Value.ToString(); string Billede = sender.getProperty("imageURL").Value.ToString(); string Nyhed = sender.getProperty("news").Value.ToString(); string Beskrivelse = sender.getProperty("description").Value.ToString(); // finder node id'et, det konverteres til en integer string nodeIDstring = umbraco.helper.Request("id"); Int32 nodeID = Convert.ToInt32(nodeIDstring); // konverterer Billede tekststrengen til en int, opretter et Media objekt og // opretter en streng, der sættes til værdien af datatypen med alias umbracoFile. Int32 mediaID = Convert.ToInt32(Billede); Media mymedia = new Media(mediaID); string imageURL = mymedia.getProperty("umbracoFile").Value.ToString(); // parser værdien fra tekststrengen Nyhed til en int, der så konverteres til en boolean (True/False). Int32 newsID = Int32.Parse(Nyhed); bool news = Convert.ToBoolean(newsID); // konverterer tekststrengen kategori til en int og derefter fåes den tilhørende tekst til id'et. Int32 kategoriID = Convert.ToInt32(Kategori); string category = umbraco.library.GetPreValueAsString(kategoriID); // SQL-kommando - tjekker om BilledID'et eksisterer // indsætter en række hvis BilledID'et ikke eksisterer ellers opdateres rækken. SqlCommand comm = new SqlCommand("IF NOT EXISTS(SELECT * FROM Varer WHERE BilledID=@BilledID) INSERT INTO Varer(BilledID, Navn, Varenr, Pris, Kategori, BilledURL, Beskrivelse, Nyhed) VALUES(@BilledID, @Navn, @Varenr, @Pris, @Kategori, @BilledURL, @Beskrivelse, @Nyhed) ELSE UPDATE Varer SET Navn=@Navn, Varenr=@Varenr, Pris=@Pris, Kategori=@Kategori, BilledURL=@BilledURL, Beskrivelse=@Beskrivelse, Nyhed=@Nyhed WHERE BilledID=@BilledID", conn); comm.Parameters.Add("@BilledID", System.Data.SqlDbType.Int); comm.Parameters["@BilledID"].Value = nodeID; comm.Parameters.Add("@Navn", System.Data.SqlDbType.NVarChar, 50); comm.Parameters["@Navn"].Value = Navn; comm.Parameters.Add("@Varenr", System.Data.SqlDbType.NVarChar, 50); comm.Parameters["@Varenr"].Value = Varenr; comm.Parameters.Add("@Pris", System.Data.SqlDbType.Money); comm.Parameters["@Pris"].Value = Pris; comm.Parameters.Add("@Kategori", System.Data.SqlDbType.NVarChar, 100); comm.Parameters["@Kategori"].Value = category; comm.Parameters.Add("@BilledURL", System.Data.SqlDbType.NVarChar, 100); comm.Parameters["@BilledURL"].Value = imageURL; comm.Parameters.Add("@Beskrivelse", System.Data.SqlDbType.NVarChar, 500); comm.Parameters["@Beskrivelse"].Value = Beskrivelse; comm.Parameters.Add("@Nyhed", System.Data.SqlDbType.Bit); comm.Parameters["@Nyhed"].Value = news; // Åbn forbindelse conn.Open(); // udfører kommando comm.ExecuteNonQuery(); } catch (Exception ex) { Log.Add(LogTypes.Publish, sender.Id, ex.Message); } finally { // luk forbindelsen conn.Close(); } } } } }/Bjarne
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.