Skip to content

Commit fd04cb3

Browse files
committed
Merged in develop (pull request #15)
APITOCART-13879 adding store
2 parents e16b8a1 + 0bcfb30 commit fd04cb3

File tree

5 files changed

+62
-78
lines changed

5 files changed

+62
-78
lines changed

src/app/Http/Controllers/StoresController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public function fields(Request $request, $id=null)
6767
{
6868
$store = collect($this->api2cart->getCartsList())->where('cart_id',$id)->first();
6969

70-
Log::debug( print_r($store,1) );
70+
// Log::debug( print_r($store,1) );
7171

72-
return '';
72+
// return '';
7373

74-
// return view('stores.store_fields', compact('store'));
74+
return view('stores.store_fields', compact('store'));
7575

7676
}
7777

@@ -103,11 +103,16 @@ public function store(StoreRequest $request)
103103
$requestData = $request->except(['_token']);
104104
$requestData['field']['cart_id'] = $request->get('cart_id');
105105

106-
//TODO: for bridget carts ftp credentials is optional
107-
// 'ftp_host','ftp_user','ftp_password','ftp_port','ftp_store_dir'
106+
$fields = array_merge( $requestData['field'], $requestData['custom'] );
108107

109-
// $this->api2cart->addCart( $requestData['field'] );
108+
$id = $this->api2cart->addCart( $fields );
110109

110+
111+
if ( $request->ajax() ){
112+
return response()->json( ['data' => $id, 'log' => $this->api2cart->getLog() ] );
113+
}
114+
115+
return redirect( route('stores.index') );
111116
}
112117

113118
/**

src/app/Http/Requests/StoreRequest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Rules\Api2CartStoreFields;
66
use Illuminate\Foundation\Http\FormRequest;
7+
use Illuminate\Support\Facades\Log;
78

89
class StoreRequest extends FormRequest
910
{
@@ -24,9 +25,19 @@ public function authorize()
2425
*/
2526
public function rules()
2627
{
28+
// Log::debug( print_r( request()->all(),1) );
29+
2730
return [
2831
'cart_id' => ['required'],
2932
'field.*' => ['required']
3033
];
3134
}
35+
36+
public function messages()
37+
{
38+
return [
39+
'required' => 'The field is required.'
40+
];
41+
}
42+
3243
}

src/app/Services/Api2Cart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,12 @@ public function addCart($fields)
304304
(isset($fields['squarespace_api_key'])) ? $fields['squarespace_api_key'] : null
305305
);
306306

307-
Log::debug( print_r($result,1) );
307+
// Log::debug( print_r($result,1) );
308308

309309
$this->logApiCall( 'account.cart.add.json', $result->getReturnCode(), $this->cart->getConfig(), null, null, null, $result->getReturnMessage(), $fields );
310310

311311
if ( $result->getReturnCode() == 0 ){
312-
return $this->mapToArray( $result->getResult()->getSupportedPlatforms() );
312+
return $result->getResult();
313313
} else {
314314
if ($this->debug) Log::debug( print_r($result,1) );
315315
return null;

src/resources/views/stores/index.blade.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ function addStore()
120120
})
121121
.then(function (presponse) {
122122
123-
//TODO: store added
124-
123+
Swal.fire(
124+
'Added!',
125+
'Store has been added.',
126+
'success'
127+
).then((result) => {
128+
window.location.reload();
129+
});
125130
126131
return true;
127132
})
@@ -161,26 +166,6 @@ function addStore()
161166
axios.get( 'stores/fields/' + item.cart_id ).then(function (cfresponse) {
162167
$('#addItemFields').append( cfresponse.data );
163168
});
164-
165-
166-
167-
// console.log( );
168-
169-
// for (let value of Object.values( item.params )) {
170-
// // console.log( value );
171-
//
172-
// $('#addItemFields').append(
173-
// '<div class="form-group row">\n' +
174-
// ' <label for="field.'+value+'" class="col-4 col-form-label">'+value+'</label>\n' +
175-
// ' <div class="col-8">\n' +
176-
// ' <input class="form-control" id="field.'+value+'" name="field['+value+']" required="required" >\n' +
177-
// ' <div class="invalid-feedback"></div>\n' +
178-
// ' </div>\n' +
179-
// ' </div>'
180-
// );
181-
// }
182-
183-
184169
});
185170
186171
Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11

2-
@php $filtered = collect( array_diff($store['params'],['cart_id','verify','ftp_host','ftp_user','ftp_password','ftp_port','ftp_store_dir']) ); @endphp
2+
@php
3+
$required = collect( $store['params']['required'][0] );
4+
$custom = collect( $store['params']['additional'] );
5+
@endphp
36

