vendor/shopware/core/Checkout/Cart/Delivery/Struct/ShippingLocation.php line 12

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