22
33namespace Vuefront \Vuefront \Model \Api \Resolver \Store ;
44
5- use \Vuefront \Vuefront \Model \Api \System \Engine \Resolver ;
5+ use Magento \Checkout \Model \Session ;
6+ use Magento \Framework \Pricing \Helper \Data ;
7+ use Magento \Framework \UrlInterface ;
8+ use Magento \Shipping \Model \Config ;
9+ use Vuefront \Vuefront \Model \Api \System \Engine \Resolver ;
610
711class Checkout extends Resolver
812{
13+ private $ _currencyHelper ;
914 /**
10- * @var \Magento\Framework\ UrlInterface
15+ * @var UrlInterface
1116 */
1217 private $ url ;
1318
19+ /**
20+ * @var Config
21+ */
22+ private $ _shippingModelConfig ;
23+
24+ /**
25+ * @var Session
26+ */
27+ protected $ checkoutSession ;
28+
1429 public function __construct (
15- \Magento \Framework \UrlInterface $ url
30+ Config $ shippingModelConfig ,
31+ UrlInterface $ url ,
32+ Session $ session ,
33+ Data $ currencyHelper
1634 ) {
35+ $ this ->_currencyHelper = $ currencyHelper ;
1736 $ this ->url = $ url ;
37+ $ this ->_shippingModelConfig = $ shippingModelConfig ;
38+ $ this ->checkoutSession = $ session ;
1839 }
1940
2041 public function link ()
@@ -23,4 +44,288 @@ public function link()
2344 'link ' => $ this ->url ->getUrl ('checkout ' )
2445 ];
2546 }
47+
48+ public function paymentMethods ()
49+ {
50+ $ this ->load ->model ('store/checkout ' );
51+
52+ $ response = $ this ->model_store_checkout ->requestCheckout (
53+ '{
54+ payments {
55+ setting
56+ codename
57+ status
58+ name
59+ }
60+ } ' ,
61+ []
62+ );
63+
64+ $ methods = [];
65+
66+ foreach ($ response ['payments ' ] as $ key => $ value ) {
67+ if ($ value ['status ' ]) {
68+ $ methods [] = [
69+ 'id ' => $ value ['codename ' ],
70+ 'codename ' => $ value ['codename ' ],
71+ "name " => $ value ['name ' ]
72+ ];
73+ }
74+ }
75+
76+ return $ methods ;
77+ }
78+
79+ public function shippingMethods ($ args )
80+ {
81+ $ result = [];
82+
83+ $ carriers = $ this ->_shippingModelConfig ->getActiveCarriers ();
84+
85+ foreach ($ carriers as $ shippingCode => $ shippingModel ) {
86+ $ shippingPrice = $ this ->_currencyHelper ->currency ($ shippingModel ->getConfigData ('price ' ), true , false );
87+ $ result [] = [
88+ 'id ' => $ shippingModel ->getCarrierCode (),
89+ 'codename ' => $ shippingModel ->getCarrierCode (),
90+ "name " => $ shippingModel ->getConfigData ('title ' ) . ' - ' . $ shippingPrice
91+ ];
92+ }
93+
94+ return $ result ;
95+ }
96+
97+ public function paymentAddress ()
98+ {
99+ $ fields = [];
100+
101+ $ fields [] = [
102+ 'type ' => 'text ' ,
103+ 'name ' => 'firstName ' ,
104+ 'required ' => true
105+ ];
106+ $ fields [] = [
107+ 'type ' => 'text ' ,
108+ 'name ' => 'lastName ' ,
109+ 'required ' => true
110+ ];
111+
112+ $ fields [] = [
113+ 'type ' => 'text ' ,
114+ 'name ' => 'email ' ,
115+ 'required ' => true
116+ ];
117+
118+ $ fields [] = [
119+ 'type ' => 'text ' ,
120+ 'name ' => 'company ' ,
121+ 'required ' => false
122+ ];
123+ $ fields [] = [
124+ 'type ' => 'text ' ,
125+ 'name ' => 'address1 ' ,
126+ 'required ' => true
127+ ];
128+ $ fields [] = [
129+ 'type ' => 'text ' ,
130+ 'name ' => 'address2 ' ,
131+ 'required ' => false
132+ ];
133+ $ fields [] = [
134+ 'type ' => 'text ' ,
135+ 'name ' => 'city ' ,
136+ 'required ' => true
137+ ];
138+ $ fields [] = [
139+ 'type ' => 'text ' ,
140+ 'name ' => 'postcode ' ,
141+ 'required ' => true
142+ ];
143+
144+ $ fields [] = [
145+ 'type ' => 'country ' ,
146+ 'name ' => 'country_id ' ,
147+ 'required ' => true
148+ ];
149+
150+ $ fields [] = [
151+ 'type ' => 'zone ' ,
152+ 'name ' => 'zone_id ' ,
153+ 'required ' => true
154+ ];
155+
156+ $ agree = null ;
157+
158+ return [
159+ 'fields ' => $ fields ,
160+ 'agree ' => $ agree
161+ ];
162+ }
163+
164+ public function shippingAddress ()
165+ {
166+ $ fields = [];
167+
168+ $ fields [] = [
169+ 'type ' => 'text ' ,
170+ 'name ' => 'firstName ' ,
171+ 'required ' => true
172+ ];
173+ $ fields [] = [
174+ 'type ' => 'text ' ,
175+ 'name ' => 'lastName ' ,
176+ 'required ' => true
177+ ];
178+
179+ $ fields [] = [
180+ 'type ' => 'text ' ,
181+ 'name ' => 'company ' ,
182+ 'required ' => false
183+ ];
184+ $ fields [] = [
185+ 'type ' => 'text ' ,
186+ 'name ' => 'address1 ' ,
187+ 'required ' => true
188+ ];
189+ $ fields [] = [
190+ 'type ' => 'text ' ,
191+ 'name ' => 'address2 ' ,
192+ 'required ' => false
193+ ];
194+ $ fields [] = [
195+ 'type ' => 'text ' ,
196+ 'name ' => 'address3 ' ,
197+ 'required ' => false
198+ ];
199+ $ fields [] = [
200+ 'type ' => 'text ' ,
201+ 'name ' => 'city ' ,
202+ 'required ' => true
203+ ];
204+ $ fields [] = [
205+ 'type ' => 'zone ' ,
206+ 'name ' => 'zone_id ' ,
207+ 'required ' => true
208+ ];
209+ $ fields [] = [
210+ 'type ' => 'text ' ,
211+ 'name ' => 'postcode ' ,
212+ 'required ' => true
213+ ];
214+
215+ $ fields [] = [
216+ 'type ' => 'country ' ,
217+ 'name ' => 'country_id ' ,
218+ 'required ' => true
219+ ];
220+
221+ return $ fields ;
222+ }
223+
224+ public function createOrder ($ args )
225+ {
226+ // $this->session->data['shipping_address'] = array();
227+
228+ // foreach ($this->shippingAddress() as $value) {
229+ // $this->session->data['shipping_address'][$value['name']] = '';
230+ // }
231+
232+ // $this->session->data['payment_address'] = array(
233+ // 'custom_field' => array()
234+ // );
235+
236+ // $paymentAddress = $this->paymentAddress();
237+ // foreach ($paymentAddress['fields'] as $value) {
238+ // $this->session->data['payment_address'][$value['name']] = '';
239+ // }
240+
241+ // $this->session->data['payment_method'] = null;
242+ // $this->session->data['shipping_method'] = null;
243+ return ['success ' => 'success ' ];
244+ }
245+
246+ public function updateOrder ($ args )
247+ {
248+ // foreach ($args['paymentAddress'] as $value) {
249+ // if (strpos($value['name'], "vfCustomField-") !== false) {
250+ // if ($value['value']) {
251+ // $field_name = str_replace("vfCustomField-", "", $value['name']);
252+ // $field_name = explode('-', $field_name);
253+ // if (!isset($this->session->data['payment_address']['custom_field'][$field_name[0]])) {
254+ // $this->session->data['payment_address']['custom_field'][$field_name[0]] = array();
255+ // }
256+ // $this->session->data['payment_address']['custom_field'][$field_name[0]][$field_name[1]] = $value['value'];
257+ // }
258+ // } else {
259+ // if ($value['value']) {
260+ // $this->session->data['payment_address'][$value['name']] = $value['value'];
261+ // }
262+ // }
263+ // }
264+
265+ // foreach ($args['shippingAddress'] as $value) {
266+ // if (strpos($value['name'], "vfCustomField-") !== false) {
267+ // if ($value['value']) {
268+ // $field_name = str_replace("vfCustomField-", "", $value['name']);
269+ // $field_name = explode('-', $field_name);
270+ // if (!isset($this->session->data['shipping_address']['custom_field'][$field_name[0]])) {
271+ // $this->session->data['shipping_address']['custom_field'][$field_name[0]] = array();
272+ // }
273+ // $this->session->data['shipping_address']['custom_field'][$field_name[0]][$field_name[1]] = $value['value'];
274+ // }
275+ // } else {
276+ // if ($value['value']) {
277+ // $this->session->data['shipping_address'][$value['name']] = $value['value'];
278+ // }
279+ // }
280+ // }
281+
282+ // if (!empty($args['shippingMethod'])) {
283+ // $shipping = explode('.', $args['shippingMethod']);
284+
285+ // $this->load->model('extension/shipping/'.$shipping[0]);
286+
287+ // $quote = $this->{'model_extension_shipping_' . $shipping[0]}->getQuote($this->session->data['shipping_address']);
288+ // if ($quote) {
289+ // $this->session->data['shipping_method'] = $quote['quote'][$shipping[1]];
290+ // }
291+ // }
292+
293+ // $this->session->data['payment_method'] = $args['paymentMethod'];
294+ $ that = $ this ;
295+ return [
296+ 'paymentMethods ' => function ($ root , $ args ) use ($ that ) {
297+ return $ that ->load ->resolver ('store/checkout/paymentMethods ' , [
298+ 'parent ' => $ root ,
299+ 'args ' => $ args
300+ ]);
301+ },
302+ 'shippingMethods ' => function ($ root , $ args ) use ($ that ) {
303+ return $ that ->load ->resolver ('store/checkout/shippingMethods ' , [
304+ 'parent ' => $ root ,
305+ 'args ' => $ args
306+ ]);
307+ },
308+ 'totals ' => function ($ root , $ args ) use ($ that ) {
309+ return $ that ->load ->resolver ('store/checkout/totals ' , [
310+ 'parent ' => $ root ,
311+ 'args ' => $ args
312+ ]);
313+ }
314+ ];
315+ }
316+
317+ public function confirmOrder ()
318+ {
319+ return [
320+ 'url ' => '1 ' ,
321+ 'order ' => [
322+ 'id ' => '1 '
323+ ]
324+ ];
325+ }
326+
327+ public function totals ()
328+ {
329+ return [];
330+ }
26331}
0 commit comments