Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\DataProvider\Provider\Data;

use Shopware\Core\Content\Product\ProductCollection;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;

#[Package('fundamentals@after-sales')]
class ProductCanonicalAssociationProvider extends AbstractProvider
{
private const BUNDLE_PRODUCT_TYPE = 'grouped_bundle';

/**
* @param EntityRepository<ProductCollection> $productRepo
*/
public function __construct(private readonly EntityRepository $productRepo)
{
}

public function getIdentifier(): string
{
return DefaultEntities::PRODUCT_CANONICAL_ASSOCIATION;
}

public function getProvidedData(int $limit, int $offset, Context $context): array
{
$criteria = new Criteria();
$criteria->setLimit($limit);
$criteria->setOffset($offset);
$this->addBundleExclusionFilter($criteria);
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('canonicalProductId', null),
]));
$criteria->addSorting(new FieldSorting('id'));
$result = $this->productRepo->search($criteria, $context)->getEntities();

$neededResult = [];

foreach ($result as $item) {
$neededResult[] = [
'id' => $item->getId(),
'canonicalProductId' => $item->getCanonicalProductId(),
];
}

return $this->cleanupSearchResult($neededResult);
}

public function getProvidedTotal(Context $context): int
{
$criteria = new Criteria();
$this->addBundleExclusionFilter($criteria);
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('canonicalProductId', null),
]));

return $this->readTotalFromRepo($this->productRepo, $context, $criteria);
}

private function addBundleExclusionFilter(Criteria $criteria): void
{
if (!$this->hasTypeColumn()) {
return;
}

$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('type', self::BUNDLE_PRODUCT_TYPE),
]));
}

private function hasTypeColumn(): bool
{
return $this->productRepo->getDefinition()->getField('type') !== null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\DataProvider\Provider\Data;

use Shopware\Core\Content\Product\ProductCollection;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;

#[Package('fundamentals@after-sales')]
class ProductCmsPageAssociationProvider extends AbstractProvider
{
private const BUNDLE_PRODUCT_TYPE = 'grouped_bundle';

/**
* @param EntityRepository<ProductCollection> $productRepo
*/
public function __construct(private readonly EntityRepository $productRepo)
{
}

public function getIdentifier(): string
{
return DefaultEntities::PRODUCT_CMS_PAGE_ASSOCIATION;
}

public function getProvidedData(int $limit, int $offset, Context $context): array
{
$criteria = new Criteria();
$criteria->setLimit($limit);
$criteria->setOffset($offset);
$this->addBundleExclusionFilter($criteria);
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('cmsPageId', null),
]));
$criteria->addSorting(new FieldSorting('id'));
$result = $this->productRepo->search($criteria, $context)->getEntities();

$neededResult = [];

foreach ($result as $item) {
$neededResult[] = [
'id' => $item->getId(),
'cmsPageId' => $item->getCmsPageId(),
];
}

return $this->cleanupSearchResult($neededResult);
}

public function getProvidedTotal(Context $context): int
{
$criteria = new Criteria();
$this->addBundleExclusionFilter($criteria);
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('cmsPageId', null),
]));

return $this->readTotalFromRepo($this->productRepo, $context, $criteria);
}

private function addBundleExclusionFilter(Criteria $criteria): void
{
if (!$this->hasTypeColumn()) {
return;
}

$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('type', self::BUNDLE_PRODUCT_TYPE),
]));
}

private function hasTypeColumn(): bool
{
return $this->productRepo->getDefinition()->getField('type') !== null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\DataProvider\Provider\Data;

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\SalesChannel\SalesChannelCollection;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;

#[Package('fundamentals@after-sales')]
class SalesChannelHomeCmsPageAssociationProvider extends AbstractProvider
{
/**
* @param EntityRepository<SalesChannelCollection> $salesChannelRepo
*/
public function __construct(private readonly EntityRepository $salesChannelRepo)
{
}

public function getIdentifier(): string
{
return DefaultEntities::SALES_CHANNEL_HOME_CMS_PAGE_ASSOCIATION;
}

public function getProvidedData(int $limit, int $offset, Context $context): array
{
$criteria = new Criteria();
$criteria->setLimit($limit);
$criteria->setOffset($offset);
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('homeCmsPageId', null),
]));
$criteria->addSorting(new FieldSorting('id'));
$result = $this->salesChannelRepo->search($criteria, $context)->getEntities();

$neededResult = [];

foreach ($result as $item) {
$neededResult[] = [
'id' => $item->getId(),
'homeCmsPageId' => $item->getHomeCmsPageId(),
];
}

return $this->cleanupSearchResult($neededResult);
}

public function getProvidedTotal(Context $context): int
{
$criteria = new Criteria();
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [
new EqualsFilter('homeCmsPageId', null),
]));

return $this->readTotalFromRepo($this->salesChannelRepo, $context, $criteria);
}
}
2 changes: 1 addition & 1 deletion src/DataProvider/Provider/Data/SalesChannelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getProvidedData(int $limit, int $offset, Context $context): arra
$criteria->addSorting(new FieldSorting('id'));
$result = $this->salesChannelRepo->search($criteria, $context);

return $this->cleanupSearchResult($result, ['analyticsId', 'hreflangDefaultDomainId', 'deliveryTime', 'paymentMethodIds']);
return $this->cleanupSearchResult($result, ['analyticsId', 'hreflangDefaultDomainId', 'deliveryTime', 'paymentMethodIds', 'homeCmsPageId']);
}

public function getProvidedTotal(Context $context): int
Expand Down
15 changes: 15 additions & 0 deletions src/DependencyInjection/dataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use SwagMigrationAssistant\DataProvider\Provider\Data\OrderProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\PageSystemConfigProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\PaymentMethodProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\ProductCanonicalAssociationProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\ProductCmsPageAssociationProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\ProductFeatureSetProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\ProductManufacturerProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\ProductProvider;
Expand All @@ -52,6 +54,7 @@
use SwagMigrationAssistant\DataProvider\Provider\Data\PropertyGroupProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\RuleProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\SalesChannelDomainProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\SalesChannelHomeCmsPageAssociationProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\SalesChannelProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\SalutationProvider;
use SwagMigrationAssistant\DataProvider\Provider\Data\SeoUrlProvider;
Expand Down Expand Up @@ -132,6 +135,14 @@
])
->tag('shopware.dataProvider.provider');

$services->set(ProductCanonicalAssociationProvider::class)
->args([service('product.repository')])
->tag('shopware.dataProvider.provider');

$services->set(ProductCmsPageAssociationProvider::class)
->args([service('product.repository')])
->tag('shopware.dataProvider.provider');

$services->set(TaxProvider::class)
->args([service('tax.repository')])
->tag('shopware.dataProvider.provider');
Expand Down Expand Up @@ -164,6 +175,10 @@
->args([service('sales_channel.repository')])
->tag('shopware.dataProvider.provider');

$services->set(SalesChannelHomeCmsPageAssociationProvider::class)
->args([service('sales_channel.repository')])
->tag('shopware.dataProvider.provider');

$services->set(SalesChannelDomainProvider::class)
->args([service('sales_channel_domain.repository')])
->tag('shopware.dataProvider.provider');
Expand Down
Loading
Loading