@@ -82,6 +82,11 @@ class Checkout extends Resolver
82
82
*/
83
83
protected $ orderSender ;
84
84
85
+ /**
86
+ * @var \Magento\Quote\Model\Quote\PaymentFactory
87
+ */
88
+ protected $ paymentFactory ;
89
+
85
90
public function __construct (
86
91
Config $ shippingModelConfig ,
87
92
UrlInterface $ url ,
@@ -97,7 +102,8 @@ public function __construct(
97
102
\Magento \Catalog \Api \ProductRepositoryInterface $ productRepository ,
98
103
\Magento \Customer \Api \CustomerRepositoryInterface $ customerRepository ,
99
104
\Magento \Quote \Model \QuoteManagement $ quoteManagement ,
100
- \Magento \Sales \Model \Order \Email \Sender \OrderSender $ orderSender
105
+ \Magento \Sales \Model \Order \Email \Sender \OrderSender $ orderSender ,
106
+ \Magento \Quote \Model \Quote \PaymentFactory $ paymentFactory
101
107
) {
102
108
$ this ->_currencyHelper = $ currencyHelper ;
103
109
$ this ->url = $ url ;
@@ -114,6 +120,7 @@ public function __construct(
114
120
$ this ->customerRepository = $ customerRepository ;
115
121
$ this ->quoteManagement = $ quoteManagement ;
116
122
$ this ->orderSender = $ orderSender ;
123
+ $ this ->paymentFactory = $ paymentFactory ;
117
124
}
118
125
119
126
public function link ()
@@ -407,7 +414,6 @@ public function updateOrder($args)
407
414
->setCity ($ shippingAddress ['city ' ])
408
415
->setCountryId ($ shippingAddress ['country_id ' ])
409
416
->setRegionId ($ shippingAddress ['zone_id ' ])
410
- // ->setRegion($region)
411
417
->setPostcode ($ shippingAddress ['postcode ' ])
412
418
->setTelephone ($ shippingAddress ['phone ' ])
413
419
->setSaveInAddressBook (0 )
@@ -446,11 +452,23 @@ public function updateOrder($args)
446
452
->setSaveInAddressBook (0 )
447
453
->setSameAsBilling (0 );
448
454
455
+ $ this ->checkoutSession ->getQuote ()->setCustomerEmail ($ shippingAddress ['email ' ]);
456
+ $ this ->checkoutSession ->getQuote ()->setCustomerFirstname ($ shippingAddress ['firstName ' ]);
457
+ $ this ->checkoutSession ->getQuote ()->setCustomerLastname ($ shippingAddress ['lastName ' ]);
458
+ $ this ->checkoutSession ->getQuote ()->setCustomerIsGuest (1 );
459
+
449
460
$ this ->checkoutSession ->getQuote ()->setBillingAddress ($ payment_address );
450
461
$ this ->checkoutSession ->getQuote ()->setShippingAddress ($ shipping_address );
451
462
463
+
452
464
$ this ->_sessionManager ->setPaymentMethod ($ args ['paymentMethod ' ]);
453
465
$ this ->_sessionManager ->setShippingMethod ($ args ['shippingMethod ' ]);
466
+ if (!empty ($ args ['paymentMethod ' ])) {
467
+ $ payment = $ this ->paymentFactory ->create ();
468
+ $ payment ->setMethod ($ args ['paymentMethod ' ]);
469
+ $ this ->checkoutSession ->getQuote ()->setPayment ($ payment );
470
+ }
471
+ $ this ->checkoutSession ->getQuote ()->save ();
454
472
455
473
$ that = $ this ;
456
474
return [
@@ -486,97 +504,37 @@ public function getCartItemsSkus() {
486
504
487
505
public function confirmOrder ()
488
506
{
489
-
490
- $ store = $ this ->storeManager ->getStore ();
491
- $ storeId = $ store ->getStoreId ();
492
-
493
- $ websiteId = $ this ->storeManager ->getStore ()->getWebsiteId ();
494
-
495
- $ shippingAddress = $ this ->_sessionManager ->getShippingAddress ();
496
- $ paymentAddress = $ this ->_sessionManager ->getPaymentAddress ();
497
-
498
- $ shippingMethod = $ this ->_sessionManager ->getShippingMethod ();
507
+ $ total = $ this ->checkoutSession ->getQuote ()->getGrandTotal ();
508
+ $ order = $ this ->quoteManagement ->submit ($ this ->checkoutSession ->getQuote ());
499
509
$ paymentMethod = $ this ->_sessionManager ->getPaymentMethod ();
500
510
501
- $ customer = $ this ->customerFactory ->create ();
502
- $ customer ->setWebsiteId ($ websiteId );
503
- $ customer ->loadByEmail ($ shippingAddress ['email ' ]);// load customet by email address
504
- if (!$ customer ->getId ()){
505
- //For guest customer create new cusotmer
506
- $ customer ->setWebsiteId ($ websiteId )
507
- ->setStore ($ store )
508
- ->setFirstname ($ shippingAddress ['firstName ' ])
509
- ->setLastname ($ shippingAddress ['lastName ' ])
510
- ->setEmail ($ shippingAddress ['email ' ])
511
- ->setPassword ($ shippingAddress ['email ' ]);
512
- $ customer ->save ();
513
- }
514
-
515
- // $quote=$this->_cartModel->getQuote();//$this->quote->create(); //Create object of quote
516
- /**
517
- * @var \Magento\Quote\Model\Quote
518
- */
519
- $ quote = $ this ->load ->resolver ('store/cart/getQuote ' );
520
-
521
- $ quote ->setStore ($ store ); //set store for our quote
522
- // /* for registered customer */
523
-
524
- $ customer = $ this ->customerRepository ->getById ($ customer ->getId ());
525
- $ quote ->setCurrency ();
526
- $ quote ->assignCustomer ($ customer ); //Assign quote to customer
527
-
528
- // $this->_cartModel->getQuote()->collectTotals();
529
- //add items in quote
530
-
531
- // $results = $this->_cartModel->getItems();
532
-
533
- // foreach ($results as $value) {
534
- // var_dump('item');
535
- // // /** @var \Magento\Catalog\Model\Product $product */
536
- // // $product = $value->getProduct();
537
- // // $quote->addProduct($product,$value->getQty());
538
- // }
539
-
540
- // //Set Billing and shipping Address to quote
541
- $ quote ->setBillingAddress ($ this ->checkoutSession ->getQuote ()->getBillingAddress ());
542
- $ quote ->setShippingAddress ($ this ->checkoutSession ->getQuote ()->getShippingAddress ());
543
-
544
- $ methodInfo = explode ('. ' , $ shippingMethod );
545
- var_dump (count ($ quote ->getAllVisibleItems ()));
546
-
547
- // set shipping method
548
- $ shippingAddress =$ quote ->getShippingAddress ();
549
- $ shippingAddress ->setCollectShippingRates (true )
550
- ->collectShippingRates ()
551
- ->setShippingMethod ($ methodInfo [1 ])->setShippingCarrierCode ($ methodInfo [0 ]); //shipping method, please verify flat rate shipping must be enable
552
- // // $quote->setPaymentMethod($paymentMethod); //payment method, please verify checkmo must be enable from admin
553
- // $quote->setInventoryProcessed(false); //decrease item stock equal to qty
554
- $ quote ->save (); //quote save
555
- // // Set Sales Order Payment, We have taken check/money order
556
- // $quote->getPayment()->importData(['method' => $paymentMethod]);
557
-
558
- // // Collect Quote Totals & Save
559
- $ quote ->collectTotals ()->save ();
560
- // // Create Order From Quote Object
561
- $ order = $ this ->quoteManagement ->submit ($ quote );
562
-
563
- var_dump ($ order ? 1 : 0 );
564
-
565
511
$ orderId = null ;
566
512
567
- // if($order) {
568
- // // throw new ÷
513
+ if (!$ order ) {
514
+ return [];
515
+ }
516
+
517
+ $ this ->orderSender ->send ($ order );
569
518
570
- // /* for send order email to customer email id */
571
- // $this->orderSender->send($order);
519
+ $ orderId = $ order ->getIncrementId ();
572
520
573
- // /* get order real id from order */
574
- // $orderId = $order->getIncrementId();
575
- // }
521
+ $ this ->load ->model ('store/checkout ' );
576
522
523
+ $ response = $ this ->model_store_checkout ->requestCheckout (
524
+ 'mutation($paymentMethod: String, $total: Float, $callback: String) {
525
+ createOrder(paymentMethod: $paymentMethod, total: $total, callback: $callback) {
526
+ url
527
+ }
528
+ } ' ,
529
+ array (
530
+ 'paymentMethod ' => $ paymentMethod ,
531
+ 'total ' => floatval ($ total ),
532
+ 'callback ' => '' //$this->url->link('extension/d_vuefront/store/checkout/callback', 'order_id='.$orderId, true)
533
+ )
534
+ );
577
535
578
536
return [
579
- 'url ' => ' 1 ' ,
537
+ 'url ' => $ response [ ' createOrder ' ][ ' url ' ] ,
580
538
'order ' => [
581
539
'id ' => $ orderId
582
540
]
0 commit comments