function it_should_recognize_subject_as_eligible_if_country_match(OrderInterface $subject, AddressInterface $address, CountryInterface $country, RepositoryInterface $countryRepository)
 {
     $country->getCode()->willReturn('IE');
     $address->getCountryCode()->willReturn('IE');
     $subject->getShippingAddress()->willReturn($address);
     $countryRepository->findOneBy(['code' => 'IE'])->willReturn($country);
     $this->isEligible($subject, ['country' => 'IE'])->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()));
 }
示例#3
0
 private function setAddress(AddressInterface $address, AddressInterface $lastOrderAddress)
 {
     if ($address->getFirstName() === null) {
         $address->setFirstName($lastOrderAddress->getFirstName());
     }
     if ($address->getLastName() === null) {
         $address->setLastName($lastOrderAddress->getLastName());
     }
     if ($address->getPhoneNumber() === null) {
         $address->setPhoneNumber($lastOrderAddress->getPhoneNumber());
     }
     if ($address->getCountryCode() === null) {
         $address->setCountryCode($lastOrderAddress->getCountryCode());
     }
     if ($address->getProvinceCode() === null) {
         $address->setProvinceCode($lastOrderAddress->getProvinceCode());
     }
     if ($address->getStreet() === null) {
         $address->setStreet($lastOrderAddress->getStreet());
     }
     if ($address->getCity() === null) {
         $address->setCity($lastOrderAddress->getCity());
     }
     if ($address->getPostcode() === null) {
         $address->setPostcode($lastOrderAddress->getPostcode());
     }
 }
 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);
 }
 /**
  * Override this method to implement your logic
  *
  * @param AddressInterface $address
  *
  * @return bool
  */
 protected function isProvinceValid(AddressInterface $address)
 {
     if (null === ($country = $address->getCountry())) {
         return true;
     }
     if (!$country->hasProvinces()) {
         return true;
     }
     if (null === $address->getProvince()) {
         return false;
     }
     if ($country->hasProvince($address->getProvince())) {
         return true;
     }
     return false;
 }
 function it_does_not_add_a_violation_if_province_is_valid(AddressInterface $address, Country $country, Province $province, ProvinceAddressConstraint $constraint, ExecutionContextInterface $context, RepositoryInterface $countryRepository, RepositoryInterface $provinceRepository)
 {
     $country->getCode()->willReturn('US');
     $address->getCountryCode()->willReturn('US');
     $countryRepository->findOneBy(['code' => 'US'])->willReturn($country);
     $country->hasProvinces()->willReturn(true);
     $address->getProvinceCode()->willReturn('US-AK');
     $province->getCode()->willReturn('US-AK');
     $provinceRepository->findOneBy(['code' => 'US-AK'])->willReturn($province);
     $country->hasProvince($province)->willReturn(true);
     $this->initialize($context);
     $context->getPropertyPath()->willReturn('property_path');
     $context->getViolations()->willReturn(new \ArrayIterator([$this->createViolation('other_property_path')]));
     $context->addViolation(Argument::any())->shouldNotBeCalled();
     $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;
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 private function specifyAddress(AddressInterface $address, $addressType)
 {
     $this->specifyElementValue($addressType . '_first_name', $address->getFirstName());
     $this->specifyElementValue($addressType . '_last_name', $address->getLastName());
     $this->specifyElementValue($addressType . '_street', $address->getStreet());
     $this->specifyElementValue($addressType . '_city', $address->getCity());
     $this->specifyElementValue($addressType . '_postcode', $address->getPostcode());
     $this->chooseCountry($address->getCountryCode(), $addressType);
 }
示例#9
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());
 }
