Skip to content

Commit

Permalink
3 gateway for classic, predict, relay
Browse files Browse the repository at this point in the history
  • Loading branch information
ehibes committed Oct 20, 2023
1 parent 3f40f24 commit 778d276
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 14 deletions.
43 changes: 42 additions & 1 deletion features/adding_shipping_gateway_configuration_dpd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,48 @@ Feature: Creating shipping gateway

@ui
Scenario: Creating DPD shipping gateway
When I visit the create shipping gateway configuration page for "dpd"
When I visit the create shipping gateway configuration page for "dpd-classic"
And I select the "DPD" shipping method
And I fill the "DPD username" field with "username"
And I fill the "DPD password" field with "password"
And I fill the "DPD customer number" field with "123456"
And I fill the "DPD center number" field with "123"
And I fill the "DPD country code" field with "250"
And I fill the "Sender name" field with "Studio Waaz"
And I fill the "Sender address" field with "Allée d'Aguiléra"
And I fill the "Sender city" field with "Biarritz"
And I fill the "Sender country" field with "FR"
And I fill the "Sender postal code" field with "64200"
And I fill the "Sender phone number" field with "0900000000"
And I fill the "Sender email" field with "noreply@studiowaaz.com"
And I fill the "Printer format" field with "PDF"
And I add it
Then I should be notified that the shipping gateway has been created


@ui
Scenario: Creating DPD shipping predict gateway
When I visit the create shipping gateway configuration page for "dpd-predict"
And I select the "DPD" shipping method
And I fill the "DPD username" field with "username"
And I fill the "DPD password" field with "password"
And I fill the "DPD customer number" field with "123456"
And I fill the "DPD center number" field with "123"
And I fill the "DPD country code" field with "250"
And I fill the "Sender name" field with "Studio Waaz"
And I fill the "Sender address" field with "Allée d'Aguiléra"
And I fill the "Sender city" field with "Biarritz"
And I fill the "Sender country" field with "FR"
And I fill the "Sender postal code" field with "64200"
And I fill the "Sender phone number" field with "0900000000"
And I fill the "Sender email" field with "noreply@studiowaaz.com"
And I fill the "Printer format" field with "PDF"
And I add it
Then I should be notified that the shipping gateway has been created

@ui
Scenario: Creating DPD shipping relay gateway
When I visit the create shipping gateway configuration page for "dpd-relay"
And I select the "DPD" shipping method
And I fill the "DPD username" field with "username"
And I fill the "DPD password" field with "password"
Expand Down
2 changes: 1 addition & 1 deletion features/exporting_shipping_data_to_dpd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Managing shipping gateway
Given the store operates on a single channel in the "United States" named "Web-US"
And I am logged in as an administrator
And the store has "DPD" shipping method with "$10.00" fee
And there is a registered "dpd" shipping gateway for this shipping method named "dpd"
And there is a registered "dpd-predict" shipping gateway for this shipping method named "dpd"
And it has "username" field set to "username"
And it has "password" field set to "password"
And it has "customer_number" field set to "123"
Expand Down
5 changes: 4 additions & 1 deletion src/EventListener/ShippingExportEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function exportShipment(ResourceControllerEvent $event): void
$shippingGateway = $shippingExport->getShippingGateway();
Assert::notNull($shippingGateway);

if (self::DPD_GATEWAY_CODE !== $shippingGateway->getCode()) {
/** @var string $shippingGatewayCode */
$shippingGatewayCode = $shippingGateway->getCode();

if (str_starts_with($shippingGatewayCode, self::DPD_GATEWAY_CODE) === false) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;

final class ShippingGatewayType extends AbstractType
final class ShippingGatewayClassicType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
Expand Down Expand Up @@ -55,13 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'data' => 250,
])

