For some products, in default scope, only root category is chooseable? - magento

just stumbled across a weird Magento problem.
Some products in the backend only has "root" as a chooseable category in the categories tab... but all categories appear if i choose a storefront as scoope.
While some other products has the whole tree chooseable in the default scope.
Index & cache has been reset.
Any clues? Please :)

you can find the solution here:
http://zaclee.net/magento/errors-magento/magento-product-edit-only-shows-default-category
Greetz!

Theres another solution in comments there. I changed it to find the categories with inconsistent children count without modifying them in the first place:
select
entity_id,
children_count,
(select (SELECT count(*) from catalog_category_entity u1
where u1.path REGEXP CONCAT('^',u2.path,'/[[:digit:]]+$'))
from catalog_category_entity u2
where u2.path = w1.path)
as actual_children_count
from catalog_category_entity w1
having children_count != actual_children_count
After you examine the offending records, run the update by Tim Schmidt:
CREATE TABLE catalog_category_entity_test AS SELECT * FROM catalog_category_entity;
UPDATE catalog_category_entity w1
SET children_count = (
select (SELECT count(*) from catalog_category_entity_test u1
where u1.path REGEXP CONCAT('^',u2.path,'/[[:digit:]]+$'))
from catalog_category_entity_test u2 where u2.path = w1.path)
DROP TABLE catalog_category_entity_test;

Related

nested query for same table oracle

