vendor/shopware/platform/src/Core/Checkout/Cart/Delivery/Struct/ShippingLocation.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart\Delivery\Struct;
  3. use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressEntity;
  4. use Shopware\Core\Framework\Struct\Struct;
  5. use Shopware\Core\System\Country\Aggregate\CountryState\CountryStateEntity;
  6. use Shopware\Core\System\Country\CountryEntity;
  7. class ShippingLocation extends Struct
  8. {
  9.     /**
  10.      * @var CountryEntity
  11.      */
  12.     protected $country;
  13.     /**
  14.      * @var CountryStateEntity|null
  15.      */
  16.     protected $state;
  17.     /**
  18.      * @var CustomerAddressEntity|null
  19.      */
  20.     protected $address;
  21.     public function __construct(CountryEntity $country, ?CountryStateEntity $state, ?CustomerAddressEntity $address)
  22.     {
  23.         $this->country $country;
  24.         $this->state $state;
  25.         $this->address $address;
  26.     }
  27.     public static function createFromAddress(CustomerAddressEntity $address): self
  28.     {
  29.         return new self(
  30.             $address->getCountry(),
  31.             $address->getCountryState(),
  32.             $address
  33.         );
  34.     }
  35.     public static function createFromCountry(CountryEntity $country): self
  36.     {
  37.         return new self($countrynullnull);
  38.     }
  39.     public function getCountry(): CountryEntity
  40.     {
  41.         if ($this->address) {
  42.             return $this->address->getCountry();
  43.         }
  44.         return $this->country;
  45.     }
  46.     public function getState(): ?CountryStateEntity
  47.     {
  48.         if ($this->address) {
  49.             return $this->address->getCountryState();
  50.         }
  51.         return $this->state;
  52.     }
  53.     public function getAddress(): ?CustomerAddressEntity
  54.     {
  55.         return $this->address;
  56.     }
  57.     public function getApiAlias(): string
  58.     {
  59.         return 'cart_delivery_shipping_location';
  60.     }
  61. }