Jump to content

SQL command


Dave L

Recommended Posts

Hi

 

Could anyone having MySQL database experience tell be what the command line should be to en-mass uncheck the home selection in Products>Associations please. 

The site I am working on for a friend has about 500 products with Home selected so featured products has a few too many selections :-0

 

Thanks.

Link to comment
Share on other sites

Hello,

DELETE FROM `ps_category_product` WHERE id_category = 2

amicalement

 

Hi,

With a fresh mind I relooked and you were totally correct. The problem was my Home Category was 1 and not 2. So using the original query removed all from Category 2.

 

So now I need to have all products in subcategory 13, 14, 15 16, 17, 18 and 109 to also be included it Category 2.

 

Appreciate your further help.

 

Thank you.

Edited by Dave L (see edit history)
Link to comment
Share on other sites

You are acting a bit risky now. If you had products that were only in category 1 or 2 they are no longer accessible in the backoffice.

 

The problem that you are asking now is that it concerns a quite complex query - what requires that someone tests it well before applying. Most people would do this with a mix of php and Mysql instead.

 

For this kind of problem it is much easier to use a tool like Prestools. Prestools is free.

Edited by musicmaster (see edit history)
Link to comment
Share on other sites

You are acting a bit risky now. If you had products that were only in category 1 or 2 they are no longer accessible in the backoffice.

 

The problem that you are asking now is that it concerns a quite complex query - what requires that someone tests it well before applying. Most people would do this with a mix of php and Mysql instead.

 

For this kind of problem it is much easier to use a tool like Prestools.

 

Hi

 

Thanks for the advice. Actually all of the products are in the other categories as well.

I need to have the products that are in subcategories 13, 14, 15 16, 17, 18 and 109 also included in the parent category which is category 2.

 

categories.jpg

 

If this is complicated or a dangerous thing to do I will have to go through each products association manually :wacko:  :wacko:  :wacko:

 

Thanks.

Link to comment
Share on other sites

First, you need to find out all child categories or parent category 2:

select c.id_category 
from ps_category p, 
     ps_category c 
where p.id_category = 2 
  and c.nleft >= p.nleft 
  and c.nright <= p.nright

Then, find out all distinct products associated with these children categories

select distinct pc.id_product 
from ps_category_product pc 
where pc.id_category in (
  select c.id_category 
  from ps_category p, 
       ps_category c 
  where p.id_category = 2 
    and c.nleft >= p.nleft 
    and c.nright <= p.nright
)

And now the association. The clean way would be to remove already associated product from the list. But since we are lazy, we can use insert ignore :)

insert ignore into ps_category_product(id_product, id_category) 
select distinct pc.id_product, 2
from ps_category_product pc
where pc.id_category in (
  select c.id_category
  from ps_category p,
       ps_category c
  where p.id_category = 2
    and c.nleft >= p.nleft
    and c.nright <= p.nright
)

Hope this helps a bit

  • Like 1
Link to comment
Share on other sites

Hi DataKick

 

Appreciate your time in putting this together for me. It's a bit late this evening but I will study it over the coming days to see if I dare have a go with it.

 

I will post back when I have a result, good or bad  :rolleyes:

 

Appreciated.

 

 

Edit:

Just a thought, would it make the job easier if I captured all the product ID's ?

Edited by Dave L (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...