Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * Saves an address making a copy in case it was already persisted. Then
  * returns the saved address.
  *
  * @param AddressInterface $address The address to save
  *
  * @return AddressInterface saved address.
  */
 public function saveAddress(AddressInterface $address)
 {
     if ($address->getId()) {
         $addressToSave = clone $address;
         $addressToSave->setId(null);
         $this->addressObjectManager->refresh($address);
         $this->addressObjectManager->persist($addressToSave);
         $this->addressObjectManager->flush($addressToSave);
         $this->addressEventDispatcher->dispatchAddressOnCloneEvent($address, $addressToSave);
         return $addressToSave;
     }
     $this->addressObjectManager->flush($address);
     return $address;
 }
Esempio n. 3
0
 /**
  * Gets the address hierarchy.
  *
  * @param AddressInterface $address
  *
  * @return LocationData[] Addres hierarchy
  */
 private function getAddressHierarchy(AddressInterface $address)
 {
     return $this->locationProvider->getHierarchy($address->getCity());
 }
Esempio n. 4
0
 /**
  * Finds all the carts that had an address for billing or delivery
  *
  * @param AddressInterface $address The address to search
  *
  * @return CartInterface[]
  */
 public function findAllCartsWithAddress(AddressInterface $address)
 {
     $queryBuilder = $this->createQueryBuilder('c');
     $result = $queryBuilder->innerJoin('c.billingAddress', 'b')->innerJoin('c.deliveryAddress', 'd')->where($queryBuilder->expr()->orX($queryBuilder->expr()->eq('b.id', ':customerId'), $queryBuilder->expr()->eq('c.id', ':addressId')))->setParameter('customerId', $address->getId())->setParameter('addressId', $address->getId())->getQuery()->getResult();
     return $result;
 }
Esempio n. 5
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());
 }
Esempio n. 6
0
 /**
  * Builds a full address string.
  *
  * @param AddressInterface $address       The address
  * @param array            $cityHierarchy The full city hierarchy
  *
  * @return string
  */
 private function buildFullAddressString(AddressInterface $address, array $cityHierarchy)
 {
     $cityString = implode(', ', $cityHierarchy);
     return sprintf('%s %s, %s %s', $address->getAddress(), $address->getAddressMore(), $cityString, $address->getPostalcode());
 }
Esempio n. 7
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);
 }