Example #1
0
 /**
  * Checks if an specific Address is contained in a Zone. For an Address, to
  * be contained in a Zone means that belongs to one (at least) of this Zone
  * locations.
  *
  * @param AddressInterface $address Address
  * @param ZoneInterface    $zone    Zone
  *
  * @return bool Address is contained in zone
  */
 public function isAddressContainedInZone(AddressInterface $address, ZoneInterface $zone)
 {
     $locations = $zone->getLocations();
     $cityId = $address->getCity();
     $found = false;
     try {
         $found = $this->locationProvider->in($cityId, $locations);
     } catch (Exception $e) {
         // Silent pass
     }
     return $found;
 }
Example #2
0
 /**
  * Formats an address on an array.
  *
  * @param AddressInterface $address The address to format
  *
  * @return array
  */
 public function toArray(AddressInterface $address)
 {
     $cityLocationId = $address->getCity();
     $cityHierarchy = $this->locationProvider->getHierarchy($cityLocationId);
     $cityHierarchyAsc = array_reverse($cityHierarchy);
     $addressArray = ['id' => $address->getId(), 'name' => $address->getName(), 'recipientName' => $address->getRecipientName(), 'recipientSurname' => $address->getRecipientSurname(), 'address' => $address->getAddress(), 'addressMore' => $address->getAddressMore(), 'postalCode' => $address->getPostalcode(), 'phone' => $address->getPhone(), 'mobile' => $address->getMobile(), 'comment' => $address->getComments()];
     foreach ($cityHierarchyAsc as $cityLocationNode) {
         /**
          * @var LocationData $cityLocationNode
          */
         $addressArray['city'][$cityLocationNode->getType()] = $cityLocationNode->getName();
     }
     $addressArray['fullAddress'] = $this->buildFullAddressString($address, $addressArray['city']);
     return $addressArray;
 }
Example #3
0
 /**
  * Gets the address hierarchy.
  *
  * @param AddressInterface $address
  *
  * @return LocationData[] Addres hierarchy
  */
 private function getAddressHierarchy(AddressInterface $address)
 {
     return $this->locationProvider->getHierarchy($address->getCity());
 }
Example #4
0
 /**
  * @param ZoneInterface    $zone
  * @param AddressInterface $address
  *
  * @return boolean Address is contained in zone
  */
 public function isAddressContainedInZone(ZoneInterface $zone, AddressInterface $address)
 {
     $city = $address->getCity();
     return $this->isCountryContainedInZone($zone, $city->getCountry()) || $this->isStateContainedInZone($zone, $city->getState()) || $this->isProvinceContainedInZone($zone, $city->getProvince()) || $this->isCityContainedInZone($zone, $address->getCity()) || $this->isPostalCodeContainedInZone($zone, $address->getPostalcode());
 }
Example #5
0
 /**
  * Get all zones where the address is included in
  *
  * @param ZoneInterface    $zone    Zone
  * @param AddressInterface $address Address
  *
  * @return boolean Address is contained in zone
  */
 public function getZonesFromAddress(ZoneInterface $zone, AddressInterface $address)
 {
     $city = $address->getCity();
     $zones = array_merge([], $this->getZonesFromCountry($zone, $city->getCountry())->toArray(), $this->getZonesFromState($zone, $city->getState())->toArray(), $this->getZonesFromProvince($zone, $city->getProvince())->toArray(), $this->getZonesFromCity($zone, $city)->toArray(), $this->getZonesFromPostalCode($zone, $address->getPostalcode())->toArray());
     return new ArrayCollection($zones);
 }