Skip to content

Commit 382d41f

Browse files
committed
magento/graphql-ce#683: Add discount information to Cart
1 parent fe708a2 commit 382d41f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ private function getAppliedTaxes(Total $total, string $currency): array
9696
private function getDiscount(Total $total, string $currency)
9797
{
9898
return [
99-
'label' => $total->getDiscountDescription(),
100-
'amount' => ['value' => $total->getDiscountAmount(), "currency" => $currency]
99+
'label' => explode(', ', $total->getDiscountDescription()),
100+
'amount' => ['value' => $total->getDiscountAmount(), 'currency' => $currency]
101101
];
102102
}
103103
}

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ type CartPrices {
142142
grand_total: Money
143143
subtotal_including_tax: Money
144144
subtotal_excluding_tax: Money
145-
discount: CartDiscountItem
145+
discount: CartDiscount
146146
subtotal_with_discount_excluding_tax: Money
147147
applied_taxes: [CartTaxItem]
148148
}
@@ -152,9 +152,9 @@ type CartTaxItem {
152152
label: String!
153153
}
154154

155-
type CartDiscountItem {
155+
type CartDiscount {
156156
amount: Money!
157-
label: String!
157+
label: [String!]!
158158
}
159159

160160
type SetPaymentMethodOnCartOutput {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testGetDiscountInformation()
168168

169169
$discountResponse = $response['cart']['prices']['discount'];
170170
self::assertEquals(-10, $discountResponse['amount']['value']);
171-
self::assertEquals('50% Off for all orders', $discountResponse['label']);
171+
self::assertEquals(['50% Off for all orders'], $discountResponse['label']);
172172
}
173173

174174
/**
@@ -188,7 +188,7 @@ public function testGetDiscountInformationWithTwoRulesApplied()
188188

189189
$discountResponse = $response['cart']['prices']['discount'];
190190
self::assertEquals(-11, $discountResponse['amount']['value']);
191-
self::assertEquals('50% Off for all orders, Test Coupon for General', $discountResponse['label']);
191+
self::assertEquals(['50% Off for all orders', 'Test Coupon for General'], $discountResponse['label']);
192192
}
193193

194194
/**

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testGetDiscountInformation()
138138

139139
$discountResponse = $response['cart']['prices']['discount'];
140140
self::assertEquals(-10, $discountResponse['amount']['value']);
141-
self::assertEquals('50% Off for all orders', $discountResponse['label']);
141+
self::assertEquals(['50% Off for all orders'], $discountResponse['label']);
142142
}
143143

144144
/**
@@ -157,7 +157,7 @@ public function testGetDiscountInformationWithTwoRulesApplied()
157157

158158
$discountResponse = $response['cart']['prices']['discount'];
159159
self::assertEquals(-15, $discountResponse['amount']['value']);
160-
self::assertEquals('50% Off for all orders, 5$ fixed discount on whole cart', $discountResponse['label']);
160+
self::assertEquals(['50% Off for all orders', '5$ fixed discount on whole cart'], $discountResponse['label']);
161161
}
162162

163163
/**

0 commit comments

Comments
 (0)