Skip to content

Commit

Permalink
Cannot return null for non-nullable field SelectedCustomizableOptionV…
Browse files Browse the repository at this point in the history
…alue.sort_order and Call to a member function getPriceType() on null
  • Loading branch information
XxXgeoXxX authored and naydav committed Apr 30, 2019
1 parent 81daba8 commit 742e6a7
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Quote\Model\Quote;
use phpDocumentor\Reflection\Types\Mixed_;

/**
* Add simple product to cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,89 @@ public function testAddProductIfQuantityIsNotAvailable()
$this->graphQlMutation($query);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
* @expectedException \Exception
* @expectedExceptionMessage The product's required option(s) weren't entered. Make sure the options are entered and try again.
*/
public function testAddProductWithoutRequiredCustomOPtions()
{
$sku = 'simple_with_custom_options';
$qty = 1;

$maskedQuoteId = $this->getMaskedQuoteId();
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
*/
public function testAddProductWithRequiredCustomOPtions()
{
$sku = 'simple_with_custom_options';
$qty = 1;
$productCustomOptions = Bootstrap::getObjectManager()
->get(\Magento\Catalog\Api\ProductCustomOptionRepositoryInterface::class)
->getList($sku);
$customizableOptions = '';
foreach ($productCustomOptions as $option) {
$value = $option->getValues() ?
'[' . key($option->getValues()) . ']' :
'Test';
$customizableOptions .= ' {
id: ' . $option->getId() . '
value: "' . $value . '"
}';
}

$maskedQuoteId = $this->getMaskedQuoteId();
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "{$maskedQuoteId}"
cartItems: {
data: {
qty: {$qty}
sku: "{$sku}"
}
customizable_options: [
{$customizableOptions}
]
}
}
)
{
cart {
items {
product {
sku
}
... on SimpleCartItem {
customizable_options {
id
is_required
sort_order
}
}
}
}
}
}
QUERY;
$response = $this->graphQlQuery($query);
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);

self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
self::assertEquals(
1,
$response['addSimpleProductsToCart']['cart']['items'][0]['customizable_options'][0]['is_required']
);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
Expand Down

0 comments on commit 742e6a7

Please sign in to comment.