We have a table where we maintain the menu and submenus for the main menu,
for ex, I have the main menu called Warehouse->and submenus Admin and USer and user-profile and edit profile are nested menus for each submenu.
we have a column called function id and parent id to differentiate menu and its submenus suppose say functionid for a warehouse is 5 admin parent id will be 5 and function id of admin will be parent id for user-profile and edit profile, where functionid is unique for all and parentid will act as foreign key in the same table.
now I need to update the column say URL for only user profile which is under admin->warehouse. first, I tried with a select query like
select * from TIFX_CM_MENU_MAIN t1 where function='User Profile' and t1.PARENTID in
(select t2.FUNCTIONID from TIFX_CM_MENU_MAIN t2 where t2.function='Admin' and t2.PARENTID in
(select t3.FUNCTIONID from TIFX_CM_MENU_MAIN t3 where t3.function='WareHouse Operator')) ;
but looks some issue in the query, can anyone help me to get the expected result.
Thank you
Might be easier to understand and maintain this query (though it's might be a bit slower):
select t1.*
from TIFX_CM_MENU_MAIN t1
left join TIFX_CM_MENU_MAIN t2 on t1.PARENTID = t2.FUNCTIONID
left join TIFX_CM_MENU_MAIN t3 on t2.PARENTID = t3.FUNCTIONID
where t1.function = 'User Profile' and
t2.function = 'Admin' and
t3.function = 'WareHouse Operator';

Update with count and group by expressions

First, I know there is a common issue in Stack Overflow, but the following solutions are not working well here. So I still need some help.
Oracle - Update COUNT of rows with specific value
Oracle - Update rows with a min value in the group of a column from another table
Oracle update statement with group function
Oracle - Update COUNT of rows with specific value
The problem is: I have a +700k lines table:
REVIEWS (PRODUCT_ID, REVIEW, REVIEW_DATE, RELEASE_DATE, ..., REVIEW_COUNT)
I'm trying to update REVIEW_COUNT by counting the lines with the same PRODUCT_ID (I want just reviews before product release). So the code below works very well for my purpose:
SELECT COUNT(PRODUCT_ID) FROM REVIEWS
WHERE REVIEW_DATE < RELEASE_DATE
GROUP BY PRODUCT_ID
But I'm having a hard time to do the update. First I tried this:
UPDATE REVIEWS R
SET R.REVIEWS_COUNT =
(SELECT COUNT(RR.PRODUCT_ID) FROM REVIEWS RR
WHERE RR.DATA < RR.REL_DATE
GROUP BY RR.PRODUCT_ID)
The error is "more than one row", which is not surprising, but since I'm using the group by statement, it shouldn't occur. So I tried a self-join:
UPDATE REVIEWS R
SET R.REVIEWS_COUNT =
(SELECT COUNT(RR.PRODUCT_ID) FROM REVIEWS RR
WHERE RR.PRODUCT_ID = R.PRODUCT_ID AND RR.DATA < RR.REL_DATE)
But the query is taking forever and I don't think that should take so long, the simple select is pretty normal-fast.
I've also tested some more fancy and more simple stuff, but the outcome remains the same: long time waiting and it seems just wrong.
Please, what I'm missing in such easy update?
Maybe instead of updating you could define view:
select product_id, review_date, release_date,
count(case when review_date < release_date then 1 end)
over (partition by product_id) review_count
from reviews;
You could also try merge instead update:
merge into reviews a
using (select product_id, count(product_id) cnt from reviews
where review_date < release_date
group by product_id ) b
on (a.product_id = b.product_id)
when matched then update set reviews_count = b.cnt
dbfiddle
I think your second update is correct:
UPDATE REVIEWS R
SET R.REVIEWS_COUNT =
(SELECT COUNT(RR.PRODUCT_ID) FROM REVIEWS RR
WHERE RR.PRODUCT_ID = R.PRODUCT_ID AND RR.DATA < RR.REL_DATE)
;
This will update every record in the reviews table. Is that what you wanted?
An index on product_id will make the inner query run faster, but it will still update all 700K or so records.

magento sql query update category from inactive to is active

I currently have an magento site with a couple of hundred categories, the problem I have is the person who added them set is active to NO. I would like to update all the main and sub categories to is_active to be YES (TRUE).
I have tried the following update Query which updated the is_active to 1 but does not update in Magento even after I re indexed all in Index Management.
UPDATE catalog_category_flat_store_1 SET is_active = 1 WHERE is_active = 0
Thanks for your help.
The catalog_category_flat_store_1 table is a generated table from the EAV tables done for performance reasons. It's not the true source of the category config data.
You'll need to update the data in the EAV. Run this query to find where is_active is stored:
SELECT t1.attribute_id, t1.attribute_code, t1.backend_type
FROM eav_entity_type AS t0
INNER JOIN eav_attribute AS t1 ON (t0.entity_type_id = t1.entity_type_id)
WHERE (t0.entity_model = 'catalog/category')
On my server it has an attribute_id of 42.
You'll then need to query catalog_category_entity and join on catalog_category_entity_int to get the rows to update.

How to JQuery PHP AJAX filter based on multiple checkbox product

I am working on a job site on which jobs will have categories titles like, salary, Sector, Location etc. The idea is to enable a visitor to filter out posts by selecting appropriate checkboxes for all these three categories and show the posts which contains category parameters chosen by the user. Here is an example of what i am looking for : http://underwearking.nl/heren/ (see the left sidebar)
I have gone through over 200 plugins and searched wordpress thoroughly but i am unable to find any plugin which fulfills this. Also, I don't know much about coding but i know that it involves something like integration of jQuery Ajax and checkboxes... Can someone please help me???
Try UNION ALL:::
select distinct wp_usermeta.user_id, wp_users.user_nicename
FROM wp_usermeta
LEFT JOIN wp_users
ON wp_usermeta.user_id=wp_users.ID
ORDER BY wp_usermeta.user_id
UNION ALL
select distinct t1.user_id ,t2.meta_value shop from wp_usermeta as t1, wp_usermeta as t2 where t1.user_id = t2.user_id and ( (t1.meta_key = 'category' and t1.meta_value like '%$catid%') ) and t2.meta_key='shop_name' order by t2.meta_value ASC
You can an extra JOIN to that table p_usermeta in the same query, then LEFT JOIN the wp_users the same way you did, something like this:
SELECT distinct
t1.user_id,
wp_users.user_nicename,
t2.meta_value shop
FROM wp_usermeta AS t1
INNER JOIN wp_usermeta as t2 ON t1.user_id = t2.user_id
LEFT JOIN wp_users ON t1.user_id = wp_users.ID
where ((t1.meta_key = 'category' and t1.meta_value like '%$catid%'))
and t2.meta_key='shop_name'
ORDER BY wp_usermeta.user_id, t2.meta_value
LIMIT 1,10"

Oracle/SQL - Join one table multiple times to the same table

I'm trying to wrap my brain around a query and hoping you can help. I have two tables: a customer_table and a product_table that look like this
name sku_num1 sku_num2 sku_num3 sku_num4
----------------------------------------------------
Bob A B C D
Frank E A
Tom G
Shelly G E
Justin E G A
sku_num widget_name
-------------------
A widget_a
B widget_b
C widget_c
D widget_d
So what I want to do is return a list of all the customers who have at least 1 product whose SKU appears in the product table. So with the above information I would receive back the records for
Bob
Frank
Justin
Any ideas how to do this?
There is no need to join one table twice:
SELECT *
FROM customers
WHERE sku_num1 IN (SELECT sku_num
FROM product_table)
OR sku_num2 IN (SELECT sku_num
FROM product_table)
....
The reason why you need multiple conditions that do a full table scan on the product_table is your wrong database design. The products a customer bought should not go into multiple columns in the customer table. Instead you should have a third table that is a N:M relation between customer and products.
Does something like this not work?
select name
from customer c, products p
where ( c.sku_num1 = p.sku)
or ( c.sku_num2 = p.sku)
or ( c.sku_num3 = p.sku)
or ( c.sku_num4 = p.sku)
Christopher,
Does this mean that you are just looking for any customers where sku_num1 or sku_num2 or sku_num3 or sku_num4 is not null?
If that's the case, you could do it two different ways.
select * from customers
where sku_num1 is not null
or sku_num2 is not null
or sku_num3 is not null
or sku_num4 is not null
If you are trying to see if they have ordered something from a specific product list, you could modify this to:
select * from customers
where sku_num1 in (select sku_num from skus)
or sku_num2 in (select sku_num from skus)
or sku_num3 in (select sku_num from skus)
or sku_num4 in (select sku_num from skus)
Incidentally, this is why people normally don't structure tables like this. There should be another join table, for lack of anything better to call it, customer_skus which would tie together customers and skus and just have a customerID and a sku_num.
This would make the query easier to write, read, and maintain. The query would look something like:
select distinct name from customers, customer_skus, skus
where customers.id = customer_skus.id
and customer_skus.sku_num = skus.sku_num
You can join a table with itself by using an alias:
select * from mytable a, mytable b where condition

Resources