示例#10
0
 public function setAddress(AddressInterface $address)
 {
     $this->setCellMargins("", "", "", "");
     $this->SetFont(self::FONT);
     $this->SetFont(self::FONT_BOLD);
     if ($address->getCompany()) {
         $this->MultiCell(self::ADDRESS_WIDTH, 0, $address->getCompany(), 0, "L", false, 1, self::MARGIN_LEFT, self::MARGIN_TOP);
         $this->MultiCell(self::ADDRESS_WIDTH, 0, $address->getFirstName(), 0, "L", false, 1, self::MARGIN_LEFT);
     } else {
         $this->MultiCell(self::ADDRESS_WIDTH, 0, $address->getFirstName(), 0, "L", false, 1, self::MARGIN_LEFT, self::MARGIN_TOP);
     }
     $this->MultiCell(self::ADDRESS_WIDTH, 0, $address->getStreet(), 0, "L", false, 1, self::MARGIN_LEFT);
     $this->MultiCell(self::ADDRESS_WIDTH, 0, $address->getPostcode(), 0, "L", false, 1, self::MARGIN_LEFT);
     $country = $address->getCountryCode();
     $this->MultiCell(self::ADDRESS_WIDTH, 0, $country, 0, "L", false, 1, self::MARGIN_LEFT);
     if (!$address->getCompany()) {
         $this->MultiCell(self::ADDRESS_WIDTH, 0, "", 0, "L", false, 1, self::MARGIN_LEFT);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getAbbreviation(AddressInterface $address)
 {
     if (null !== $address->getProvinceName()) {
         return $address->getProvinceName();
     }
     if (null === $address->getProvinceCode()) {
         return '';
     }
     $province = $this->provinceRepository->findOneBy(['code' => $address->getProvinceCode()]);
     Assert::notNull($province, sprintf('Province with code "%s" not found.', $address->getProvinceCode()));
     return $province->getAbbreviation() ?: $province->getName();
 }
示例#12
0
 function it_ignores_leading_and_trailing_spaces_or_letter_cases(AddressInterface $firstAddress, AddressInterface $secondAddress)
 {
     $firstAddress->getCity()->willReturn('TOOWOOMBA');
     $firstAddress->getStreet()->willReturn('Ryans Dr     ');
     $firstAddress->getCompany()->willReturn('   Burger');
     $firstAddress->getPostcode()->willReturn(' 4350 ');
     $firstAddress->getLastName()->willReturn('jones ');
     $firstAddress->getFirstName()->willReturn('mIa');
     $firstAddress->getPhoneNumber()->willReturn(' 999');
     $firstAddress->getCountryCode()->willReturn('au');
     $firstAddress->getProvinceCode()->willReturn(null);
     $firstAddress->getProvinceName()->willReturn('qUEENSLAND');
     $secondAddress->getCity()->willReturn('Toowoomba');
     $secondAddress->getStreet()->willReturn('Ryans Dr');
     $secondAddress->getCompany()->willReturn('Burger');
     $secondAddress->getPostcode()->willReturn('4350');
     $secondAddress->getLastName()->willReturn('Jones');
     $secondAddress->getFirstName()->willReturn('Mia');
     $secondAddress->getPhoneNumber()->willReturn('999');
     $secondAddress->getCountryCode()->willReturn('AU');
     $secondAddress->getProvinceCode()->willReturn(null);
     $secondAddress->getProvinceName()->willReturn('Queensland');
     $this->equal($firstAddress, $secondAddress)->shouldReturn(true);
 }
示例#13
0
 /**
  * @param AddressInterface $address
  *
  * @return array
  */
 private function normalizeAddress(AddressInterface $address)
 {
     return array_map(function ($value) {
         return trim(strtolower($value));
     }, [$address->getCity(), $address->getCompany(), $address->getCountryCode(), $address->getFirstName(), $address->getLastName(), $address->getPhoneNumber(), $address->getPostcode(), $address->getProvinceCode(), $address->getProvinceName(), $address->getStreet()]);
 }
示例#14
0
 function it_matches_all_zones_by_scope_when_one_zone_for_address_is_defined(RepositoryInterface $repository, AddressInterface $address, ZoneMemberInterface $memberCountry, ZoneInterface $zoneCountry)
 {
     $repository->findBy(['scope' => 'shipping'])->willReturn([$zoneCountry]);
     $address->getCountryCode()->willReturn('US');
     $memberCountry->getCode()->willReturn('US');
     $zoneCountry->getType()->willReturn(ZoneInterface::TYPE_COUNTRY);
     $zoneCountry->getMembers()->willReturn([$memberCountry]);
     $memberCountry->getBelongsTo()->willReturn($zoneCountry);
     $this->matchAll($address, 'shipping')->shouldReturn([$zoneCountry]);
 }
示例#15
0
 /**
  * @param AddressInterface    $address
  * @param ZoneMemberInterface $member
  *
  * @return bool
  *
  * @throws \InvalidArgumentException
  */
 protected function addressBelongsToZoneMember(AddressInterface $address, ZoneMemberInterface $member)
 {
     switch ($type = $member->getBelongsTo()->getType()) {
         case ZoneInterface::TYPE_PROVINCE:
             return null !== $address->getProvinceCode() && $address->getProvinceCode() === $member->getCode();
         case ZoneInterface::TYPE_COUNTRY:
             return null !== $address->getCountryCode() && $address->getCountryCode() === $member->getCode();
         case ZoneInterface::TYPE_ZONE:
             $zone = $this->getZoneByCode($member->getCode());
             return $this->addressBelongsToZone($address, $zone);
         default:
             throw new \InvalidArgumentException(sprintf('Unexpected zone type "%s".', $type));
     }
 }
示例#16
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));
 }
 function it_gets_province_name_form_address_if_its_abbreviation_is_not_set(AddressInterface $address)
 {
     $address->getProvinceName()->willReturn('Ulster');
     $this->getAbbreviation($address)->shouldReturn('Ulster');
 }