Exemplo n.º 1
0
 public function testGetRegionCodeRegionFailure()
 {
     $this->address->setData(['region' => 1, 'region_id' => 1, 'country_id' => 1]);
     $this->regionFactoryMock->expects($this->once())->method('create')->willReturn($this->regionMock);
     $this->regionMock->expects($this->once())->method('load')->with(1)->willReturn($this->regionMock);
     $this->regionMock->expects($this->once())->method('getCountryId')->willReturn(2);
     $this->regionMock->expects($this->never())->method('getCode');
     $this->assertEquals(null, $this->address->getRegionCode());
 }
Exemplo n.º 2
0
 public function testBeforeSave()
 {
     $regionId = '23';
     $countryId = '67';
     $this->object->expects($this->once())->method('getData')->with('region')->willReturn($regionId);
     $this->object->expects($this->once())->method('getCountryId')->willReturn($countryId);
     $this->regionFactory->expects($this->once())->method('create')->willReturn($this->region);
     $this->region->expects($this->once())->method('load')->with($regionId)->willReturnSelf();
     $this->region->expects($this->atLeastOnce())->method('getId')->willReturn($regionId);
     $this->region->expects($this->once())->method('getCountryId')->willReturn($countryId);
     $this->object->expects($this->once())->method('setRegionId')->with($regionId)->willReturnSelf();
     $this->region->expects($this->once())->method('getName')->willReturn('Region name');
     $this->object->expects($this->once())->method('setRegion')->with('Region name');
     $this->model->beforeSave($this->object);
 }
Exemplo n.º 3
0
 public function getRegion()
 {
     if (!$this->getCountry()->getId()) {
         return NULL;
     }
     if (is_null($this->region)) {
         $countryRegions = $this->getCountry()->getRegionCollection();
         $countryRegions->getSelect()->where('code = ? OR default_name = ?', $this->getState());
         $this->region = $countryRegions->getFirstItem();
         if ($this->isRegionValidationRequired() && !$this->region->getId()) {
             throw new \Ess\M2ePro\Model\Exception(sprintf('State/Region "%s" in the shipping address is invalid.', $this->getState()));
         }
     }
     return $this->region;
 }
Exemplo n.º 4
0
 /**
  * Convert a rate model to a TaxRate data object
  *
  * @param TaxRateModel $rateModel
  * @return TaxRateDataObject
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function createTaxRateDataObjectFromModel(TaxRateModel $rateModel)
 {
     $this->taxRateDataObjectBuilder->populateWithArray([]);
     if ($rateModel->getId()) {
         $this->taxRateDataObjectBuilder->setId($rateModel->getId());
     }
     if ($rateModel->getTaxCountryId()) {
         $this->taxRateDataObjectBuilder->setCountryId($rateModel->getTaxCountryId());
     }
     /* tax region id may be 0 which is "*" which would fail an if check */
     if ($rateModel->getTaxRegionId() !== null) {
         $this->taxRateDataObjectBuilder->setRegionId($rateModel->getTaxRegionId());
         $regionName = $this->directoryRegion->load($rateModel->getTaxRegionId())->getCode();
         $this->taxRateDataObjectBuilder->setRegionName($regionName);
     }
     if ($rateModel->getRegionName()) {
         $this->taxRateDataObjectBuilder->setRegionName($rateModel->getRegionName());
     }
     if ($rateModel->getTaxPostcode()) {
         $this->taxRateDataObjectBuilder->setPostcode($rateModel->getTaxPostcode());
     }
     if ($rateModel->getCode()) {
         $this->taxRateDataObjectBuilder->setCode($rateModel->getCode());
     }
     if ($rateModel->getRate()) {
         $this->taxRateDataObjectBuilder->setPercentageRate((double) $rateModel->getRate());
     }
     if ($rateModel->getZipIsRange()) {
         $zipRange = $this->zipRangeDataObjectBuilder->populateWithArray([])->setFrom($rateModel->getZipFrom())->setTo($rateModel->getZipTo())->create();
         $this->taxRateDataObjectBuilder->setZipRange($zipRange);
     }
     $this->taxRateDataObjectBuilder->setTitles($this->createTitleArrayFromModel($rateModel));
     return $this->taxRateDataObjectBuilder->create();
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getRegionName()
 {
     if (!$this->getData(self::KEY_REGION_NAME)) {
         $regionName = $this->directoryRegion->load($this->getTaxRegionId())->getCode();
         $this->setData(self::KEY_REGION_NAME, $regionName);
     }
     return $this->getData(self::KEY_REGION_NAME);
 }