Skip to content

Commit

Permalink
[shopsys] move ready category seo mix from project-base to packages (…
Browse files Browse the repository at this point in the history
…#3494)
  • Loading branch information
grossmannmartin authored Nov 4, 2024
2 parents 8fb8a89 + 6bbcaa4 commit 6742d0b
Showing 24 changed files with 1,467 additions and 191 deletions.
34 changes: 34 additions & 0 deletions src/Model/Brand/BrandsBatchLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrontendApiBundle\Model\Brand;

use GraphQL\Executor\Promise\Promise;
use GraphQL\Executor\Promise\PromiseAdapter;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\Product\Brand\BrandFacade;

class BrandsBatchLoader
{
/**
* @param \GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\Product\Brand\BrandFacade $brandFacade
*/
public function __construct(
protected readonly PromiseAdapter $promiseAdapter,
protected readonly Domain $domain,
protected readonly BrandFacade $brandFacade,
) {
}

/**
* @param int[] $brandIds
* @return \GraphQL\Executor\Promise\Promise
*/
public function loadByIds(array $brandIds): Promise
{
return $this->promiseAdapter->all($this->brandFacade->getByIds($brandIds, $this->domain->getCurrentDomainConfig()));
}
}
56 changes: 56 additions & 0 deletions src/Model/Category/ReadyCategorySeoMixBatchLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrontendApiBundle\Model\Category;

use GraphQL\Executor\Promise\Promise;
use GraphQL\Executor\Promise\PromiseAdapter;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Router\FriendlyUrl\FriendlyUrlFacade;
use Shopsys\FrameworkBundle\Model\CategorySeo\ReadyCategorySeoMix;
use Shopsys\FrameworkBundle\Model\CategorySeo\ReadyCategorySeoMixFacade;

class ReadyCategorySeoMixBatchLoader
{
/**
* @param \GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter
* @param \Shopsys\FrameworkBundle\Model\CategorySeo\ReadyCategorySeoMixFacade $readyCategorySeoMixFacade
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Component\Router\FriendlyUrl\FriendlyUrlFacade $friendlyUrlFacade
*/
public function __construct(
protected readonly PromiseAdapter $promiseAdapter,
protected readonly ReadyCategorySeoMixFacade $readyCategorySeoMixFacade,
protected readonly Domain $domain,
protected readonly FriendlyUrlFacade $friendlyUrlFacade,
) {
}

/**
* @param int[] $categoryIds
* @return \GraphQL\Executor\Promise\Promise
*/
public function loadByCategoryIds(array $categoryIds): Promise
{
$allReadyCategorySeoMixes = $this->readyCategorySeoMixFacade->getAllIndexedByCategoryId($categoryIds, $this->domain->getCurrentDomainConfig());

$result = [];

foreach ($allReadyCategorySeoMixes as $readyCategorySeoMixes) {
$result[] = array_map(
fn (ReadyCategorySeoMix $readyCategorySeoMix) => [
'name' => $readyCategorySeoMix->getH1(),
'slug' => '/' . $this->friendlyUrlFacade->getMainFriendlyUrlSlug(
$this->domain->getId(),
'front_category_seo',
$readyCategorySeoMix->getId(),
),
],
$readyCategorySeoMixes,
);
}

return $this->promiseAdapter->all($result);
}
}
96 changes: 96 additions & 0 deletions src/Model/Product/BatchLoad/ProductBatchLoadByEntityData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrontendApiBundle\Model\Product\BatchLoad;

use Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterData;

class ProductBatchLoadByEntityData
{
/**
* @param string $id
* @param int $entityId
* @param string $entityClass
* @param int $limit
* @param int $offset
* @param string $orderingModeId
* @param \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterData $productFilterData
* @param string $search
*/
public function __construct(
protected readonly string $id,
protected readonly int $entityId,
protected readonly string $entityClass,
protected readonly int $limit,
protected readonly int $offset,
protected readonly string $orderingModeId,
protected readonly ProductFilterData $productFilterData,
protected readonly string $search = '',
) {
}

/**
* @return string
*/
public function getId(): string
{
return $this->id;
}

/**
* @return int
*/
public function getEntityId(): int
{
return $this->entityId;
}

/**
* @return string
*/
public function getEntityClass(): string
{
return $this->entityClass;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterData
*/
public function getProductFilterData(): ProductFilterData
{
return $this->productFilterData;
}

/**
* @return int
*/
public function getLimit(): int
{
return $this->limit;
}

/**
* @return int
*/
public function getOffset(): int
{
return $this->offset;
}

/**
* @return string
*/
public function getOrderingModeId(): string
{
return $this->orderingModeId;
}

/**
* @return string
*/
public function getSearch(): string
{
return $this->search;
}
}
Loading

0 comments on commit 6742d0b

Please sign in to comment.