Skip to content

Commit

Permalink
Merge pull request #4977 from magento-engcom/fix-nightly-fails-with-msi
Browse files Browse the repository at this point in the history
[EngCom][Combined] Inventory Stabilization + GraphQl + SSL MySql + DBC
  • Loading branch information
ishakhsuvarov authored Nov 6, 2019
2 parents 1ebd7cc + c0f9fb7 commit 0572853
Show file tree
Hide file tree
Showing 28 changed files with 704 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<severity value="CRITICAL"/>
<testCaseId value="MC-148"/>
<group value="CatalogRule"/>
<skip>
<issueId value="MC-22577"/>
</skip>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="login"/>
Expand Down Expand Up @@ -148,7 +151,7 @@
<argument name="attribute" value="{{productAttributeDropdownTwoOptions.attribute_code}}"/>
</actionGroup>
<actionGroup ref="SaveAttributeSet" stepKey="saveAttributeSet"/>

<!-- First Simple Product: choose green as attribute value -->
<actionGroup ref="filterAndSelectProduct" stepKey="openFirstSimpleProduct">
<argument name="productSku" value="$$createFirstProduct.sku$$"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\Data\RegionInterface;
use Magento\Customer\Api\Data\RegionInterfaceFactory;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Quote\Model\Quote\Address as QuoteAddress;
Expand Down Expand Up @@ -89,8 +90,15 @@ public function execute(QuoteAddress $quoteAddress, int $customerId): void
$customerAddress->setRegion($region);

$this->addressRepository->save($customerAddress);
} catch (LocalizedException $e) {
throw new GraphQlInputException(__($e->getMessage()), $e);
} catch (InputException $inputException) {
$graphQlInputException = new GraphQlInputException(__($inputException->getMessage()));
$errors = $inputException->getErrors();
foreach ($errors as $error) {
$graphQlInputException->addError(new GraphQlInputException(__($error->getMessage())));
}
throw $graphQlInputException;
} catch (LocalizedException $exception) {
throw new GraphQlInputException(__($exception->getMessage()), $exception);
}
}
}
48 changes: 46 additions & 2 deletions app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Quote\Model\Quote\Address as QuoteAddress;
use Magento\Quote\Model\Quote\AddressFactory as BaseQuoteAddressFactory;
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory as RegionCollectionFactory;
use Magento\Directory\Helper\Data as CountryHelper;
use Magento\Directory\Model\AllowedCountries;

/**
* Create QuoteAddress
Expand All @@ -36,36 +39,77 @@ class QuoteAddressFactory
*/
private $addressHelper;

/**
* @var RegionCollectionFactory
*/
private $regionCollectionFactory;

/**
* @var CountryHelper
*/
private $countryHelper;

/**
* @var AllowedCountries
*/
private $allowedCountries;

/**
* @param BaseQuoteAddressFactory $quoteAddressFactory
* @param GetCustomerAddress $getCustomerAddress
* @param AddressHelper $addressHelper
* @param RegionCollectionFactory $regionCollectionFactory
* @param CountryHelper $countryHelper
* @param AllowedCountries $allowedCountries
*/
public function __construct(
BaseQuoteAddressFactory $quoteAddressFactory,
GetCustomerAddress $getCustomerAddress,
AddressHelper $addressHelper
AddressHelper $addressHelper,
RegionCollectionFactory $regionCollectionFactory,
CountryHelper $countryHelper,
AllowedCountries $allowedCountries
) {
$this->quoteAddressFactory = $quoteAddressFactory;
$this->getCustomerAddress = $getCustomerAddress;
$this->addressHelper = $addressHelper;
$this->regionCollectionFactory = $regionCollectionFactory;
$this->countryHelper = $countryHelper;
$this->allowedCountries = $allowedCountries;
}

