Adapter/ShopwareAdapter/RequestGenerator/Product/ProductRequestGenerator.php
private function getCategories(Product $product)
    {
        /**
         * @var CategoryRepository $categoryRepository
         */
        $categoryRepository = $this->entityManager->getRepository(CategoryModel::class);

        /**
         * @var ShopRepository $shopRepository
         */
        $shopRepository = $this->entityManager->getRepository(ShopModel::class);

        $shopCategories = [];

        foreach ($product->getShopIdentifiers() as $shopIdentifier) {
            $identities = $this->identityService->findBy([
                    'objectIdentifier' => (string) $shopIdentifier,
                    'objectType' => Shop::TYPE,
                    'adapterName' => ShopwareAdapter::NAME,
            ]);

            if ($identities === null) {
                continue;
            }

            foreach ($identities as $identity) {
                /**
                 * @var ShopModel $shop
                 */
                $shop = $shopRepository->find($identity->getAdapterIdentifier());

                if ($shop !== null) {
                    $shopCategories[] = $shop->getCategory()->getId();
                }
            }
        }

        $this->categories = [];

        foreach ($product->getCategoryIdentifiers() as $categoryIdentifier) {
            $categoryIdentities = $this->identityService->findBy([
                'objectIdentifier' => $categoryIdentifier,
                'objectType' => Category::TYPE,
                'adapterName' => ShopwareAdapter::NAME,
            ]);

            foreach ($categoryIdentities as $categoryIdentity) {
                if (in_array($categoryIdentity->getAdapterIdentifier(), array_column($this->categories, 'id'), true)) {
                    continue;
                }

                $category = $categoryRepository->find($categoryIdentity->getAdapterIdentifier());

                if (null === $category) {
                    continue;
                }

                $extractedCategoryPath = array_filter(explode('|', $category->getPath()));
                $matchedShopCategories = array_intersect($extractedCategoryPath, $shopCategories);

                if (empty($matchedShopCategories)) {
                    continue;
                }

                $this->categories[] = [
                    'id' => $categoryIdentity->getAdapterIdentifier(),
                ];
            }
        }

        return $this->categories;
    }
private function getCategories(Product $product)
    {
        /**
         * @var CategoryRepository $categoryRepository
         */
        $categoryRepository = $this->entityManager->getRepository(CategoryModel::class);

        /**
         * @var ShopRepository $shopRepository
         */
        $shopRepository = $this->entityManager->getRepository(ShopModel::class);

        $shopCategories = [];

        foreach ($product->getShopIdentifiers() as $shopIdentifier) {
            $identities = $this->identityService->findBy([
                    'objectIdentifier' => (string) $shopIdentifier,
                    'objectType' => Shop::TYPE,
                    'adapterName' => ShopwareAdapter::NAME,
            ]);

            if ($identities === null) {
                continue;
            }

            foreach ($identities as $identity) {
                /**
                 * @var ShopModel $shop
                 */
                $shop = $shopRepository->find($identity->getAdapterIdentifier());

                if ($shop !== null) {
                    $shopCategories[] = $shop->getCategory()->getId();
                }
            }
        }

        $this->categories = [];

        foreach ($product->getCategoryIdentifiers() as $categoryIdentifier) {
            $categoryIdentities = $this->identityService->findBy([
                'objectIdentifier' => $categoryIdentifier,
                'objectType' => Category::TYPE,
                'adapterName' => ShopwareAdapter::NAME,
            ]);

            foreach ($categoryIdentities as $categoryIdentity) {
                if (in_array($categoryIdentity->getAdapterIdentifier(), array_column($this->categories, 'id'), true)) {
                    continue;
                }

                $category = $categoryRepository->find($categoryIdentity->getAdapterIdentifier());

                if (null === $category) {
                    continue;
                }

                $extractedCategoryPath = array_filter(explode('|', $category->getPath()));
                $matchedShopCategories = array_intersect($extractedCategoryPath, $shopCategories);

                if (empty($matchedShopCategories)) {
                    continue;
                }

                $this->categories[] = [
                    'id' => $categoryIdentity->getAdapterIdentifier(),
                ];
            }
        }

        return $this->categories;
    }
@param Product $product

@return array