Skip to content

Commit

Permalink
customer account address
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Sep 22, 2017
1 parent ab3cfc2 commit a17f4c8
Showing 1 changed file with 78 additions and 21 deletions.
99 changes: 78 additions & 21 deletions app/appserver/modules/Customer/controllers/AddressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,63 @@ public function actionIndex(){
}


public function coll()
{
$identity = Yii::$app->user->identity;
$customer_id = $identity['id'];
$filter = [
'numPerPage' => 100,
'pageNum' => 1,
'orderBy' => ['updated_at' => SORT_DESC],
'where' => [
['customer_id' => $customer_id],
],
'asArray' => true,
];
$coll = Yii::$service->customer->address->coll($filter);
$arr = [];
if (isset($coll['coll']) && !empty($coll['coll'])) {
foreach($coll['coll'] as $one){
$one['stateName'] = Yii::$service->helper->country->getStateByContryCode($one['country'],$one['state']);
$one['countryName'] = Yii::$service->helper->country->getCountryNameByKey($one['country']);
$arr[] = $one;
public function actionEdit(){
$address = [];
$country = '';
$address_id = Yii::$app->request->get('address_id');
if($address_id){
$addressModel = Yii::$service->customer->address->getByPrimaryKey($address_id);
$identity = Yii::$app->user->identity;
$customer_id = $identity['id'];

if ($addressModel['address_id']) {
// 该id必须是当前用户的
if ($customer_id == $addressModel['customer_id']) {
foreach ($addressModel as $k=>$v) {
$address[$k] = $v;
}
}
}
$country = isset($address['country']) ? $address['country'] : '';

}else{

}
return $arr;
if(!$country){
$country = Yii::$service->helper->country->getDefaultCountry();
}
$countryArr = Yii::$service->helper->country->getAllCountryArray();
$address['countryArr'] = $countryArr;



$state = isset($address['state']) ? $address['state'] : '';
$stateArr = Yii::$service->helper->country->getStateByContryCode($country);
$stateIsSelect = 0;
if(!empty($stateArr)){
$stateIsSelect = 1;
}
$address['stateArr'] = $stateArr;
$address['stateIsSelect'] = $stateIsSelect;

// if (!$stateHtml) {
// $stateHtml = '<input id="state" name="address[state]" value="'.$state.'" title="State" class="input-text" style="" type="text">';
// } else {
// $stateHtml = '<select id="address:state" class="address_state validate-select" title="State" name="address[state]">
// <option value="">Please select region, state or province</option>'
// .$stateHtml.'</select>';
// }
// $this->_address['stateHtml'] = $stateHtml;

return [
'code' => 200,
'address' => $address,
];

}



public function actionRemove(){
$address_id = Yii::$app->request->post('address_id');
if($address_id){
Expand All @@ -81,4 +113,29 @@ public function removeAddressById($address_id)
Yii::$service->customer->address->remove($address_id, $customer_id);
}


public function coll()
{
$identity = Yii::$app->user->identity;
$customer_id = $identity['id'];
$filter = [
'numPerPage' => 100,
'pageNum' => 1,
'orderBy' => ['updated_at' => SORT_DESC],
'where' => [
['customer_id' => $customer_id],
],
'asArray' => true,
];
$coll = Yii::$service->customer->address->coll($filter);
$arr = [];
if (isset($coll['coll']) && !empty($coll['coll'])) {
foreach($coll['coll'] as $one){
$one['stateName'] = Yii::$service->helper->country->getStateByContryCode($one['country'],$one['state']);
$one['countryName'] = Yii::$service->helper->country->getCountryNameByKey($one['country']);
$arr[] = $one;
}
}
return $arr;
}
}

0 comments on commit a17f4c8

Please sign in to comment.