Technical support This forum is closed.
Version 1.x > Technical support > Shopping Cart - DataItem.ComProductID View modes: 
User avatar
Member
Member
JeremyThake - 1/11/2006 9:50:14 AM
   
Shopping Cart - DataItem.ComProductID
I've seen you can create a Add to cart link using the following:

<p><a href="<%# ResolveUrl("~/ShoppingCart/ShoppingCart.aspx?ProductID=") + Convert.ToString(DataBinder.Eval(Container, "DataItem.ComProductID")) + "&quantity=1" %>">Add to Cart</a></p>

But what if I wanted to get the Cost from the Product type...I've tried DataItem.ComCost , DataItem.ComPrice but no luck. I want to be able to output the cost next to the products as well as the add to cart link.

In the demo they use ProductPrice but this is set in the CMS element as well as the Products part of the tree item...this is replication and could cause problems with prices being out of sync.

User avatar
Guest
admin - 1/13/2006 2:45:59 PM
   
Re: Shopping Cart - DataItem.ComProductID
Hi Jeremy,

Thank you for this question. You're right that those two tables (COM_Product and CMS_Product) are not a very good example. We will improve it in Kentico CMS 2.0.

Here's what you can do now:

1) Modify the View_CMS_Tree_Joined view like this:

SELECT dbo.CMS_Tree.NodeID, dbo.CMS_Tree.IDPath, dbo.CMS_Tree.AliasPath, dbo.CMS_Tree.NamePath, dbo.CMS_Tree.NodeName,
dbo.CMS_Tree.NodeAlias, dbo.CMS_Tree.ModifiedWhen, dbo.CMS_Tree.ModifiedByUserID, dbo.CMS_Tree.ClassID, dbo.CMS_Tree.ParentNodeID,
dbo.CMS_Tree.NodeLevel, dbo.CMS_Tree.ForeignKeyValue, dbo.CMS_Tree.CreatedByUserID, dbo.CMS_Tree.CreatedWhen,
dbo.CMS_Tree.OwnerUserID, dbo.CMS_Tree.CheckedOutByUserID, dbo.CMS_Tree.CheckedOutWhen, dbo.CMS_Tree.CheckedOutVersionHistoryID,
dbo.CMS_Tree.PublishedVersionHistoryID, dbo.CMS_Tree.WorkflowStepID, dbo.CMS_Tree.PublishFrom, dbo.CMS_Tree.PublishTo,
dbo.CMS_Tree.ACLID, dbo.CMS_Tree.UrlPath, dbo.CMS_Tree.ComProductID, dbo.CMS_Class.ClassName, dbo.CMS_Class.ClassDisplayName,
dbo.CMS_User.UserName, dbo.CMS_User.FullName, OWNER.UserName AS OwnerUserName, OWNER.FullName AS OwnerFullName,
CREATOR.UserName AS CreatorUserName, CREATOR.FullName AS CreatorFullName, CHECKEDOUT.UserName AS CheckedOutByUserName,
CHECKEDOUT.FullName AS CheckedOutByFullName, CASE WHEN ((checkedoutversionhistoryid IS NULL AND publishedversionhistoryid IS NULL) OR
(checkedoutversionhistoryid IS NOT NULL AND publishedversionhistoryid IS NOT NULL)) AND (publishfrom IS NULL OR
(publishfrom IS NOT NULL AND publishfrom <= getdate())) AND (publishto IS NULL OR
(publishto IS NOT NULL AND publishto >= getdate())) THEN 1 ELSE 0 END AS Published, dbo.COM_Product.ProductName AS COM_ProductName,
dbo.COM_Product.ProductPrice AS COM_ProductPrice, dbo.COM_Product.ProductCode AS COM_ProductCode,
dbo.COM_Product.ProductVatRate AS COM_ProductVatRate, dbo.COM_Product.ProductIsActive AS COM_ProductIsActive
FROM dbo.CMS_Tree LEFT OUTER JOIN
dbo.CMS_Class ON dbo.CMS_Class.ClassID = dbo.CMS_Tree.ClassID LEFT OUTER JOIN
dbo.CMS_User ON dbo.CMS_User.UserID = dbo.CMS_Tree.ModifiedByUserID LEFT OUTER JOIN
dbo.CMS_User AS OWNER ON OWNER.UserID = dbo.CMS_Tree.OwnerUserID LEFT OUTER JOIN
dbo.CMS_User AS CREATOR ON CREATOR.UserID = dbo.CMS_Tree.CreatedByUserID LEFT OUTER JOIN
dbo.CMS_User AS CHECKEDOUT ON CHECKEDOUT.UserID = dbo.CMS_Tree.CheckedOutByUserID LEFT OUTER JOIN
dbo.COM_Product ON dbo.COM_Product.ProductID = dbo.CMS_Tree.ComProductID

2) Now you can use the following expression to display the price from the COM_Product table:

<%# DataBinder.Eval(Container, "DataItem.COM_ProductPrice") %>

Please let me know if you need any additional details.

Best Regards,

User avatar
Member
Member
JeremyThake - 1/17/2006 3:44:48 AM
   
Re: Shopping Cart - DataItem.ComProductID
Ok, that's great.

I now have removed the product name and price so it uses the COM_Product table.

But now if I create a new Product, the nodenamesourceattribute has to still have a value...how do I get round this to use the COM_Product name?

Jeremy

User avatar
Guest
admin - 1/17/2006 7:53:05 AM
   
Re: Shopping Cart - DataItem.ComProductID
Hi Jeremy,

Thank you for your message. Unfortunately, this is not supported as the product name (COM_Product) is specified after you create the product document (Content_Product).

We will solve this in some of the next version by allowing you to specify the source attribute that will be used for COM_Product.ProductName.

Best Regards,