getCategories example

'invoice_amount_min' => (float) $customer->getOrderInformation()->getMinAmount(),
            'invoice_amount_max' => (float) $customer->getOrderInformation()->getMaxAmount(),
            'first_order_time' => $this->formatDate($customer->getOrderInformation()->getFirstOrderTime()),
            'last_order_time' => $this->formatDate($customer->getOrderInformation()->getLastOrderTime()),
            'has_canceled_orders' => $customer->getOrderInformation()->hasCanceledOrders(),
            'ordered_at_weekdays' => $this->implodeUnique($customer->getOrderInformation()->getWeekdays()),
            'ordered_in_shops' => $this->implodeUnique($customer->getOrderInformation()->getShops()),
            'ordered_on_devices' => $this->implodeUnique($customer->getOrderInformation()->getDevices()),
            'ordered_with_deliveries' => $this->implodeUnique($customer->getOrderInformation()->getDispatches()),
            'ordered_with_payments' => $this->implodeUnique($customer->getOrderInformation()->getPayments()),
            'ordered_products' => $this->implodeUnique($customer->getOrderInformation()->getProducts()),
            'ordered_products_of_categories' => $this->implodeUnique($customer->getOrderInformation()->getCategories()),
            'ordered_products_of_manufacturer' => $this->implodeUnique($customer->getOrderInformation()->getManufacturers()),
        ];

        return $data;
    }

    private function createInsertQuery()
    {
        return $this->connection->prepare(
            'INSERT INTO s_customer_search_index ( id, email, active, accountmode, firstlogin, newsletter, shop_id, default_billing_address_id, title, salutation, firstname, lastname, birthday, customernumber, customer_group_id, customer_group_name, payment_id, company, department, street, zipcode, city, phone, additional_address_line1, additional_address_line2, country_id, country_name, state_id, age, count_orders , invoice_amount_sum, invoice_amount_avg, invoice_amount_min, invoice_amount_max, first_order_time, last_order_time, has_canceled_orders, ordered_at_weekdays, ordered_in_shops, ordered_on_devices, ordered_with_deliveries, ordered_with_payments, product_avg, ordered_products, ordered_products_of_categories, ordered_products_of_manufacturer, index_time ) VALUES ( :id, :email, :active, :accountmode, :firstlogin, :newsletter, :shop_id, :default_billing_address_id, :title, :salutation, :firstname, :lastname, :birthday, :customernumber, :customer_group_id, :customer_group_name, :payment_id, :company, :department, :street, :zipcode, :city, :phone, :additional_address_line1, :additional_address_line2, :country_id, :country_name, :state_id, :age, :count_orders, :invoice_amount_sum, :invoice_amount_avg, :invoice_amount_min, :invoice_amount_max, :first_order_time, :last_order_time, :has_canceled_orders, :ordered_at_weekdays, :ordered_in_shops, :ordered_on_devices, :ordered_with_deliveries, :ordered_with_payments, :product_avg, :ordered_products, :ordered_products_of_categories, :ordered_products_of_manufacturer, NOW() )'
/** * Loads plugin category data and organizes it in tree format * If no categories are found for the original locale, a fallback is used instead * * @param string $locale * @param string $fallbackLocale * * @return CategoryStruct[] */
    public function get($locale$fallbackLocale)
    {
        $categories = $this->getCategories($locale$fallbackLocale);

        $firstLevel = $categories[null];

        return $this->buildTree($firstLevel$categories);
    }

    /** * @throws \Doctrine\DBAL\DBALException */
    public function synchronize()
    {
        
$prices = $product->getPrices();
        if (empty($prices)) {
            return false;
        }

        if ($this->config->get('hideNoInStock') && !$product->isAvailable() && !$product->hasAvailableVariant()) {
            return false;
        }

        $ids = array_map(function DCategory $category) {
            return $category->getId();
        }$product->getCategories());

        return \in_array($context->getShop()->getCategory()->getId()$ids);
    }

    private function allowBuyInListing(ListProduct $product): bool
    {
        return !$product->hasConfigurator()
            && $product->isAvailable()
            && $product->getUnit()
            && $product->getUnit()->getMinPurchase() <= 1
            && !$product->displayFromPrice();
    }
$versionContext = $context->createWithVersionId($versionId);

        $criteria = new Criteria([$productId]);
        $criteria->addAssociation('categories');

        /** @var ProductEntity $product */
        $product = $this->productRepository
            ->search($criteria$context)
            ->first();

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertInstanceOf(CategoryCollection::class$product->getCategories());
        static::assertCount(2, $product->getCategories());

        $categories = $this->connection->fetchAllAssociative(
            'SELECT * FROM product_category WHERE product_id = :id AND product_version_id = :version',
            ['id' => Uuid::fromHexToBytes($productId), 'version' => Uuid::fromHexToBytes($versionId)]
        );

        static::assertCount(2, $categories);

        foreach ($categories as $category) {
            $categoryVersion = Uuid::fromBytesToHex($category['category_version_id']);
            


        $availability = null;
        $listingPrices = null;
        $combinations = null;
        $configurations = null;
        $variantConfiguration = null;
        $products = $this->productGateway->getList($numbers$context);
        $average = $this->voteService->getAverages($products$context);
        $cheapest = $this->getCheapestPrices($products$shop->getId());
        $calculated = $this->getCalculatedPrices($shop$products$cheapest);
        $categories = $this->getCategories($products);
        $properties = $this->getProperties($products$context);

        $variantFacet = $this->variantHelper->getVariantFacet();

        $productIds = array_map(
            static function DListProduct $product) {
                return $product->getId();
            },
            $products
        );

        
$view->assign('sNotesQuantity', $view->getAssign('sNotesQuantity') ?: 0);
        $view->assign('sUserLoggedIn', $view->getAssign('sUserLoggedIn') ?: false);

        $view->assign('Shop', $shop);
        if (!$shop->getLocale() instanceof ShopLocale) {
            throw new RuntimeException('Shop does not have a locale set');
        }
        $view->assign('Locale', $shop->getLocale()->getLocale());

        $view->assign('sCategoryStart', $shop->getCategory()->getId());
        $view->assign('sCategoryCurrent', $this->getCategoryCurrent($view->getAssign('sCategoryStart')));
        $view->assign('sCategories', $this->getCategories($view->getAssign('sCategoryCurrent')));
        $view->assign('sMainCategories', $view->getAssign('sCategories'));
        $view->assign('sOutputNet', Shopware()->Session()->get('sOutputNet'));

        $activePage = $view->getAssign('sCustomPage')['id'] ?? null;
        $view->assign('sMenu', $this->getMenu($shop->getId()$activePage));

        $view->assign('sShopname', Shopware()->Config()->get('shopName'));
    }

    /** * Returns basket amount * * @return float */
