<?php declare(strict_types=1);
namespace Expert\ExpertDepositExtension;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
class ExpertDepositExtension extends Plugin
{
/**
* @param InstallContext $context
*/
public function install(InstallContext $context): void
{
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->create(
[
[
'name' => 'deposit',
'config' => [
'label' => [
'de-DE' => 'Pfand Zuschlag',
'en-GB' => 'Deposit',
],
],
'customFields' => [
[
'name' => 'deposit',
'type' => CustomFieldTypes::FLOAT,
'config' => [
'min' => 0,
'label' => [
'de-DE' => 'Pfandbetrag eingeben',
'en-GB' => 'Enter deposit value',
],
],
],
],
'relations' => [
[
'entityName' => 'product',
],
],
],
],
$context->getContext()
);
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context): void
{
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$entitites = $customFieldSetRepository->search(
(new Criteria())->addFilter(
new MultiFilter(
MultiFilter::CONNECTION_OR,
[
new EqualsFilter('name', 'deposit')
]
)
),
\Shopware\Core\Framework\Context::createDefaultContext()
);
foreach ($entitites->getEntities() as $_entityId => $_entityData) {
$customFieldSetRepository->delete(
[
['id' => $_entityId],
],
\Shopware\Core\Framework\Context::createDefaultContext()
);
}
}
}