Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

#758: applied_taxes of empty cart causes 'Internal server error' message on PHP 7.2 #759

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function getAppliedTaxes(Total $total, string $currency): array
$appliedTaxesData = [];
$appliedTaxes = $total->getAppliedTaxes();

if (count($appliedTaxes) === 0) {
if (empty($appliedTaxes)) {
return $appliedTaxesData;
}

Expand Down
27 changes: 27 additions & 0 deletions dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ public function testGetCartTotalsWithTaxApplied()
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
*/
public function testGetCartTotalsWithEmptyCart()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId);
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('prices', $response['cart']);
$pricesResponse = $response['cart']['prices'];
self::assertEquals(0, $pricesResponse['grand_total']['value']);
self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']);
self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']);
self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);

$appliedTaxesResponse = $pricesResponse['applied_taxes'];

self::assertCount(0, $appliedTaxesResponse);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
Expand Down
26 changes: 26 additions & 0 deletions dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ public function testGetCartTotalsWithTaxApplied()
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
*/
public function testGetCartTotalsWithEmptyCart()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId);
$response = $this->graphQlQuery($query);

self::assertArrayHasKey('prices', $response['cart']);
$pricesResponse = $response['cart']['prices'];
self::assertEquals(0, $pricesResponse['grand_total']['value']);
self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']);
self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']);
self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);

$appliedTaxesResponse = $pricesResponse['applied_taxes'];

self::assertCount(0, $appliedTaxesResponse);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
Expand Down