classes/XLite/Model/Address.php line 109

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2001-present X-Cart Holdings LLC. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Exception;
  10. use Includes\Utils\Converter;
  11. use XLite\API\Endpoint\ProfileAddress\DTO\ProfileAddressInput as Input;
  12. use XLite\API\Endpoint\ProfileAddress\DTO\ProfileAddressOutput as Output;
  13. /**
  14.  * @ORM\Entity
  15.  * @ORM\Table (
  16.  *     name="profile_addresses",
  17.  *     indexes={
  18.  *         @ORM\Index (name="is_billing", columns={"is_billing"}),
  19.  *         @ORM\Index (name="is_shipping", columns={"is_shipping"})
  20.  *     }
  21.  * )
  22.  * @ApiPlatform\ApiResource(
  23.  *     input=Input::class,
  24.  *     output=Output::class,
  25.  *     itemOperations={
  26.  *          "get"={
  27.  *              "method"="GET",
  28.  *              "path"="/profiles/{profile_id}/addresses/{address_id}.{_format}",
  29.  *              "identifiers"={"profile_id", "address_id"},
  30.  *              "requirements"={"profile_id"="\d+", "address_id"="\d+"},
  31.  *              "openapi_context"={
  32.  *                  "summary"="Retrieve an address from a profile",
  33.  *                  "parameters"={
  34.  *                      {"name"="profile_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  35.  *                      {"name"="address_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  36.  *                  }
  37.  *              }
  38.  *          },
  39.  *          "put"={
  40.  *              "method"="PUT",
  41.  *              "path"="/profiles/{profile_id}/addresses/{address_id}.{_format}",
  42.  *              "identifiers"={"profile_id", "address_id"},
  43.  *              "requirements"={"profile_id"="\d+", "address_id"="\d+"},
  44.  *              "openapi_context"={
  45.  *                  "summary"="Update an address of a profile",
  46.  *                  "parameters"={
  47.  *                      {"name"="profile_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  48.  *                      {"name"="address_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  49.  *                  }
  50.  *              }
  51.  *          },
  52.  *          "delete"={
  53.  *              "method"="DELETE",
  54.  *              "path"="/profiles/{profile_id}/addresses/{address_id}.{_format}",
  55.  *              "identifiers"={"profile_id", "address_id"},
  56.  *              "requirements"={"profile_id"="\d+", "address_id"="\d+"},
  57.  *              "openapi_context"={
  58.  *                  "summary"="Delete an address from a profile",
  59.  *                  "parameters"={
  60.  *                      {"name"="profile_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  61.  *                      {"name"="address_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  62.  *                  }
  63.  *              }
  64.  *          }
  65.  *     },
  66.  *     collectionOperations={
  67.  *          "get"={
  68.  *              "method"="GET",
  69.  *              "path"="/profiles/{profile_id}/addresses.{_format}",
  70.  *              "identifiers"={"profile_id", "address_id"},
  71.  *              "requirements"={"profile_id"="\d+"},
  72.  *              "openapi_context"={
  73.  *                  "summary"="Retrieve a list of addresses from a profile",
  74.  *                  "parameters"={
  75.  *                      {"name"="profile_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  76.  *                  },
  77.  *              }
  78.  *          },
  79.  *          "post"={
  80.  *              "method"="POST",
  81.  *              "path"="/profiles/{profile_id}/addresses.{_format}",
  82.  *              "controller"="xcart.api.profile_address.controller",
  83.  *              "identifiers"={"profile_id", "address_id"},
  84.  *              "requirements"={"profile_id"="\d+"},
  85.  *              "openapi_context"={
  86.  *                  "summary"="Add an address to a profile",
  87.  *                  "parameters"={
  88.  *                      {"name"="profile_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  89.  *                  }
  90.  *              }
  91.  *          }
  92.  *     }
  93.  * )
  94.  *
  95.  * @method string getFirstname
  96.  * @method string setFirstname
  97.  * @method string getLastname
  98.  * @method string setLastname
  99.  * @method string getAddress1
  100.  * @method string getAddress2
  101.  * @method string getAddress3
  102.  * @method string setAddress1
  103.  * @method string setAddress2
  104.  * @method string setAddress3
  105.  * @method string getZipcode
  106.  * @method string setZipcode
  107.  * @method string getCity
  108.  * @method string setCity
  109.  * @method string getPhone
  110.  * @method string setPhone
  111.  */
  112. class Address extends \XLite\Model\Base\PersonalAddress
  113. {
  114.     /**
  115.      * Address type codes
  116.      */
  117.     public const BILLING  'b';
  118.     public const SHIPPING 's';
  119.     /**
  120.      * Address fields collection
  121.      *
  122.      * @var \Doctrine\Common\Collections\ArrayCollection
  123.      *
  124.      * @ORM\OneToMany (targetEntity="XLite\Model\AddressFieldValue", mappedBy="address", cascade={"all"})
  125.      */
  126.     protected $addressFields;
  127.     /**
  128.      * Flag: is it a billing address
  129.      *
  130.      * @var bool
  131.      *
  132.      * @ORM\Column (type="boolean")
  133.      */
  134.     protected $is_billing false;
  135.     /**
  136.      * Flag: is it a shipping address
  137.      *
  138.      * @var bool
  139.      *
  140.      * @ORM\Column (type="boolean")
  141.      */
  142.     protected $is_shipping false;
  143.     /**
  144.      * Flag: is it a work address
  145.      *
  146.      * @var bool
  147.      *
  148.      * @ORM\Column (type="boolean")
  149.      */
  150.     protected $isWork false;
  151.     /**
  152.      * @var Profile
  153.      *
  154.      * @ORM\ManyToOne (targetEntity="XLite\Model\Profile", inversedBy="addresses", cascade={"persist","merge","detach"})
  155.      * @ORM\JoinColumn (name="profile_id", referencedColumnName="profile_id", onDelete="CASCADE")
  156.      */
  157.     protected $profile;
  158.     /**
  159.      * Constructor
  160.      *
  161.      * @param array $data Entity properties OPTIONAL
  162.      */
  163.     public function __construct(array $data = [])
  164.     {
  165.         $this->addressFields = new \Doctrine\Common\Collections\ArrayCollection();
  166.         parent::__construct($data);
  167.     }
  168.     /**
  169.      * Universal setter
  170.      *
  171.      * @param string $property
  172.      * @param mixed  $value
  173.      *
  174.      * @return true|null Returns TRUE if the setting succeeds. NULL if the setting fails
  175.      */
  176.     public function setterProperty($property$value)
  177.     {
  178.         $result parent::setterProperty($property$value);
  179.         if ($result === null) {
  180.             $addressField \XLite\Core\Database::getRepo('XLite\Model\AddressField')
  181.                 ->findOneBy(['serviceName' => $property]);
  182.             if ($addressField) {
  183.                 $repo \XLite\Core\Database::getRepo('XLite\Model\AddressFieldValue');
  184.                 $addressFieldValue $this->getFieldValue($property);
  185.                 if ($addressFieldValue) {
  186.                     $addressFieldValue->setValue($value);
  187.                     if ($this->isPersistent()) {
  188.                         $repo->update($addressFieldValue);
  189.                     }
  190.                 } else {
  191.                     $addressFieldValue = new AddressFieldValue();
  192.                     $addressFieldValue->map([
  193.                         'address'      => $this,
  194.                         'addressField' => $addressField,
  195.                         'value'        => $value,
  196.                     ]);
  197.                     $this->addAddressFields($addressFieldValue);
  198.                     if ($this->isPersistent()) {
  199.                         $repo->insert($addressFieldValue);
  200.                     }
  201.                 }
  202.                 $result true;
  203.             } else {
  204.                 // Log wrong access to property
  205.                 $this->logWrongAddressPropertyAccess($propertyfalse);
  206.             }
  207.         }
  208.         return $result;
  209.     }
  210.     /**
  211.      * Update searchFakeField of profile
  212.      *
  213.      * @return boolean
  214.      * @throws Exception
  215.      */
  216.     public function update()
  217.     {
  218.         $result parent::update();
  219.         if ($this->getProfile()) {
  220.             \XLite\Core\Database::getEM()->refresh($this->getProfile());
  221.             $this->getProfile()->updateSearchFakeField();
  222.             \XLite\Core\Database::getEM()->flush();
  223.         }
  224.         return $result;
  225.     }
  226.     /**
  227.      * Update searchFakeField of profile
  228.      *
  229.      * @return boolean
  230.      */
  231.     public function delete()
  232.     {
  233.         // We are using id because we can't use em->refresh or em->merge
  234.         $profileId $this->getProfile()?->getProfileId();
  235.         $result parent::delete();
  236.         if ($profileId) {
  237.             $profile \XLite\Core\Database::getRepo('XLite\Model\Profile')->find($profileId);
  238.             $profile->updateSearchFakeField();
  239.         }
  240.         return $result;
  241.     }
  242.     /**
  243.      * Update searchFakeField of profile
  244.      *
  245.      * @return boolean
  246.      */
  247.     public function create()
  248.     {
  249.         $result parent::create();
  250.         if ($this->getProfile()) {
  251.             \XLite\Core\Database::getEM()->refresh($this->getProfile());
  252.             $this->getProfile()->updateSearchFakeField();
  253.         }
  254.         return $result;
  255.     }
  256.     /**
  257.      * Get address field method
  258.      * for magic call
  259.      *
  260.      * @param string $fieldName Field name
  261.      * @param bool   $toUpper
  262.      *
  263.      * @return string
  264.      */
  265.     public static function getAddressFieldMethod(string $fieldNamebool $toUpper true): string
  266.     {
  267.         // $methodName assembled from 'get' + $fieldName in 'camel case' style, but
  268.         // for custom address field service names like ('*_', '*-', '*_digit', '*-digit' etc.)
  269.         // 'camel case' cannot be implemented, due it will be used for magic call ->$method
  270.         return preg_match('/[-_]\d+$|[-_]$/'$fieldName)
  271.             ? $fieldName
  272.             : ($toUpper
  273.                 Converter::convertToUpperCamelCase($fieldName)
  274.                 : Converter::convertFromCamelCase($fieldName));
  275.     }
  276.     /**
  277.      * Get address field value
  278.      *
  279.      * @param string $fieldName Field name
  280.      *
  281.      * @return string|null
  282.      */
  283.     public function getFieldValueAsString(string $fieldName): ?string
  284.     {
  285.         if (empty($fieldName)) {
  286.             return null;
  287.         }
  288.         $methodName 'get' . static::getAddressFieldMethod($fieldName);
  289.         return $this->$methodName();
  290.     }
  291.     /**
  292.      * Universal getter
  293.      *
  294.      * @param string $property
  295.      *
  296.      * @return mixed|null Returns NULL if it is impossible to get the property
  297.      */
  298.     public function getterProperty($property)
  299.     {
  300.         $result parent::getterProperty($property);
  301.         if ($result === null) {
  302.             $addressField = static::getAddressFieldByServiceName($property);
  303.             if ($addressField) {
  304.                 $addressFieldValue $this->getFieldValue($property);
  305.                 $result $addressFieldValue
  306.                     $addressFieldValue->getValue()
  307.                     : static::getDefaultFieldPlainValue($property);
  308.             } else {
  309.                 // Log wrong access to property
  310.                 $this->logWrongAddressPropertyAccess($property);
  311.             }
  312.         }
  313.         return $result;
  314.     }
  315.     /**
  316.      * Disable default logging of access to wrong property
  317.      *
  318.      * @param string  $property Property name
  319.      * @param boolean $isGetter Flag: is called property getter (true) or setter (false) OPTIONAL
  320.      *
  321.      * @return void
  322.      */
  323.     protected function logWrongPropertyAccess($property$isGetter true)
  324.     {
  325.     }
  326.     /**
  327.      * Log access to unknown address property
  328.      *
  329.      * @param string  $property Property name
  330.      * @param boolean $isGetter Flag: is called property getter (true) or setter (false) OPTIONAL
  331.      *
  332.      * @return void
  333.      */
  334.     protected function logWrongAddressPropertyAccess($property$isGetter true)
  335.     {
  336.         parent::logWrongPropertyAccess($property$isGetter);
  337.     }
  338.     /**
  339.      * Return true if specified property exists
  340.      *
  341.      * @param string $name Property name
  342.      *
  343.      * @return boolean
  344.      */
  345.     public function isPropertyExists($name)
  346.     {
  347.         return parent::isPropertyExists($name)
  348.             || (bool)static::getAddressFieldByServiceName($name);
  349.     }
  350.     /**
  351.      * Get field value
  352.      *
  353.      * @param string $name Field name
  354.      *
  355.      * @return AddressFieldValue
  356.      */
  357.     public function getFieldValue($name)
  358.     {
  359.         $addressFieldValue null;
  360.         $addressField = static::getAddressFieldByServiceName($name);
  361.         if ($addressField) {
  362.             foreach ($this->getAddressFields() as $field) {
  363.                 if (
  364.                     $field->getAddressField()
  365.                     && (int)$field->getAddressField()->getId() === (int)$addressField->getId()
  366.                 ) {
  367.                     $addressFieldValue $field;
  368.                     break;
  369.                 }
  370.             }
  371.         }
  372.         return $addressFieldValue;
  373.     }
  374.     public static function createDefaultShippingAddress()
  375.     {
  376.         $address = new Address();
  377.         $requiredFields = ['country''state''custom_state''zipcode''city'];
  378.         $data = [];
  379.         foreach ($requiredFields as $fieldName) {
  380.             if (!isset($data[$fieldName]) && Address::getDefaultFieldValue($fieldName)) {
  381.                 $data[$fieldName] = Address::getDefaultFieldValue($fieldName);
  382.             }
  383.         }
  384.         $address->map($data);
  385.         return $address;
  386.     }
  387.     public function checkAddress()
  388.     {
  389.         /** @var AddressFieldValue $addressFieldValue */
  390.         foreach ($this->getAddressFields() as $addressFieldValue) {
  391.             $serviceName $addressFieldValue->getAddressField()
  392.                 ? $addressFieldValue->getAddressField()->getServiceName()
  393.                 : '';
  394.             $val $addressFieldValue->getValue();
  395.             if (!$this->checkAddressField($serviceName$val)) {
  396.                 return false;
  397.             }
  398.         }
  399.         return true;
  400.     }
  401.     public function restoreInvalid()
  402.     {
  403.         /** @var AddressFieldValue $addressFieldValue */
  404.         foreach ($this->getAddressFields() as $addressFieldValue) {
  405.             $serviceName $addressFieldValue->getAddressField()
  406.                 ? $addressFieldValue->getAddressField()->getServiceName()
  407.                 : '';
  408.             $val $addressFieldValue->getValue();
  409.             if (!$this->checkAddressField($serviceName$val)) {
  410.                 $addressFieldValue->setValue(static::getDefaultFieldValue($serviceName));
  411.             }
  412.         }
  413.     }
  414.     /**
  415.      * Get default value for the field
  416.      *
  417.      * @param string $fieldName Field service name
  418.      *
  419.      * @return mixed
  420.      */
  421.     public static function getDefaultFieldValue($fieldName)
  422.     {
  423.         $result null;
  424.         switch ($fieldName) {
  425.             case 'country':
  426.                 $code \XLite\Core\Config::getInstance()->Shipping->anonymous_country;
  427.                 $result \XLite\Core\Database::getRepo('XLite\Model\Country')->findOneByCode($code);
  428.                 if ($result && !$result->getEnabled()) {
  429.                     $newResult \XLite\Core\Database::getRepo('XLite\Model\Country')->findOneBy(['enabled' => true]);
  430.                     $result $newResult ?: $result;
  431.                 }
  432.                 break;
  433.             case 'country_code':
  434.                 $code \XLite\Core\Config::getInstance()->Shipping->anonymous_country;
  435.                 $result \XLite\Core\Database::getRepo('XLite\Model\Country')->findOneByCode($code);
  436.                 if ($result && !$result->getEnabled()) {
  437.                     $newResult \XLite\Core\Database::getRepo('XLite\Model\Country')->findOneBy(['enabled' => true]);
  438.                     $result $newResult ?: $result;
  439.                 }
  440.                 $result $result->getCode();
  441.                 break;
  442.             case 'state':
  443.                 $id \XLite\Core\Config::getInstance()->Shipping->anonymous_state;
  444.                 $result \XLite\Core\Database::getRepo('XLite\Model\State')->find($id);
  445.                 break;
  446.             case 'custom_state':
  447.                 $result \XLite\Core\Config::getInstance()->Shipping->anonymous_custom_state;
  448.                 break;
  449.             case 'zipcode':
  450.                 $result \XLite\Core\Config::getInstance()->Shipping->anonymous_zipcode;
  451.                 break;
  452.             case 'city':
  453.                 $result \XLite\Core\Config::getInstance()->Shipping->anonymous_city;
  454.                 break;
  455.             default:
  456.         }
  457.         return $result;
  458.     }
  459.     /**
  460.      * Get required fields by address type
  461.      *
  462.      * @param string $atype Address type code
  463.      *
  464.      * @return array
  465.      */
  466.     public function getRequiredFieldsByType($atype)
  467.     {
  468.         switch ($atype) {
  469.             case static::BILLING:
  470.                 $list \XLite\Core\Database::getRepo('XLite\Model\AddressField')->getBillingRequiredFields();
  471.                 break;
  472.             case static::SHIPPING:
  473.                 $list \XLite\Core\Database::getRepo('XLite\Model\AddressField')->getShippingRequiredFields();
  474.                 break;
  475.             default:
  476.                 $list null;
  477.             // TODO - add throw exception
  478.         }
  479.         return $list;
  480.     }
  481.     /**
  482.      * Returns array of address fields serviceName/value pairs
  483.      *
  484.      * @return array
  485.      */
  486.     public function serialize()
  487.     {
  488.         $fields $this->getAddressFields();
  489.         $result = [];
  490.         if ($fields) {
  491.             $result array_reduce($fields->toArray(), static function ($acc$item) {
  492.                 if ($item->getAddressField()) {
  493.                     $acc[$item->getAddressField()->getServiceName()] = $item->getValue();
  494.                     return $acc;
  495.                 }
  496.             }, []);
  497.         }
  498.         return $result;
  499.     }
  500.     /**
  501.      * Clone
  502.      *
  503.      * @return AEntity
  504.      */
  505.     public function cloneEntity()
  506.     {
  507.         $entity parent::cloneEntity();
  508.         foreach (\XLite\Core\Database::getRepo('XLite\Model\AddressField')->findAllEnabled() as $field) {
  509.             if (
  510.                 $field->getServiceName() === 'state_id'
  511.                 && $this->getCountry()
  512.                 && $this->getCountry()->isForcedCustomState()
  513.             ) {
  514.                 continue;
  515.             }
  516.             $entity->setterProperty($field->getServiceName(), $this->getterProperty($field->getServiceName()));
  517.         }
  518.         if ($this->getProfile()) {
  519.             $entity->setProfile($this->getProfile());
  520.         }
  521.         return $entity;
  522.     }
  523.     /**
  524.      * Get country
  525.      *
  526.      * @return \XLite\Model\Country
  527.      */
  528.     public function getCountry()
  529.     {
  530.         $result $this->country;
  531.         if (!$result) {
  532.             $result Address::getDefaultFieldValue('country');
  533.         }
  534.         return $result;
  535.     }
  536.     /**
  537.      * Serialize address to array
  538.      *
  539.      * @return array
  540.      */
  541.     public function toArray()
  542.     {
  543.         return [
  544.             'name'         => trim($this->getFirstname() . ' ' $this->getLastname()),
  545.             'address1'     => $this->getAddress1(),
  546.             'address2'     => $this->getAddress2(),
  547.             'address3'     => $this->getAddress3(),
  548.             'city'         => $this->getCity(),
  549.             'state'        => $this->getState() ? $this->getState()->getCode() : '',
  550.             'custom_state' => $this->getCustomState(),
  551.             'zipcode'      => $this->getZipcode(),
  552.             'country'      => $this->getCountry() ? $this->getCountry()->getCode() : '',
  553.             'type'         => $this->getType() ?: \XLite\Core\Config::getInstance()->Shipping->anonymous_address_type,
  554.         ];
  555.     }
  556.     /**
  557.      * Set is_billing
  558.      *
  559.      * @param boolean $isBilling
  560.      *
  561.      * @return Address
  562.      */
  563.     public function setIsBilling($isBilling)
  564.     {
  565.         $this->is_billing $isBilling;
  566.         return $this;
  567.     }
  568.     /**
  569.      * Get is_billing
  570.      *
  571.      * @return boolean
  572.      */
  573.     public function getIsBilling()
  574.     {
  575.         return $this->is_billing;
  576.     }
  577.     /**
  578.      * Set is_shipping
  579.      *
  580.      * @param boolean $isShipping
  581.      *
  582.      * @return Address
  583.      */
  584.     public function setIsShipping($isShipping)
  585.     {
  586.         $this->is_shipping $isShipping;
  587.         return $this;
  588.     }
  589.     /**
  590.      * Get is_shipping
  591.      *
  592.      * @return boolean
  593.      */
  594.     public function getIsShipping()
  595.     {
  596.         return $this->is_shipping;
  597.     }
  598.     /**
  599.      * Set isWork
  600.      *
  601.      * @param boolean $isWork
  602.      *
  603.      * @return Address
  604.      */
  605.     public function setIsWork($isWork)
  606.     {
  607.         $this->isWork $isWork;
  608.         return $this;
  609.     }
  610.     /**
  611.      * Get isWork
  612.      *
  613.      * @return boolean
  614.      */
  615.     public function getIsWork()
  616.     {
  617.         return $this->isWork;
  618.     }
  619.     /**
  620.      * Get address_id
  621.      *
  622.      * @return integer
  623.      */
  624.     public function getAddressId()
  625.     {
  626.         return $this->address_id;
  627.     }
  628.     /**
  629.      * Set address_type
  630.      *
  631.      * @param string $addressType
  632.      *
  633.      * @return Address
  634.      */
  635.     public function setAddressType($addressType)
  636.     {
  637.         $this->address_type $addressType;
  638.         return $this;
  639.     }
  640.     /**
  641.      * Get address_type
  642.      *
  643.      * @return string
  644.      */
  645.     public function getAddressType()
  646.     {
  647.         return $this->address_type;
  648.     }
  649.     /**
  650.      * Add addressFields
  651.      *
  652.      * @param AddressFieldValue $addressFields
  653.      *
  654.      * @return Address
  655.      */
  656.     public function addAddressFields(AddressFieldValue $addressFields)
  657.     {
  658.         $this->addressFields[] = $addressFields;
  659.         return $this;
  660.     }
  661.     /**
  662.      * Get addressFields
  663.      *
  664.      * @return \Doctrine\Common\Collections\Collection
  665.      */
  666.     public function getAddressFields()
  667.     {
  668.         return $this->addressFields;
  669.     }
  670.     /**
  671.      * Set profile
  672.      *
  673.      * @param Profile $profile
  674.      *
  675.      * @return Address
  676.      */
  677.     public function setProfile(Profile $profile null)
  678.     {
  679.         $this->profile $profile;
  680.         return $this;
  681.     }
  682.     /**
  683.      * Get profile
  684.      *
  685.      * @return Profile
  686.      */
  687.     public function getProfile()
  688.     {
  689.         return $this->profile;
  690.     }
  691.     public function getAddressLinesList(): array
  692.     {
  693.         $result = [];
  694.         for ($i 1$i <= 3$i++) {
  695.             $method "getAddress{$i}";
  696.             $result[] = $this->$method();
  697.         }
  698.         return $result;
  699.     }
  700.     public function getAddressLineConcat(): string
  701.     {
  702.         return trim(
  703.             implode(' 'array_filter($this->getAddressLinesList()))
  704.         );
  705.     }
  706.     public function getAddressLineConcat23(): string
  707.     {
  708.         return $this->getAddress2() . ' ' $this->getAddress3();
  709.     }
  710.     /**
  711.      * @deprecated since CDev-Core 5.5.1, use \XLite\Model\Address::getAddress1() instead
  712.      */
  713.     public function getStreet(): string
  714.     {
  715.         trigger_deprecation('CDev-Core''5.5.1''"%s" is deprecated, use \XLite\Model\Address::getAddress1() instead.'__METHOD__);
  716.         return $this->getAddress1();
  717.     }
  718.     public static function prepareAddressLines(string $address1 ''string $address2 ''string $address3 ''): array
  719.     {
  720.         $result = [
  721.             'address1' => $address1,
  722.             'address2' => $address2,
  723.             'address3' => $address3,
  724.         ];
  725.         if (static::line3Disabled()) {
  726.             $result['address2'] .= ' ' $result['address3'];
  727.             $result['address3'] = '';
  728.         }
  729.         if (static::line2Disabled()) {
  730.             $result['address1'] .= ' ' $result['address2'];
  731.             $result['address2'] = '';
  732.         }
  733.         return $result;
  734.     }
  735.     public static function line2Disabled(): bool
  736.     {
  737.         return !static::getAddressFieldByServiceName('address2')->getEnabled();
  738.     }
  739.     public static function line3Disabled(): bool
  740.     {
  741.         return !static::getAddressFieldByServiceName('address3')->getEnabled();
  742.     }
  743.     public function getAddressLineConcatCommaDivided(): string
  744.     {
  745.         $fields = [];
  746.         foreach (['address1''address2''address3'] as $line) {
  747.             $method 'get' ucfirst($line);
  748.             if (
  749.                 ($fieldValue $this->getFieldValue($line))
  750.                 && $fieldValue->getAddressField()->getEnabled()
  751.                 && !empty($this->$method())
  752.             ) {
  753.                 $fields[] = $this->$method();
  754.             }
  755.         }
  756.         return implode(', '$fields);
  757.     }
  758. }