0
votes

I want to create some sort of export that shows all products of all shops including product variations in a HTML table.

Can anyone tell me how to get all products with variations for all products available in all shops?

I'm using latest version of Shopware 6 (SW 6.3.3.1).

1
Do you want to write a plugin for shopware and load the products there, or do you want to load the products over the API?j_elfering
yes through plugin - i have button in configuration "Load Products" and button calling controller and controller will be calling some models to collect product data.MageSoftech
Please take a look at the docs on how to read data inside plugins: docs.shopware.com/en/shopware-platform-dev-en/developer-guide/…j_elfering

1 Answers

2
votes

You can use this method to fetch all parent products (products with variations) through the product repository (dependency inject it). This works because parent products does not have a parent and they have at least one child product.

If you want all variants, search for all products with parentId not null.

You can also consider using ->searchIds() instead of ->search() (much faster, you et the IDs only) and then fetch specific variations afterwards based on a specific parent ID.

        $criteria = new Criteria();
        $criteria->addFilter(new RangeFilter('childCount', [RangeFilter::GT => 0]));
        $criteria->addFilter(new EqualsFilter('parentId', null));

        $parentProducts = $this->productRepository->search(
            $criteria,
            Context::createDefaultContext()
        )->getElements();