/**
  * Override this method to implement your logic
  *
  * @param AddressInterface $address
  *
  * @return boolean
  */
 protected function isProvinceValid(AddressInterface $address)
 {
     if (null === $address->getCountry()) {
         return false;
     }
     if (!$address->getCountry()->hasProvinces()) {
         return true;
     }
     if (null === $address->getProvince()) {
         return false;
     }
     if ($address->getCountry()->hasProvince($address->getProvince())) {
         return true;
     }
     return false;
 }
Esempio n. 2
0
 public static function createAddress(AddressInterface $address)
 {
     $result = (new Address())->setStreetLines([$address->getStreet()])->setCity($address->getCity())->setPostalCode($address->getPostcode())->setCountryCode($address->getCountry()->getIsoName());
     if (null === ($province = $address->getProvince())) {
         return $result;
     }
     return $result->setStateOrProvinceCode($province->getIsoName());
 }
 function it_should_recognize_subject_as_eligible_if_country_match(OrderInterface $subject, AddressInterface $address, CountryInterface $country, RepositoryInterface $countryRepository)
 {
     $country->getCode()->willReturn('IE');
     $address->getCountry()->willReturn('IE');
     $subject->getShippingAddress()->willReturn($address);
     $country->getId()->willReturn(1);
     $countryRepository->findOneBy(array('code' => 'IE'))->willReturn($country);
     $this->isEligible($subject, array('country' => 1))->shouldReturn(true);
 }
 protected function getChinaSubdivisionRegionCodeByAddress(AddressInterface $address)
 {
     $isoName = $address->getProvince()->getIsoName();
     foreach ($this->chinaSubdivisions as $subdivision) {
         if ($subdivision['iso_name'] === $isoName) {
             return $subdivision['sf_region_code'];
         }
     }
     throw new CalculatorException(sprintf('Region %s, %s is not supported.', $address->getProvince()->getName(), $address->getCountry()->getName()));
 }
 function it_adds_violation_because_address_has_not_province(AddressInterface $address, Country $country, ProvinceAddressConstraint $constraint, ExecutionContextInterface $context)
 {
     $address->getCountry()->shouldBeCalled()->willreturn($country);
     $country->hasProvinces()->shouldBeCalled()->willreturn(true);
     $address->getProvince()->shouldBeCalled()->willreturn(null);
     $this->initialize($context);
     $context->getPropertyPath()->shouldBeCalled()->willReturn('property_path');
     $context->getViolations()->shouldBeCalled()->willReturn(new \ArrayIterator(array($this->createViolation('other_property_path'))));
     $context->addViolation(Argument::any())->shouldBeCalled();
     $this->validate($address, $constraint);
 }
 /**
  * @param AddressInterface $address
  *
  * @return bool
  */
 protected function isProvinceValid(AddressInterface $address)
 {
     $countryCode = $address->getCountry();
     if (null === ($country = $this->countryRepository->findOneBy(array('code' => $countryCode)))) {
         return true;
     }
     if (!$country->hasProvinces()) {
         return true;
     }
     if (null === $address->getProvince()) {
         return false;
     }
     if ($country->hasProvince($address->getProvince())) {
         return true;
     }
     return false;
 }
Esempio n. 7
0
 function it_should_match_all_zones_by_scope_when_one_zone_for_address_is_defined($repository, CountryInterface $country, AddressInterface $address, ZoneMemberCountry $memberCountry, ZoneInterface $zoneCountry)
 {
     $repository->findBy(array('scope' => 'shipping'))->shouldBeCalled()->willReturn(array($zoneCountry));
     $address->getCountry()->shouldBeCalled()->willReturn($country);
     $memberCountry->getCountry()->shouldBeCalled()->willReturn($country);
     $zoneCountry->getType()->shouldBeCalled()->willReturn(ZoneInterface::TYPE_COUNTRY);
     $zoneCountry->getMembers()->shouldBeCalled()->willReturn(array($memberCountry));
     $memberCountry->getBelongsTo()->willReturn($zoneCountry);
     $this->matchAll($address, 'shipping')->shouldReturn(array($zoneCountry));
 }
Esempio n. 8
0
 /**
  * Checks if address belongs to particular zone member.
  *
  * @param AddressInterface    $address
  * @param ZoneMemberInterface $member
  *
  * @return Boolean
  *
  * @throws \InvalidArgumentException
  */
 protected function addressBelongsToZoneMember(AddressInterface $address, ZoneMemberInterface $member)
 {
     $type = $member->getBelongsTo()->getType();
     switch ($type) {
         case ZoneInterface::TYPE_PROVINCE:
             return null !== $address->getProvince() && $address->getProvince() === $member->getProvince();
         case ZoneInterface::TYPE_COUNTRY:
             return null !== $address->getCountry() && $address->getCountry() === $member->getCountry();
         case ZoneInterface::TYPE_ZONE:
             return $this->addressBelongsToZone($address, $member->getZone());
         default:
             throw new \InvalidArgumentException(sprintf('Unexpected zone type "%s".', $type));
     }
 }