return Profiler::trace('navigation-route', function D) use ($activeId$rootId$request$context$criteria) {
            if ($context->hasState(...$this->states)) {
                return $this->getDecorated()->load($activeId$rootId$request$context$criteria);
            }

            $depth = $request->query->getInt('depth', $request->request->getInt('depth', 2));

            // first we load the base navigation, the base navigation is shared for all storefront listings             $response = $this->loadNavigation($request$rootId$rootId$depth$context$criteria[self::ALL_TAG, self::BASE_NAVIGATION_TAG]);

            // no we have to check if the active category is loaded and the children of the active category are loaded             if ($this->isActiveLoaded($rootId$response->getCategories()$activeId)) {
                return $response;
            }

            // reload missing children of active category, depth 0 allows us the skip base navigation loading in the core route             $active = $this->loadNavigation($request$activeId$rootId, 0, $context$criteria[self::ALL_TAG]);

            $response->getCategories()->merge($active->getCategories());

            return $response;
        });
    }

    

    public function saveFeedAction()
    {
        $params = $this->Request()->getParams();

        $feedId = $params['id'] ?? null;
        if (!empty($feedId)) {
            // Edit Product Feed             /** @var ProductFeed $productFeed */
            $productFeed = $this->get('models')->getRepository(ProductFeed::class)->find($feedId);
            // Clear all previous associations             $productFeed->getCategories()->clear();
            $productFeed->getSuppliers()->clear();
            $productFeed->getArticles()->clear();
        } else {
            // New Product Feed             $productFeed = new ProductFeed();
            // To set this value initial             $productFeed->setLastExport('now');
        }

        if (empty($params['shopId'])) {
            $params['shopId'] = null;
        }

    protected function prepareCategoryAssociatedData($data, ProductModel $article)
    {
        if (!isset($data['categories'])) {
            return $data;
        }

        $this->resetProductCategoryAssignment($data$article);

        $categories = $article->getCategories();

        $categoryIds = $categories->map(function DCategory $category) {
            return $category->getId();
        });

        $categoryIds = array_flip($categoryIds->toArray());

        foreach ($data['categories'] as $categoryData) {
            $category = $this->getManyToManySubElement(
                $categories,
                $categoryData,
                
/** * @return array[] */
    private function resolveCategoryPath(array $data): array
    {
        $ids = [];
        foreach ($data as $row) {
            $ids = array_merge($idsexplode('|', $row['path']));
            $ids[] = $row['id'];
        }
        $ids = array_values(array_unique(array_filter($ids)));
        $categories = $this->getCategories($ids);

        foreach ($data as &$row) {
            $parents = array_filter(explode('|', $row['path']));
            $parents = array_reverse($parents);
            $path = [];
            foreach ($parents as $parent) {
                $path[] = $categories[$parent];
            }
            $path[] = $row['name'];
            $row['name'] = implode('>', $path);
        }

        
$criteria = new Criteria([$productIds[0]]);
        $criteria->addAssociation('categories');

        $product = $this->productRepository->search($criteria$context)->first();

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertNotSame($name$product->getName());
        static::assertSame(Uuid::fromStringToHex('tax19')$product->getTaxId());
        static::assertSame(Uuid::fromStringToHex('manufacturer1')$product->getManufacturerId());

        static::assertInstanceOf(CategoryCollection::class$categories = $product->getCategories());
        static::assertCount(3, $categories);
        static::assertTrue($categories->has($category1Id));
        static::assertTrue($categories->has($category2Id));
        static::assertTrue($categories->has($category3Id));
    }

    public function testProductsWithCategoryPaths(): void
    {
        $context = Context::createDefaultContext();
        $context->addState(EntityIndexerRegistry::DISABLE_INDEXING);

        
$dispatchModel->getCountries()->add($countryModel);
            }
        }

        foreach ($categories as $category) {
            if (empty($category['id'])) {
                continue;
            }

            $categoryModel = $this->getModelManager()->find(Category::class$category['id']);
            if ($categoryModel instanceof Category) {
                $dispatchModel->getCategories()->add($categoryModel);
            }
        }

        foreach ($holidays as $holiday) {
            if (empty($holiday['id'])) {
                continue;
            }

            $holidayModel = $this->getModelManager()->find(Holiday::class$holiday['id']);
            if ($holidayModel instanceof Holiday) {
                $dispatchModel->getHolidays()->add($holidayModel);
            }
$criteria = new Criteria([$id]);
        $criteria->addAssociation('categories');

        $products = $this->salesChannelProductRepository->search($criteria$context);

        static::assertCount(1, $products);

        /** @var SalesChannelProductEntity $product */
        $product = $products->first();
        static::assertInstanceOf(SalesChannelProductEntity::class$product);

        static::assertCount(1, $product->getCategories());
    }
}
$id = $before($ids$context$this->getContainer());

        $route->load($id$root, self::request($depth)$contextnew Criteria());
        $route->load($id$root, self::request($depth)$contextnew Criteria());

        $after($ids$context$this->getContainer());

        $route->load($id$root, self::request($depth)$contextnew Criteria());
        $response = $route->load($id$root, self::request($depth)$contextnew Criteria());

        static::assertTrue($response->getCategories()->has($id));
        static::assertTrue($response->getCategories()->count() > 0);
    }

    public static function invalidationProvider(): \Generator
    {
        $ids = new IdsCollection();

        yield 'Test root call' => [
            $ids,
            2,
            fn (IdsCollection $ids): string => $ids->get('navigation'),
            
/** @var ProductEntity $product */
        $product = $this->productRepository->search($criteria, Context::createDefaultContext())->first();

        $this->createProductStreams();
        $this->createCategoryStreams();
        $product->setStreamIds([$this->ids->create('stream_id_1')]);

        $category = $this->breadcrumbBuilder->getProductSeoCategory($product$this->salesChannelContext);
        $category2 = $this->breadcrumbBuilder->getProductSeoCategory($product$this->contextFactory->create('', $this->ids->get('sales-channel-2')));

        static::assertInstanceOf(CategoryCollection::class$product->getCategories());

        if ($hasCategories) {
            static::assertInstanceOf(CategoryEntity::class$category);
            static::assertInstanceOf(CategoryEntity::class$category2);
            static::assertNotCount(0, $product->getCategories());

            if ($hasMainCategory) {
                static::assertSame($this->ids->get('navigation-a-1')$category->getId());
            } else {
                static::assertTrue(\in_array($category->getId()$this->ids->prefixed('navigation-a'), true));
            }

            
Home | Imprint | This part of the site doesn't use cookies.