/** * Add a postalcode with the premise that the city has to be added already * * @param CityInterface $city City * @param string $postalCodeCode Postalcode code * * @return PostalCodeInterface */ public function addPostalCode(CityInterface $city, $postalCodeCode) { $postalCodeCode = trim($postalCodeCode); $cityCountry = $city->getCountry(); $postalCodeId = $cityCountry->getCode() . '_' . trim($postalCodeCode); if (!isset($this->postalCodes[$postalCodeId])) { $postalCode = $this->postalCodeFactory->create(); $postalCode->setId($postalCodeId)->setCode($postalCodeCode)->setCities(new ArrayCollection())->addCity($city)->setEnabled(true); $city->addPostalCode($postalCode); $this->postalCodes[$postalCodeId] = $postalCode; } return $this->postalCodes[$postalCodeId]; }