Totally Zenned
- Join Date:
- Jul 2012
- Posts:
- 16,908
- Plugin Contributions:
- 2
Unable to display linked product in category page
snk060:
To come out of this issue, what I was doing is:
Suppose I have 4 product (p1, p2, p3, p4) and 2 category (cat1, cat2)
Earlier:
Cat 1 (p1, p2, p3, p4) => so it displays (p1, p2, p3, p4)
Cat 2 (all linked product) => so it displays (nothing)Now:
Cat 1 (p1, p2 + 2 linked pdt) => so it displays (p1, p2)
Cat 2 (p3, p4 + 2 linked pdt) => so it displays (p3, p4)I did like this to display atleast some product in cat 2. So that Cat 2 will not be completely blank.
But, if I have only one product in category then
Cat 1 (p1) => so it displays (p1)
Cat 2 (linked ptd) => it displays nothing coz of linked pdt.
Okay, so I went back to my previous data and query... Considering that Zen-Cart doesn't force relationships, I reworked the data and the SQL to handle multiple languages, multiple products, and made sure that it could handle a linked product (product_id exists mutliple times with only one category for each instance of the product_id in the products to categories table). This is what I came up with, though I haven't compared it to the previous three provided:
SELECT p.products_type, m.manufacturers_name, pd.products_name
FROM pd, ptc, m, p
WHERE (((p.products_id)=[pd].[product_id] And (p.products_id)=[ptc].[products_id]) AND ((p.manufacturers_id)=[m].[manufacturers_id]) AND ((pd.language_id)=1) AND ((ptc.category_id)=1) AND ((p.products_status)=1));
From the above: p is the products table, m is the manufacturers table, pd is the product description, and ptc is the products to categories table.
In the where statement: ptc.category_id = 1 <- 1 is the current category being referenced (Ie., the category from your query that is defined before this code.)
pd.language_id = 1 where 1 is to be set to the current language.
That should fix your issues now that I have properly considered the categories data to be the products_to_categories table.
The list of parentheses may not be necessary; however, the above works when the tables are properly filled out.
Dataset was this:
two languages
four products
two categories
two manufacturers
two product descriptions for each product (one for each language in pd). Don't have a "language override" in this, if the product description does not exist in the language of choice, then it is not displayed... Apparently to force even a null, the application being used indicated that an additional query would be necessary to then be inserted into this query... I didn't go and develop that.. :/ Supposedly the outer joins necessary to make it work were "too confusing" for the application... I think ideally, would want to query the pd table against the p table on the language of choice, such that all p's were returned and those pd's that were equivalent were provided and NULL for the remaining. Then where NULL is provided to give back the pd in the default language. But as it currently stands, if the pd does not exist in the language of choice (no record in the pd for the language of choice), that row of data is not returned... I don't have multiple language in place on my site, so I can not tell if the existence of a second language forces a product description record for the other language(s) even if no data is in the fields... I am hoping it does force a record for the sake of this query...
p1 and p4 main category was 1 (table p)
p2 and p3 main category was 2 (table p)
p1, p3, p4 were in category 1 (as listed in ptc)
p2, p3, p4 were in category 2 (as listed in ptc)
Therefore can see that products p3 and p4 are linked products between categories 1 and 2, while p1 and p2 are each in their own category alone.
p1 and p4 were manufacturer 1 (table m)
p2 and p3 were manufacturer 2 (table m)
the above query as written provided results for p1, p3, and p4 as expected because looking at the category being category 1.
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...