mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
review updates
This commit is contained in:
parent
9fe9181b6e
commit
949d6f07cd
3 changed files with 41 additions and 25 deletions
|
|
@ -301,7 +301,7 @@ class AddressPage extends SymfonyPage implements AddressPageInterface
|
|||
'login_password' => '[data-test-password-input]',
|
||||
'login_validation_error' => '[data-test-login-validation-error]',
|
||||
'next_step' => '[data-test-next-step]',
|
||||
'shipping_address' => '#sylius-shipping-address',
|
||||
'shipping_address' => '[data-test-shipping-address]',
|
||||
'shipping_address_book' => '[data-test-shipping-address] [data-test-address-book]',
|
||||
'shipping_city' => '[data-test-shipping-city]',
|
||||
'shipping_country' => '[data-test-shipping-country]',
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ final class AddressType extends AbstractResourceType
|
|||
if (null === $addressComparator) {
|
||||
@trigger_error(
|
||||
sprintf(
|
||||
'Not passing an $addressComparator to %s constructor is deprecated since Sylius 1.7 and will be removed in Sylius 2.0.',
|
||||
'Not passing an $addressComparator to "%s" constructor is deprecated since Sylius 1.8 and will be impossible in Sylius 2.0.',
|
||||
__CLASS__,
|
||||
),
|
||||
\E_USER_DEPRECATED
|
||||
|
|
@ -56,35 +56,26 @@ final class AddressType extends AbstractResourceType
|
|||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
|
||||
->add('differentBillingAddress', CheckboxType::class, [
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'label' => 'sylius.form.checkout.addressing.different_billing_address',
|
||||
])
|
||||
->add('differentShippingAddress', CheckboxType::class, [
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'label' => 'sylius.form.checkout.addressing.different_shipping_address',
|
||||
])
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event): void {
|
||||
$form = $event->getForm();
|
||||
$order = $event->getData();
|
||||
/** @var OrderInterface $order */
|
||||
$order = $event->getData();
|
||||
|
||||
Assert::isInstanceOf($order, OrderInterface::class);
|
||||
|
||||
$channel = $order->getChannel();
|
||||
|
||||
$differentBillingOrShippingAddressChecked = null !== $this->addressComparator
|
||||
&& null !== $order->getBillingAddress() && null !== $order->getShippingAddress()
|
||||
&& !$this->addressComparator->equal($order->getBillingAddress(), $order->getShippingAddress());
|
||||
|
||||
$form
|
||||
->add('differentBillingAddress', CheckboxType::class, [
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'label' => 'sylius.form.checkout.addressing.different_billing_address',
|
||||
'attr' => [
|
||||
'checked' => $differentBillingOrShippingAddressChecked,
|
||||
],
|
||||
])
|
||||
->add('differentShippingAddress', CheckboxType::class, [
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'label' => 'sylius.form.checkout.addressing.different_shipping_address',
|
||||
'attr' => [
|
||||
'checked' => $differentBillingOrShippingAddressChecked,
|
||||
],
|
||||
])
|
||||
->add('shippingAddress', SyliusAddressType::class, [
|
||||
'shippable' => true,
|
||||
'constraints' => [new Valid()],
|
||||
|
|
@ -96,6 +87,18 @@ final class AddressType extends AbstractResourceType
|
|||
])
|
||||
;
|
||||
})
|
||||
->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event): void {
|
||||
$form = $event->getForm();
|
||||
/** @var OrderInterface $order */
|
||||
$order = $event->getData();
|
||||
|
||||
Assert::isInstanceOf($order, OrderInterface::class);
|
||||
|
||||
$areAddressesDifferent = $this->areAddressesDifferent($order);
|
||||
|
||||
$form->get('differentBillingAddress')->setData($areAddressesDifferent);
|
||||
$form->get('differentShippingAddress')->setData($areAddressesDifferent);
|
||||
})
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options): void {
|
||||
$form = $event->getForm();
|
||||
$resource = $event->getData();
|
||||
|
|
@ -147,4 +150,17 @@ final class AddressType extends AbstractResourceType
|
|||
{
|
||||
return 'sylius_checkout_address';
|
||||
}
|
||||
|
||||
private function areAddressesDifferent(OrderInterface $order): bool
|
||||
{
|
||||
if (null === $this->addressComparator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === $order->getBillingAddress() || null === $order->getShippingAddress()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$this->addressComparator->equal($order->getBillingAddress(), $order->getShippingAddress());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
<service id="sylius.form.type.checkout_address" class="Sylius\Bundle\CoreBundle\Form\Type\Checkout\AddressType">
|
||||
<argument>%sylius.model.order.class%</argument>
|
||||
<argument>%sylius.form.type.checkout_address.validation_groups%</argument>
|
||||
<argument type="service" id="sylius.address_comparator"/>
|
||||
<argument type="service" id="sylius.address_comparator" />
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
<service id="sylius.form.type.checkout_select_shipping" class="Sylius\Bundle\CoreBundle\Form\Type\Checkout\SelectShippingType">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue