I am running Umbraco 7.2 with uCommerce uCommerce-for-Umbraco7-6.5.3.14350.zip.x
I have added an ASPX WebForm page for the purpose of uCommerce Admin functions like a button to add products from a database table into the Catalogue.
I have included the following code from HERE on that page
var product = new Product
{
Sku = "SKU-123456",
Name = "My Product",
AllowOrdering = true,
DisplayOnSite = true,
ProductDefinitionId = 1, // Set to an existing defintion
ThumbnailImageMediaId = 1 // ID from Umbraco (nullable int)
};
product.Save();
However when I compile the project that code that code results in the following error:
Error 1 The type or namespace name 'Product' could not be found (are you missing a using directive or an assembly reference?) C:\Clancy\A_ClancyCom\Dev\ClancyCom8\ClancyCom8\TCUC_Admin.aspx.cs 25 31 ClancyCom8
Do I need to add a Using Directive ? If so what ? Any help getting past this error would be appreciated.
I am not sure what I am missing here but I tried adding
using UCommerce;
using UCommerce.EntitiesV2;
To my source file and I still get the error plus this error
Error 1 The type or namespace name 'UCommerce' could not be found (are you missing a using directive or an assembly reference?) C:\Clancy\A_ClancyCom\Dev\ClancyCom8\ClancyCom8\TCUC_Admin.aspx.cs 7 7 ClancyCom8
if you can see my problem or have any suggestions I would appreciate it.
I have included the code for the whole page below.
Thanks again
Terry Clancy
ClanceZ
Code for the whole page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UCommerce;
using UCommerce.EntitiesV2;
namespace ClancyCom8
{
public partial class TCUC_Admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int i = 1;
ClancyCom8.TCASPNET.MessageBox.Show("This is a message!");
i = i + 1;
var product = new Product
{
Sku = "SKU-123456",
Name = "My Product",
AllowOrdering = true,
DisplayOnSite = true,
ProductDefinitionId = 1, // Set to an existing defintion
ThumbnailImageMediaId = 1 // ID from Umbraco (nullable int)
};
product.Save();
}
}
This might be a 'stupid' question but have you remembered to reference your project to ucommerce libraries? Usually when it can't find the namespace it's because a reference in the project file has not been added.
var product = new Product
{
Sku = "SKU-123456",
Name = "My Product",
AllowOrdering = true,
DisplayOnSite = true,
ProductDefinitionId = 1, // Set to an existing defintion
ThumbnailImageMediaId = 1 // ID from Umbraco (nullable int)
};
product.Save();
The first error I am getting is
Error 1 'UCommerce.EntitiesV2.Product' does not contain a definition for 'ProductDefinitionId' C:\Clancy\A_ClancyCom\Dev\ClancyCom8\ClancyCom8\TCUC_Admin.aspx.cs 31 17 ClancyCom8
The second error is related to the line "ThumbnailImageMediaId = 1" and is as follows
Error 1 Cannot implicitly convert type 'int' to 'string' C:\Clancy\A_ClancyCom\Dev\ClancyCom8\ClancyCom8\TCUC_Admin.aspx.cs 32 41 ClancyCom8
At this point I am assuming that these are errors with the sample code and I have resolved by
(1) Commenting out the line ProductDefinitionId = 1
(2) Changing ThumbnailImageMediaId = 1 to read ThumbnailImageMediaId = "1"
With these changes the project now builds correctly.
When you want to link your product to a specific product definition you should use the property "ProductDefinition" and set it to an instance of your ProductDefinition.
Etc.
var product = new Product
{
ProductDefinition = ProductDefinition.SingleOrDefault(x => x.Name == "MyDefinition"),
// Setting other properties
};
Of course I would recommend moving your productdefinition call into a variable so you just reuse the same instance. Then the underlaying data layer (NHibernate) will ensure it will be saved into the database correctly.
uCommerce: Adding "new Product" on APSX WebForm page results in type or namespace could not be found
Hi all,
I am running Umbraco 7.2 with uCommerce uCommerce-for-Umbraco7-6.5.3.14350.zip.x I have added an ASPX WebForm page for the purpose of uCommerce Admin functions like a button to add products from a database table into the Catalogue.
I have included the following code from HERE on that page
However when I compile the project that code that code results in the following error:
Do I need to add a Using Directive ? If so what ? Any help getting past this error would be appreciated.
Thanks very much.
Terry Clancy ClanceZ
Hi Clancy
You are missing the
UCommerce.EntitiesV2
namespaceBR
Thanks Nickolaj,
I am not sure what I am missing here but I tried adding
using UCommerce; using UCommerce.EntitiesV2;
To my source file and I still get the error plus this error
if you can see my problem or have any suggestions I would appreciate it.
I have included the code for the whole page below.
Thanks again
Terry Clancy ClanceZ
Code for the whole page:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UCommerce;
using UCommerce.EntitiesV2;
namespace ClancyCom8
{
}
Hi Terry,
This might be a 'stupid' question but have you remembered to reference your project to ucommerce libraries? Usually when it can't find the namespace it's because a reference in the project file has not been added.
best regards Martin
Martin,
Not a stupid question at all. In fact I asked if that was necessary in an earlier post but did not get an answer on that.
The answer is no I had not added a reference. I thought the uCommerce package installation would have added any required references.
I have now found the instruactions at http://docs.ucommerce.net/ucommerce/v6/getting-started/ucommerce-api-overview.html to:
"All the Libraries for doing various operations are located in the namespace UCommerce.Api that are located in the assembly UCommerce.dll."
Based on that I have now added a reference to:
Assembly UCommerce at C:\Clancy\A_ClancyCom\Dev\ClancyCom8\ClancyCom8\Bin\UCommerce.dll
This solved the problem and the following does not cause an error:
I did get two errors with the following sample code from http://docs.ucommerce.net/ucommerce/v6/how-to/Create-a-product-using-the-api.html :
The first error I am getting is
The second error is related to the line "ThumbnailImageMediaId = 1" and is as follows
At this point I am assuming that these are errors with the sample code and I have resolved by
(1) Commenting out the line ProductDefinitionId = 1
(2) Changing ThumbnailImageMediaId = 1 to read ThumbnailImageMediaId = "1"
With these changes the project now builds correctly.
Thanks so much for your help with this.
Terry Clancy
ClanceZ
Hi Terry,
When you want to link your product to a specific product definition you should use the property "ProductDefinition" and set it to an instance of your ProductDefinition.
Etc.
var product = new Product { ProductDefinition = ProductDefinition.SingleOrDefault(x => x.Name == "MyDefinition"), // Setting other properties };
Of course I would recommend moving your productdefinition call into a variable so you just reuse the same instance. Then the underlaying data layer (NHibernate) will ensure it will be saved into the database correctly.
Happy to see you found the mistake :-)
Best regards Martin
is working on a reply...