Skip to content

Commit

Permalink
magento/graphql-ce#683: Add discount information to Cart
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaorobei committed Jun 11, 2019
1 parent fe708a2 commit 382d41f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ private function getAppliedTaxes(Total $total, string $currency): array
private function getDiscount(Total $total, string $currency)
{
return [
'label' => $total->getDiscountDescription(),
'amount' => ['value' => $total->getDiscountAmount(), "currency" => $currency]
'label' => explode(', ', $total->getDiscountDescription()),
'amount' => ['value' => $total->getDiscountAmount(), 'currency' => $currency]
];
}
}
6 changes: 3 additions & 3 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type CartPrices {
grand_total: Money
subtotal_including_tax: Money
subtotal_excluding_tax: Money
discount: CartDiscountItem
discount: CartDiscount
subtotal_with_discount_excluding_tax: Money
applied_taxes: [CartTaxItem]
}
Expand All @@ -152,9 +152,9 @@ type CartTaxItem {
label: String!
}

type CartDiscountItem {
type CartDiscount {
amount: Money!
label: String!
label: [String!]!
}

type SetPaymentMethodOnCartOutput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function testGetDiscountInformation()

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

/**
Expand All @@ -188,7 +188,7 @@ public function testGetDiscountInformationWithTwoRulesApplied()

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testGetDiscountInformation()

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

/**
Expand All @@ -157,7 +157,7 @@ public function testGetDiscountInformationWithTwoRulesApplied()

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

/**
Expand Down

0 comments on commit 382d41f

Please sign in to comment.