/**
* Create QuoteAddress based on input data
*
* @param array $addressInput
*
* @return QuoteAddress
* @throws GraphQlInputException
*/
public function createBasedOnInputData(array $addressInput): QuoteAddress
{
$addressInput['country_id'] = '';
if ($addressInput['country_code']) {
if (isset($addressInput['country_code']) && $addressInput['country_code']) {
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
$addressInput['country_id'] = $addressInput['country_code'];
}

$allowedCountries = $this->allowedCountries->getAllowedCountries();
if (!in_array($addressInput['country_code'], $allowedCountries, true)) {
throw new GraphQlInputException(__('Country is not available'));
}
$isRegionRequired = $this->countryHelper->isRegionRequired($addressInput['country_code']);
if ($isRegionRequired && !empty($addressInput['region'])) {
$regionCollection = $this->regionCollectionFactory
->create()
->addRegionCodeFilter($addressInput['region'])
->addCountryFilter($addressInput['country_code']);
if ($regionCollection->getSize() === 0) {
throw new GraphQlInputException(
__('Region is not available for the selected country')
);
}
}
$maxAllowedLineCount = $this->addressHelper->getStreetLines();
if (is_array($addressInput['street']) && count($addressInput['street']) > $maxAllowedLineCount) {
throw new GraphQlInputException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ private function createBillingAddress(
(int)$context->getUserId()
);
}
$errors = $billingAddress->validate();

if (true !== $errors) {
$e = new GraphQlInputException(__('Billing address errors'));
foreach ($errors as $error) {
$e->addError(new GraphQlInputException($error));
}
throw $e;
}

return $billingAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\GraphQl\Model\Query\ContextInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote\Address;

/**
* Set single shipping address for a specified shopping cart
Expand Down Expand Up @@ -52,6 +53,15 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s

$shippingAddress = $this->getShippingAddress->execute($context, $shippingAddressInput);

$errors = $shippingAddress->validate();

if (true !== $errors) {
$e = new GraphQlInputException(__('Shipping address errors'));
foreach ($errors as $error) {
$e->addError(new GraphQlInputException($error));
}
throw $e;
}
$this->assignShippingAddressToCart->execute($cart, $shippingAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<actionGroup ref="orderSelectFlatRateShipping" stepKey="orderSelectFlatRateShippingMethod"/>
<actionGroup ref="AdminSubmitOrderActionGroup" stepKey="submitOrder"/>
<actionGroup ref="verifyCreatedOrderInformation" stepKey="verifyCreatedOrderInformation"/>
<grabTextFrom selector="|Order # (\d+)|" stepKey="getOrderId"/>
<actionGroup ref="OpenOrderById" stepKey="openOrder">
<argument name="orderId" value="$getOrderId"/>
</actionGroup>
<click selector="{{AdminOrderDetailsMainActionsSection.ship}}" stepKey="clickShipAction"/>
<click selector="{{AdminShipmentMainActionsSection.submitShipment}}" stepKey="clickSubmitShipment"/>
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="frontendCustomerLogIn">
<argument name="Customer" value="$$simpleCustomer$$"/>
</actionGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<actionGroup ref="orderSelectFlatRateShipping" stepKey="orderSelectFlatRateShippingMethod"/>
<actionGroup ref="AdminSubmitOrderActionGroup" stepKey="submitOrder"/>
<actionGroup ref="verifyCreatedOrderInformation" stepKey="verifyCreatedOrderInformation"/>
<grabTextFrom selector="|Order # (\d+)|" stepKey="getOrderId"/>
<actionGroup ref="OpenOrderById" stepKey="openOrder">
<argument name="orderId" value="$getOrderId"/>
</actionGroup>
<click selector="{{AdminOrderDetailsMainActionsSection.ship}}" stepKey="clickShipAction"/>
<click selector="{{AdminShipmentMainActionsSection.submitShipment}}" stepKey="clickSubmitShipment"/>
<actionGroup ref="AssertAdminProductStockStatusActionGroup" stepKey="checkProductStockStatus">
<argument name="productId" value="$$simpleProduct.id$$"/>
<argument name="stockStatus" value="Out of Stock"/>
Expand Down
Loading

0 comments on commit 0572853

Please sign in to comment.