Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty tierprices should remove the form row #81

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 31 additions & 0 deletions src/Form/TierPriceMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Brille24\SyliusTierPricePlugin\Form;

use Symfony\Component\Form\DataMapperInterface;
use Traversable;

class TierPriceMapper implements DataMapperInterface
{
public function __construct(private DataMapperInterface $inner) {}

public function mapDataToForms($viewData, Traversable $forms)

Check failure on line 14 in src/Form/TierPriceMapper.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Method Brille24\SyliusTierPricePlugin\Form\TierPriceMapper::mapDataToForms() has no return typehint specified.

Check failure on line 14 in src/Form/TierPriceMapper.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Method Brille24\SyliusTierPricePlugin\Form\TierPriceMapper::mapDataToForms() has no return typehint specified.
{
$this->inner->mapDataToForms($viewData, $forms);
}

public function mapFormsToData(Traversable $forms, &$viewData)

Check failure on line 19 in src/Form/TierPriceMapper.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Method Brille24\SyliusTierPricePlugin\Form\TierPriceMapper::mapFormsToData() has no return typehint specified.

Check failure on line 19 in src/Form/TierPriceMapper.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Method Brille24\SyliusTierPricePlugin\Form\TierPriceMapper::mapFormsToData() has no return typehint specified.
{
$formData = iterator_to_array($forms);
if ($formData['qty']->getData() === null
&& $formData['price']->getData() === null
&& $formData['channel']->getData() === null
) {
$viewData = null;
} else {
$this->inner->mapFormsToData($forms, $viewData);
}
}
}
5 changes: 5 additions & 0 deletions src/Form/TierPriceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

class TierPriceType extends AbstractType
{
public function __construct(private TierPriceMapper $dataMapper) {
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('qty', NumberType::class, [
Expand All @@ -45,6 +48,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->add('channel', ChannelChoiceType::class, [
'attr' => ['style' => 'display:none'],
]);

$builder->setDataMapper($this->dataMapper);
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Brille24\SyliusTierPricePlugin\Factory\TierPriceFactoryInterface;
use Brille24\SyliusTierPricePlugin\Fixtures\TierPriceFixture;
use Brille24\SyliusTierPricePlugin\Form\Extension\ProductVariantTypeExtension;
use Brille24\SyliusTierPricePlugin\Form\TierPriceMapper;
use Brille24\SyliusTierPricePlugin\Form\TierPriceType;
use Brille24\SyliusTierPricePlugin\Repository\TierPriceRepositoryInterface;
use Brille24\SyliusTierPricePlugin\Services\OrderPricesRecalculator;
Expand All @@ -27,6 +28,7 @@
use Sylius\Bundle\ProductBundle\Form\Type\ProductVariantType;
use Sylius\Component\Core\Calculator\ProductVariantPricesCalculatorInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand Down Expand Up @@ -66,7 +68,11 @@
->tag('sylius_fixtures.fixture')
;

$services->set(TierPriceType::class);
$services->set(TierPriceType::class)
->args([TierPriceMapper::class]);

$services->set(TierPriceMapper::class)
->args([DataMapper::class]);

$services->set(ProductVariantTypeExtension::class)
->tag('form.type_extension', ['extended_type' => ProductVariantType::class, 'priority' => -5])
Expand Down
Loading