frontend/controllers/UserController.php
public function actionAddress( $ctype ) {

		$user		= Yii::$app->core->getUser();
		$address	= null;

		// Accept only selected type for a user
		if( !in_array( $ctype, [ Address::TYPE_PRIMARY, Address::TYPE_BILLING, Address::TYPE_MAILING, Address::TYPE_SHIPPING ] ) ) {

			throw new InvalidArgumentException( 'Address type not allowed.' );
		}

		switch( $ctype ) {

			case Address::TYPE_PRIMARY: {

				$address = $user->primaryAddress;

				break;
			}
			case Address::TYPE_BILLING: {

				$address = $user->billingAddress;

				break;
			}
			case Address::TYPE_MAILING: {

				$address = $user->mailingAddress;

				break;
			}
			case Address::TYPE_SHIPPING: {

				$address = $user->shippingAddress;

				break;
			}
		}

		if( empty( $address ) ) {

			$address = $this->addressService->getModelObject();
		}

		if( $address->load( Yii::$app->request->post(), $address->getClassName() ) && $address->validate() ) {

			// Create/Update Address
			$address = $this->addressService->createOrUpdate( $address );

			// Create Mapping
			$modelAddress = $this->modelAddressService->activateByModelId( $user->id, CoreGlobal::TYPE_USER, $address->id, $ctype );

			return $this->refresh();
		}

		$countryMap		= Yii::$app->factory->get( 'countryService' )->getIdNameMap();
		$countryId		= isset( $address->country ) ? $address->country->id : array_keys( $countryMap )[ 0 ];
		$provinceMap	= Yii::$app->factory->get( 'provinceService' )->getMapByCountryId( $countryId, [ 'default' => true, 'defaultValue' => Yii::$app->core->provinceLabel ] );
		$provinceId		= isset( $address->province ) ? $address->province->id : array_keys( $provinceMap )[ 0 ];
		$regionMap		= Yii::$app->factory->get( 'regionService' )->getMapByProvinceId( $provinceId, [ 'default' => true, 'defaultValue' => Yii::$app->core->regionLabel ] );

		return $this->render( 'address', [
			'user' => $user,
			'address' => $address,
			'countryMap' => $countryMap,
			'provinceMap' => $provinceMap,
			'regionMap' => $regionMap
		]);
	}
public function actionAddress( $ctype ) {

		$user		= Yii::$app->core->getUser();
		$address	= null;

		// Accept only selected type for a user
		if( !in_array( $ctype, [ Address::TYPE_PRIMARY, Address::TYPE_BILLING, Address::TYPE_MAILING, Address::TYPE_SHIPPING ] ) ) {

			throw new InvalidArgumentException( 'Address type not allowed.' );
		}

		switch( $ctype ) {

			case Address::TYPE_PRIMARY: {

				$address = $user->primaryAddress;

				break;
			}
			case Address::TYPE_BILLING: {

				$address = $user->billingAddress;

				break;
			}
			case Address::TYPE_MAILING: {

				$address = $user->mailingAddress;

				break;
			}
			case Address::TYPE_SHIPPING: {

				$address = $user->shippingAddress;

				break;
			}
		}

		if( empty( $address ) ) {

			$address = $this->addressService->getModelObject();
		}

		if( $address->load( Yii::$app->request->post(), $address->getClassName() ) && $address->validate() ) {

			// Create/Update Address
			$address = $this->addressService->createOrUpdate( $address );

			// Create Mapping
			$modelAddress = $this->modelAddressService->activateByModelId( $user->id, CoreGlobal::TYPE_USER, $address->id, $ctype );

			return $this->refresh();
		}

		$countryMap		= Yii::$app->factory->get( 'countryService' )->getIdNameMap();
		$countryId		= isset( $address->country ) ? $address->country->id : array_keys( $countryMap )[ 0 ];
		$provinceMap	= Yii::$app->factory->get( 'provinceService' )->getMapByCountryId( $countryId, [ 'default' => true, 'defaultValue' => Yii::$app->core->provinceLabel ] );
		$provinceId		= isset( $address->province ) ? $address->province->id : array_keys( $provinceMap )[ 0 ];
		$regionMap		= Yii::$app->factory->get( 'regionService' )->getMapByProvinceId( $provinceId, [ 'default' => true, 'defaultValue' => Yii::$app->core->regionLabel ] );

		return $this->render( 'address', [
			'user' => $user,
			'address' => $address,
			'countryMap' => $countryMap,
			'provinceMap' => $provinceMap,
			'regionMap' => $regionMap
		]);
	}
public function actionAddress ( $ ctype ) { $ user = Yii :: $ app -> core -> getUser ( ) ; $ address = null ; // Accept only selected type for a user if ( ! in_array ( $ ctype , [ Address :: TYPE_PRIMARY , Address :: TYPE_BILLING , Address :: TYPE_MAILING , Address :: TYPE_SHIPPING ] ) ) { throw new InvalidArgumentException ( 'Address type not allowed.' ) ; } switch ( $ ctype ) { case Address :: TYPE_PRIMARY : { $ address = $ user -> primaryAddress ; break ; } case Address :: TYPE_BILLING : { $ address = $ user -> billingAddress ; break ; } case Address :: TYPE_MAILING : { $ address = $ user -> mailingAddress ; break ; } case Address :: TYPE_SHIPPING : { $ address = $ user -> shippingAddress ; break ; } } if ( empty ( $ address ) ) { $ address = $ this -> addressService -> getModelObject ( ) ; } if ( $ address -> load ( Yii :: $ app -> request -> post ( ) , $ address -> getClassName ( ) ) && $ address -> validate ( ) ) { // Create/Update Address $ address = $ this -> addressService -> createOrUpdate ( $ address ) ; // Create Mapping $ modelAddress = $ this -> modelAddressService -> activateByModelId ( $ user -> id , CoreGlobal :: TYPE_USER , $ address -> id , $ ctype ) ; return $ this -> refresh ( ) ; } $ countryMap = Yii :: $ app -> factory -> get ( 'countryService' ) -> getIdNameMap ( ) ; $ countryId = isset ( $ address -> country ) ? $ address -> country -> id : array_keys ( $ countryMap ) [ 0 ] ; $ provinceMap = Yii :: $ app -> factory -> get ( 'provinceService' ) -> getMapByCountryId ( $ countryId , [ 'default' => true , 'defaultValue' => Yii :: $ app -> core -> provinceLabel ] ) ; $ provinceId = isset ( $ address -> province ) ? $ address -> province -> id : array_keys ( $ provinceMap ) [ 0 ] ; $ regionMap = Yii :: $ app -> factory -> get ( 'regionService' ) -> getMapByProvinceId ( $ provinceId , [ 'default' => true , 'defaultValue' => Yii :: $ app -> core -> regionLabel ] ) ; return $ this -> render ( 'address' , [ 'user' => $ user , 'address' => $ address , 'countryMap' => $ countryMap , 'provinceMap' => $ provinceMap , 'regionMap' => $ regionMap ] ) ; }
The address action allows user to update primary address using form submit. Use the
corresponding Ajax Action to handle multiple user address.

In case we need multiple address using form submit, this action can be overridden by
child classes to load multiple address.

@return string
The address action allows user to update primary address using form submit . Use the corresponding Ajax Action to handle multiple user address .