Question: I have a magento shop with over 3000 products and 1000 categories.

```
Category I
      Category 1
      Category 2
Category II
      Category 3
      Category 4

```

My problem is that all the products are only in the deepest categories. For example: A product in Category 3 also has to be in Category II, but it's not. Is there a way to do this via php script with all the products?

Thanks in advance!

Answer: 
```
private Fragment getVisibleFragment() {
        FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
        List<Fragment> fragments = fragmentManager.getFragments();
        for (Fragment fragment : fragments) {
            if (fragment != null && fragment.isVisible())
                return fragment;
        }
        return null;
}

```

**Usage**

```
if (getVisibleFragment() instanceof HomeScreen) {
  // Logic here...
}

```

Were `MainActivity` is the holder and `HomeScreen` is your one of the fragment.
```
public boolean checkFragmentAvailableOrNot1(String fragmentName) 
{
   Fragment fragment=getSupportFragmentManager().findFragmentByTag(fragmentName);
    if (fragment instanceof FragMercado && fragment.isVisible()) 
    {
        return true;
    }
    return false;
}

```