Skip to content

Commit a40c19e

Browse files
Merge pull request #6 from integer-net/5/Remove-Hyva-Dependency
Remove Hyva dependency: \Hyva\Theme\ViewModel\Cart\GraphQlQueries Dependency
2 parents 05be786 + 2b8e208 commit a40c19e

File tree

2 files changed

+238
-24
lines changed

2 files changed

+238
-24
lines changed

src/ViewModel/GraphQlQueries.php

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace IntegerNet\ShippingPreselection\ViewModel\Cart;
5+
6+
use Magento\Framework\View\Element\Block\ArgumentInterface;
7+
8+
class GraphQlQueries implements ArgumentInterface
9+
{
10+
/**
11+
* @return string
12+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
13+
*/
14+
public function getCartGraphQlQuery()
15+
{
16+
return '
17+
total_quantity
18+
is_virtual
19+
items {
20+
id
21+
errors
22+
prices {
23+
price {
24+
value
25+
}
26+
row_total {
27+
value
28+
currency
29+
}
30+
row_total_incl_tax {
31+
value
32+
currency
33+
}
34+
price_incl_tax{
35+
value
36+
}
37+
}
38+
product_type
39+
product {
40+
id
41+
name
42+
sku
43+
small_image {
44+
label
45+
url
46+
}
47+
url_key
48+
url_suffix
49+
price_tiers {
50+
quantity
51+
final_price {
52+
value
53+
}
54+
discount {
55+
amount_off
56+
percent_off
57+
}
58+
}
59+
}
60+
quantity
61+
... on SimpleCartItem {
62+
customizable_options {
63+
label
64+
values {
65+
label
66+
value
67+
price {
68+
value
69+
type
70+
}
71+
}
72+
}
73+
}
74+
... on VirtualCartItem {
75+
customizable_options {
76+
label
77+
values {
78+
label
79+
value
80+
price {
81+
value
82+
type
83+
}
84+
}
85+
}
86+
}
87+
... on DownloadableCartItem {
88+
customizable_options {
89+
label
90+
values {
91+
label
92+
value
93+
price {
94+
value
95+
type
96+
}
97+
}
98+
}
99+
}
100+
101+
... on ConfigurableCartItem {
102+
configurable_options {
103+
id
104+
option_label
105+
value_label
106+
}
107+
}
108+
... on BundleCartItem {
109+
bundle_options {
110+
id
111+
label
112+
values {
113+
quantity
114+
label
115+
}
116+
}
117+
customizable_options {
118+
label
119+
values {
120+
label
121+
value
122+
price {
123+
value
124+
type
125+
}
126+
}
127+
}
128+
}
129+
}
130+
available_payment_methods {
131+
code
132+
title
133+
}
134+
selected_payment_method {
135+
code
136+
title
137+
}
138+
applied_coupons {
139+
code
140+
}
141+
billing_address {
142+
country {
143+
code
144+
}
145+
region {
146+
label
147+
region_id
148+
}
149+
postcode
150+
}
151+
shipping_addresses {
152+
country {
153+
code
154+
}
155+
region {
156+
label
157+
region_id
158+
}
159+
postcode
160+
selected_shipping_method {
161+
amount {
162+
value
163+
currency
164+
}
165+
carrier_title
166+
carrier_code
167+
method_title
168+
method_code
169+
}
170+
available_shipping_methods {
171+
price_excl_tax {
172+
value
173+
currency
174+
}
175+
price_incl_tax {
176+
value
177+
currency
178+
}
179+
carrier_title
180+
carrier_code
181+
method_title
182+
method_code
183+
}
184+
}
185+
prices {
186+
grand_total {
187+
value
188+
currency
189+
}
190+
subtotal_excluding_tax {
191+
value
192+
currency
193+
}
194+
subtotal_including_tax {
195+
value
196+
currency
197+
}
198+
applied_taxes {
199+
amount {
200+
value
201+
currency
202+
}
203+
label
204+
}
205+
discounts {
206+
amount {
207+
value
208+
currency
209+
}
210+
label
211+
}
212+
}
213+
';
214+
}
215+
}

src/ViewModel/ShippingAddressMutation.php

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,44 @@
33

44
namespace IntegerNet\ShippingPreselection\ViewModel;
55

6+
use IntegerNet\ShippingPreselection\ViewModel\Cart\GraphQlQueries;
67
use Magento\Directory\Model\Country;
78
use Magento\Framework\View\Element\Block\ArgumentInterface;
8-
use Hyva\Theme\ViewModel\Cart\GraphQlQueries;
99

1010
class ShippingAddressMutation implements ArgumentInterface
1111
{
1212
private GraphQlQueries $graphQlQueries;
1313

14-
public function __construct(
15-
GraphQlQueries $graphQlQueries)
14+
public function __construct(GraphQlQueries $graphQlQueries)
1615
{
1716
$this->graphQlQueries = $graphQlQueries;
1817
}
1918

2019
public function getMutateAddressQuery()
2120
{
22-
return 'setShippingAddressesOnCart(
23-
input: {
24-
cart_id: "${this.cartId}"
25-
shipping_addresses: [
26-
{
27-
address: {
28-
firstname: "${addressDataFromCart.firstname}"
29-
lastname: "${addressDataFromCart.lastname}"
30-
street: "${addressDataFromCart.street}"
31-
city: "${addressDataFromCart.city}"
32-
region: "${addressDataFromCart.region.code}"
33-
country_code: "${countryCode}"
34-
telephone: "${addressDataFromCart.telephone}"
35-
postcode: "${addressDataFromCart.postcode}"
36-
save_in_address_book: false
37-
}
38-
}
39-
]
40-
}
41-
){
21+
return '
22+
setShippingAddressesOnCart(
23+
input: {
24+
cart_id: "${this.cartId}"
25+
shipping_addresses: [{
26+
address: {
27+
firstname: "${addressDataFromCart.firstname}"
28+
lastname: "${addressDataFromCart.lastname}"
29+
street: "${addressDataFromCart.street}"
30+
city: "${addressDataFromCart.city}"
31+
region: "${addressDataFromCart.region.code}"
32+
country_code: "${countryCode}"
33+
telephone: "${addressDataFromCart.telephone}"
34+
postcode: "${addressDataFromCart.postcode}"
35+
save_in_address_book: false
36+
}
37+
}]
38+
}
39+
) {
4240
cart {
4341
' . $this->graphQlQueries->getCartGraphQlQuery() . '
4442
}
45-
}';
43+
}
44+
';
4645
}
4746
}

0 commit comments

Comments
 (0)