logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
ray22901031  
#1 Posted : Wednesday, March 4, 2020 12:27:41 AM(UTC)
ray22901031

Rank: Advanced Member

Groups: Authorized User, Developers
Joined: 2/17/2019(UTC)
Posts: 826

Thanks: 3 times
Was thanked: 13 time(s) in 13 post(s)
Hello,

I'm trying to create some basic Crystal reports to run against the database. One of the main reports that we need to create is, a product and the category that it is attached to.

There seems to be 4 tables at play here:

- Products
- Categories
- CatalogNodes
- CategoryParents

Below is the SQL attaching the tables, at least three of them:

SELECT
dbo.ac_Products.ProductId,
dbo.ac_Products.Name,
dbo.ac_Products.Sku,
dbo.ac_CatalogNodes.CatalogNodeId,
dbo.ac_Categories.CategoryId,
dbo.ac_CatalogNodes.CategoryId,
dbo.ac_Categories.Name
FROM
dbo.ac_Products
INNER JOIN dbo.ac_CatalogNodes ON dbo.ac_Products.ProductId = dbo.ac_CatalogNodes.CatalogNodeId
INNER JOIN dbo.ac_Categories ON dbo.ac_CatalogNodes.CategoryId = dbo.ac_Categories.CategoryId


Everything works fine until you bring the CategoryParents table into the picture, it seems that if you have a product that is nested 2 levels deep, then it would have multiple parents. So if, I check the main category just one time, under category B, and category B is a child of Category A, then in reality the product would have two parent categories as opposed to one, even though category A is not checked.

I just want to make sure that this is correct, since linking the CategoryParents table to the above SQL query will create multiple instances of the same product.

Am I correct on this?

Many Thanks

Edited by user Wednesday, March 4, 2020 12:29:35 AM(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

mazhar  
#2 Posted : Wednesday, March 4, 2020 5:08:21 AM(UTC)
mazhar

Rank: Administration

Groups: Admin, Administrators, HelpDesk, System, Authorized User, Developers, Registered
Joined: 10/5/2018(UTC)
Posts: 175

Thanks: 8 times
Was thanked: 17 time(s) in 15 post(s)
Category Parents are used to keep track of category hierarchies and when you want to traverse the entire category hierarchy. If you are just looking to get the name of immediate parent category for a product then you should be using the ac_CatalogNodes table with product. This query will result with duplicate product entries with each with a different parent category name if product is placed in multiple categories. This is exactly what your above query is outputting at the moment.

Please use the dbo.ac_CatalogNodes.CatalogNodeType to further restrict to a single type of catalog nodes if you are looking only for products.

Code:
SELECT
dbo.ac_Products.ProductId,
dbo.ac_Products.Name,
dbo.ac_Products.Sku,
dbo.ac_CatalogNodes.CatalogNodeId,
dbo.ac_Categories.CategoryId,
dbo.ac_CatalogNodes.CategoryId,
dbo.ac_Categories.Name
FROM
dbo.ac_Products
INNER JOIN dbo.ac_CatalogNodes ON dbo.ac_Products.ProductId = dbo.ac_CatalogNodes.CatalogNodeId AND dbo.ac_CatalogNodes.CatalogNodeTypeId = 1
INNER JOIN dbo.ac_Categories ON dbo.ac_CatalogNodes.CategoryId = dbo.ac_Categories.CategoryId


Catalog Node Type Values:- Category = 0, Product = 1 and Webpage = 2
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.