4-
@foreach( $filtered as $k=>$v )
7+
@foreach( $required->whereNotIn('name',['cart_id']) as $k=>$v )
58
<div class="form-group row">
6-
<label for="{{ $v }}" class="col-4 col-form-label">{{ $v }}</label>
9+
<label for="field.{{$v['name']}}" class="col-4 col-form-label">{{ $v['name'] }}</label>
710
<div class="col-8">
8-
<input type="text" class="form-control" id="field.{{$v}}" name="field[{{ $v }}]" value="">
11+
<input type="text" class="form-control" id="field.{{$v['name']}}" name="field[{{ $v['name'] }}]" value="">
12+
<small id="emailHelp" class="form-text text-muted">{{ $v['description'] }}</small>
913
<div class="invalid-feedback"></div>
1014
</div>
1115
</div>
1216
@endforeach
13-
@if( in_array('verify', $store['params']) )
17+
18+
@if( count($custom) > 0 )
19+
1420
<div class="form-group row">
1521
<label for="verify" class="col-4 col-form-label"></label>
1622
<div class="col-8">
@@ -20,54 +26,31 @@
2026
</div>
2127
</div>
2228
</div>
23-
@endif
24-
25-
@if( in_array('ftp_host', $store['params']) && in_array('ftp_store_dir', $store['params']) )
26-
27-
28-
<div class="custom-control custom-checkbox">
29-
<input type="checkbox" class="custom-control-input" id="upload_bridge" name="upload_bridge" data-toggle="collapse" data-target="#collapseExample">
30-
<label class="custom-control-label" for="upload_bridge">Please upload bridge to my store</label>
31-
</div>
32-
33-
<div class="collapse" id="collapseExample">
3429

3530
<div class="form-group row">
36-
<label for="ftp_host" class="col-4 col-form-label">ftp_host</label>
37-
<div class="col-8">
38-
<input type="text" class="form-control" id="ftp_host" name="ftp_host" value="">
39-
<div class="invalid-feedback"></div>
40-
</div>
41-
</div>
42-
<div class="form-group row">
43-
<label for="ftp_port" class="col-4 col-form-label">ftp_port</label>
44-
<div class="col-8">
45-
<input type="text" class="form-control" id="ftp_port" name="ftp_port" value="">
46-
<div class="invalid-feedback"></div>
47-
</div>
48-
</div>
49-
<div class="form-group row">
50-
<label for="ftp_user" class="col-4 col-form-label">ftp_user</label>
51-
<div class="col-8">
52-
<input type="text" class="form-control" id="ftp_user" name="ftp_user" value="">
53-
<div class="invalid-feedback"></div>
54-
</div>
55-
</div>
56-
<div class="form-group row">
57-
<label for="ftp_password" class="col-4 col-form-label">ftp_password</label>
31+
<label for="verify" class="col-4 col-form-label"></label>
5832
<div class="col-8">
59-
<input type="text" class="form-control" id="ftp_password" name="ftp_password" value="">
60-
<div class="invalid-feedback"></div>
33+
<div class="custom-control custom-checkbox">
34+
<input type="checkbox" class="custom-control-input" id="use_additional" name="use_additional" data-toggle="collapse" data-target="#collapseExample" >
35+
<label class="custom-control-label" for="use_additional">Use additional params</label>
36+
</div>
6137
</div>
6238
</div>
63-
<div class="form-group row">
64-
<label for="ftp_store_dir" class="col-4 col-form-label">ftp_store_dir</label>
65-
<div class="col-8">
66-
<input type="text" class="form-control" id="ftp_store_dir" name="ftp_store_dir" value="">
67-
<div class="invalid-feedback"></div>
68-
</div>
39+
40+
41+
42+
<div class="collapse" id="collapseExample">
43+
@foreach( $custom->whereNotIn('name',['verify']) as $item )
44+
<div class="form-group row">
45+
<label for="custom.{{$item['name']}}" class="col-4 col-form-label">{{ $item['name'] }}</label>
46+
<div class="col-8">
47+
<input type="text" class="form-control" id="custom.{{$item['name']}}" name="custom[{{ $item['name'] }}]" value="">
48+
<small id="{{$item['name']}}.Help" class="form-text text-muted">{{ $item['description'] }}</small>
49+
<div class="invalid-feedback"></div>
50+
</div>
51+
</div>
52+
@endforeach
6953
</div>
7054

71-
</div>
7255

73-
@endif
56+
@endif

0 commit comments

Comments
 (0)