13
13
use Magento \GraphQl \Model \Query \ContextInterface ;
14
14
use Magento \Quote \Api \Data \CartInterface ;
15
15
use Magento \Quote \Model \Quote \Address ;
16
- use Magento \QuoteGraphQl \Model \Cart \Address \SaveQuoteAddressToCustomerAddressBook ;
17
16
18
17
/**
19
18
* Set billing address for a specified shopping cart
@@ -30,24 +29,16 @@ class SetBillingAddressOnCart
30
29
*/
31
30
private $ assignBillingAddressToCart ;
32
31
33
- /**
34
- * @var SaveQuoteAddressToCustomerAddressBook
35
- */
36
- private $ saveQuoteAddressToCustomerAddressBook ;
37
-
38
32
/**
39
33
* @param QuoteAddressFactory $quoteAddressFactory
40
34
* @param AssignBillingAddressToCart $assignBillingAddressToCart
41
- * @param SaveQuoteAddressToCustomerAddressBook $saveQuoteAddressToCustomerAddressBook
42
35
*/
43
36
public function __construct (
44
37
QuoteAddressFactory $ quoteAddressFactory ,
45
- AssignBillingAddressToCart $ assignBillingAddressToCart ,
46
- SaveQuoteAddressToCustomerAddressBook $ saveQuoteAddressToCustomerAddressBook
38
+ AssignBillingAddressToCart $ assignBillingAddressToCart
47
39
) {
48
40
$ this ->quoteAddressFactory = $ quoteAddressFactory ;
49
41
$ this ->assignBillingAddressToCart = $ assignBillingAddressToCart ;
50
- $ this ->saveQuoteAddressToCustomerAddressBook = $ saveQuoteAddressToCustomerAddressBook ;
51
42
}
52
43
53
44
/**
@@ -90,7 +81,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
90
81
);
91
82
}
92
83
93
- $ billingAddress = $ this ->createBillingAddress ($ context , $ customerAddressId , $ addressInput, $ sameAsShipping );
84
+ $ billingAddress = $ this ->createBillingAddress ($ context , $ customerAddressId , $ addressInput );
94
85
95
86
$ this ->assignBillingAddressToCart ->execute ($ cart , $ billingAddress , $ sameAsShipping );
96
87
}
@@ -101,7 +92,6 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
101
92
* @param ContextInterface $context
102
93
* @param int|null $customerAddressId
103
94
* @param array $addressInput
104
- * @param bool $sameAsShipping
105
95
* @return Address
106
96
* @throws GraphQlAuthorizationException
107
97
* @throws GraphQlInputException
@@ -110,21 +100,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
110
100
private function createBillingAddress (
111
101
ContextInterface $ context ,
112
102
?int $ customerAddressId ,
113
- ?array $ addressInput ,
114
- $ sameAsShipping
103
+ ?array $ addressInput
115
104
): Address {
116
105
if (null === $ customerAddressId ) {
117
106
$ billingAddress = $ this ->quoteAddressFactory ->createBasedOnInputData ($ addressInput );
118
-
119
- $ customerId = $ context ->getUserId ();
120
- // need to save address only for registered user and if save_in_address_book = true
121
- // and address is not same as shipping
122
- if (0 !== $ customerId
123
- && isset ($ addressInput ['save_in_address_book ' ])
124
- && (bool )$ addressInput ['save_in_address_book ' ] && !$ sameAsShipping
125
- ) {
126
- $ this ->saveQuoteAddressToCustomerAddressBook ->execute ($ billingAddress , $ customerId );
127
- }
128
107
} else {
129
108
if (false === $ context ->getExtensionAttributes ()->getIsCustomer ()) {
130
109
throw new GraphQlAuthorizationException (__ ('The current customer isn \'t authorized. ' ));
@@ -136,15 +115,13 @@ private function createBillingAddress(
136
115
);
137
116
}
138
117
$ errors = $ billingAddress ->validate ();
139
-
140
118
if (true !== $ errors ) {
141
119
$ e = new GraphQlInputException (__ ('Billing address errors ' ));
142
120
foreach ($ errors as $ error ) {
143
121
$ e ->addError (new GraphQlInputException ($ error ));
144
122
}
145
123
throw $ e ;
146
124
}
147
-
148
125
return $ billingAddress ;
149
126
}
150
127
}
0 commit comments