custom/plugins/CioDefaultBillingAddress/src/Subscriber/CheckoutSubscriber.php line 19

Open in your IDE?
  1. <?php
  2. namespace CioDefaultBillingAddress\Subscriber;
  3. use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressEntity;
  4. use Shopware\Core\Framework\Uuid\Uuid;
  5. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CheckoutSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents()
  10.     {
  11.         return [
  12.             CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoaded'
  13.         ];
  14.     }
  15.     public function onCheckoutConfirmPageLoaded(CheckoutConfirmPageLoadedEvent $checkoutCartPageLoadedEvent)
  16.     {
  17.         $customer $checkoutCartPageLoadedEvent->getSalesChannelContext()->getCustomer();
  18.         $activeBillingAddress $customer->getActiveBillingAddress();
  19.         $billingAddress = new CustomerAddressEntity();
  20.         $billingAddress->setId(Uuid::randomHex());
  21.         $billingAddress->setCompany('EWE TEL GmbH');
  22.         $billingAddress->setFirstName(' ');
  23.         $billingAddress->setLastName(' ');
  24.         $billingAddress->setStreet('Cloppenburger Str. 310');
  25.         $billingAddress->setZipcode('26133');
  26.         $billingAddress->setCity('Oldenburg ');
  27.         if ($activeBillingAddress->getCountry()) { $billingAddress->setCountry($activeBillingAddress->getCountry()); }
  28.         $billingAddress->setCountryId($activeBillingAddress->getCountryId());
  29.         if ($activeBillingAddress->getCustomer()) { $billingAddress->setCustomer($activeBillingAddress->getCustomer()); }
  30.         $billingAddress->setCustomerId($activeBillingAddress->getCustomerId());
  31.         if ($activeBillingAddress->getSalutation()) { $billingAddress->setSalutation($activeBillingAddress->getSalutation()); }
  32.         if ($activeBillingAddress->getSalutationId()) { $billingAddress->setSalutationId($activeBillingAddress->getSalutationId()); }
  33.         if ($activeBillingAddress->getCountryState()) { $billingAddress->setCountryState($activeBillingAddress->getCountryState()); }
  34.         if ($activeBillingAddress->getCountryStateId()) { $billingAddress->setCountryStateId($activeBillingAddress->getCountryStateId()); }
  35.         $customer->setActiveBillingAddress($billingAddress);
  36.     }
  37. }