->add('type', ChoiceType::class, [
'label' => 'waaz.ui.dpd_type',
'choices' => [
'DPD classic' => 'classic',
'DPD predict' => 'predict',
'DPD point relais' => 'relay',
],
->add('type', HiddenType::class, [
'data' => 'classic',
])

Expand Down
121 changes: 121 additions & 0 deletions src/Form/Type/ShippingGatewayPredictType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

declare(strict_types=1);

namespace Waaz\SyliusDpdPlugin\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;

final class ShippingGatewayPredictType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username', TextType::class, [
'label' => 'waaz.ui.dpd_username',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('password', TextType::class, [
'label' => 'waaz.ui.dpd_password',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('customer_number', TextType::class, [
'label' => 'waaz.ui.dpd_customer_number',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
new Regex([
'pattern' => '/^\\d+$/',
'message' => 'waaz.dpd_customer_number_invalid',
'groups' => ['bitbag'],
]),
],
])
->add('customer_centernumber', TextType::class, [
'label' => 'waaz.ui.dpd_customer_centernumber',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('customer_countrycode', TextType::class, [
'label' => 'waaz.ui.dpd_customer_countrycode',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
'data' => 250,
])

->add('type', HiddenType::class, [
'data' => 'predict',
])

->add('sender_name', TextType::class, [
'label' => 'waaz.ui.dpd_sender_name',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_street', TextType::class, [
'label' => 'waaz.ui.dpd_sender_street',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_city', TextType::class, [
'label' => 'waaz.ui.dpd_sender_city',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_postalcode', TextType::class, [
'label' => 'waaz.ui.dpd_sender_postalcode',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_country', TextType::class, [
'label' => 'waaz.ui.dpd_sender_country',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
new Length([
'max' => 2,
'maxMessage' => 'waaz.dpd_sender_country_invalid',
'groups' => ['bitbag'],
]),
],
])
->add('sender_phone', TextType::class, [
'label' => 'waaz.ui.dpd_sender_phone',
'required' => false,
])
->add('sender_email', TextType::class, [
'label' => 'waaz.ui.dpd_sender_email',
'required' => false,
])
->add('sender_commercial_address', CheckboxType::class, [
'label' => 'waaz.ui.dpd_sender_commercial_address',
'required' => false,
'data' => true,
])
->add('printer_format', ChoiceType::class, [
'label' => 'waaz.ui.dpd_printer_format.label',
'required' => false,
'choices' => [
'waaz.ui.dpd_printer_format.choices.pdf' => 'PDF',
],
'data' => 'PDF',
])
;
}
}
121 changes: 121 additions & 0 deletions src/Form/Type/ShippingGatewayRelayType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

declare(strict_types=1);

namespace Waaz\SyliusDpdPlugin\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;

final class ShippingGatewayRelayType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username', TextType::class, [
'label' => 'waaz.ui.dpd_username',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('password', TextType::class, [
'label' => 'waaz.ui.dpd_password',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('customer_number', TextType::class, [
'label' => 'waaz.ui.dpd_customer_number',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
new Regex([
'pattern' => '/^\\d+$/',
'message' => 'waaz.dpd_customer_number_invalid',
'groups' => ['bitbag'],
]),
],
])
->add('customer_centernumber', TextType::class, [
'label' => 'waaz.ui.dpd_customer_centernumber',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('customer_countrycode', TextType::class, [
'label' => 'waaz.ui.dpd_customer_countrycode',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
'data' => 250,
])

->add('type', HiddenType::class, [
'data' => 'relay',
])

->add('sender_name', TextType::class, [
'label' => 'waaz.ui.dpd_sender_name',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_street', TextType::class, [
'label' => 'waaz.ui.dpd_sender_street',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_city', TextType::class, [
'label' => 'waaz.ui.dpd_sender_city',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_postalcode', TextType::class, [
'label' => 'waaz.ui.dpd_sender_postalcode',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
],
])
->add('sender_country', TextType::class, [
'label' => 'waaz.ui.dpd_sender_country',
'constraints' => [
new NotBlank(['groups' => ['bitbag']]),
new Length([
'max' => 2,
'maxMessage' => 'waaz.dpd_sender_country_invalid',
'groups' => ['bitbag'],
]),
],
])
->add('sender_phone', TextType::class, [
'label' => 'waaz.ui.dpd_sender_phone',
'required' => false,
])
->add('sender_email', TextType::class, [
'label' => 'waaz.ui.dpd_sender_email',
'required' => false,
])
->add('sender_commercial_address', CheckboxType::class, [
'label' => 'waaz.ui.dpd_sender_commercial_address',
'required' => false,
'data' => true,
])
->add('printer_format', ChoiceType::class, [
'label' => 'waaz.ui.dpd_printer_format.label',
'required' => false,
'choices' => [
'waaz.ui.dpd_printer_format.choices.pdf' => 'PDF',
],
'data' => 'PDF',
])
;
}
}
16 changes: 13 additions & 3 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
services:
waaz.dpd_plugin.form.type.dpd_shipping_gateway:
class: Waaz\SyliusDpdPlugin\Form\Type\ShippingGatewayType
waaz.dpd_plugin.form.type.dpd_shipping_gateway_classic:
class: Waaz\SyliusDpdPlugin\Form\Type\ShippingGatewayClassicType
tags:
- { name: bitbag.shipping_gateway_configuration_type, type: 'dpd', label: "dpd" }
- { name: bitbag.shipping_gateway_configuration_type, type: 'dpd-classic', label: "DPD classic" }

waaz.dpd_plugin.form.type.dpd_shipping_gateway_predict:
class: Waaz\SyliusDpdPlugin\Form\Type\ShippingGatewayPredictType
tags:
- { name: bitbag.shipping_gateway_configuration_type, type: 'dpd-predict', label: "DPD predict" }

waaz.dpd_plugin.form.type.dpd_shipping_gateway_relay:
class: Waaz\SyliusDpdPlugin\Form\Type\ShippingGatewayRelayType
tags:
- { name: bitbag.shipping_gateway_configuration_type, type: 'dpd-relay', label: "DPD relay" }

waaz.dpd_plugin.api.shipping_label_fetcher:
class: Waaz\SyliusDpdPlugin\Api\ShippingLabelFetcher
Expand Down

0 comments on commit 778d276

Please sign in to comment.