Skip to content

Commit cba40fa

Browse files
committed
MAGETWO-91678: Minimum Order amount required in Admin orders
1 parent c7bd909 commit cba40fa

File tree

2 files changed

+179
-5
lines changed

2 files changed

+179
-5
lines changed

app/code/Magento/Quote/etc/di.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,23 @@
9999
<type name="Magento\Quote\Model\ValidationRules\QuoteValidationComposite">
100100
<arguments>
101101
<argument name="validationRules" xsi:type="array">
102-
<item name="ShippingAddressValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\ShippingAddressValidationRule</item>
103102
<item name="AllowedCountryValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\AllowedCountryValidationRule</item>
103+
<item name="ShippingAddressValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\ShippingAddressValidationRule</item>
104104
<item name="ShippingMethodValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\ShippingMethodValidationRule</item>
105105
<item name="BillingAddressValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\BillingAddressValidationRule</item>
106106
<item name="PaymentMethodValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\PaymentMethodValidationRule</item>
107107
<item name="MinimumAmountValidationRule" xsi:type="object">Magento\Quote\Model\ValidationRules\MinimumAmountValidationRule</item>
108108
</argument>
109109
</arguments>
110110
</type>
111-
<type name="Magento\Quote\Model\ValidationRules\ShippingAddressValidationRule">
111+
<type name="Magento\Quote\Model\ValidationRules\AllowedCountryValidationRule">
112112
<arguments>
113-
<argument name="defaultMessage" xsi:type="string">Please check the shipping address information.</argument>
113+
<argument name="defaultMessage" xsi:type="string">Some addresses can't be used due to the configurations for specific countries.</argument>
114114
</arguments>
115115
</type>
116-
<type name="Magento\Quote\Model\ValidationRules\AllowedCountryValidationRule">
116+
<type name="Magento\Quote\Model\ValidationRules\ShippingAddressValidationRule">
117117
<arguments>
118-
<argument name="defaultMessage" xsi:type="string">Some addresses can't be used due to the configurations for specific countries.</argument>
118+
<argument name="defaultMessage" xsi:type="string">Please check the shipping address information.</argument>
119119
</arguments>
120120
</type>
121121
<type name="Magento\Quote\Model\ValidationRules\ShippingMethodValidationRule">
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Quote\Model;
8+
9+
use Magento\Quote\Api\Data\AddressInterface;
10+
use Magento\Quote\Model\Quote\Address\Rate;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/**
14+
* Class QuoteValidatorTest
15+
*
16+
* @magentoDbIsolation enabled
17+
*/
18+
class QuoteValidatorTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var QuoteValidator
22+
*/
23+
private $quoteValidator;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function setUp()
29+
{
30+
$this->quoteValidator = Bootstrap::getObjectManager()->create(QuoteValidator::class);
31+
}
32+
33+
/**
34+
* @expectedException \Magento\Framework\Exception\LocalizedException
35+
* @expectedExceptionMessage Please check the shipping address information.
36+
*/
37+
public function testValidateBeforeSubmitShippingAddressInvalid()
38+
{
39+
$quote = $this->getQuote();
40+
$quote->getShippingAddress()->setPostcode('');
41+
42+
$this->quoteValidator->validateBeforeSubmit($quote);
43+
}
44+
45+
/**
46+
* @expectedException \Magento\Framework\Exception\LocalizedException
47+
* @expectedExceptionMessage Some addresses can't be used due to the configurations for specific countries.
48+
*/
49+
public function testValidateBeforeSubmitCountryIsNotAllowed()
50+
{
51+
/** @magentoConfigFixture does not allow to change the value for the website scope */
52+
Bootstrap::getObjectManager()->get(
53+
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
54+
)->setValue(
55+
'general/country/allow',
56+
'US',
57+
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES
58+
);
59+
$quote = $this->getQuote();
60+
$quote->getShippingAddress()->setCountryId('AF');
61+
62+
$this->quoteValidator->validateBeforeSubmit($quote);
63+
}
64+
65+
/**
66+
* @expectedException \Magento\Framework\Exception\LocalizedException
67+
* @expectedExceptionMessage The shipping method is missing. Select the shipping method and try again.
68+
*/
69+
public function testValidateBeforeSubmitShippingMethodInvalid()
70+
{
71+
$quote = $this->getQuote();
72+
$quote->getShippingAddress()->setShippingMethod('NONE');
73+
74+
$this->quoteValidator->validateBeforeSubmit($quote);
75+
}
76+
77+
/**
78+
* @expectedException \Magento\Framework\Exception\LocalizedException
79+
* @expectedExceptionMessage Please check the billing address information.
80+
*/
81+
public function testValidateBeforeSubmitBillingAddressInvalid()
82+
{
83+
$quote = $this->getQuote();
84+
$quote->getBillingAddress()->setTelephone('');
85+
86+
$this->quoteValidator->validateBeforeSubmit($quote);
87+
}
88+
89+
/**
90+
* @expectedException \Magento\Framework\Exception\LocalizedException
91+
* @expectedExceptionMessage Enter a valid payment method and try again.
92+
*/
93+
public function testValidateBeforeSubmitPaymentMethodInvalid()
94+
{
95+
$quote = $this->getQuote();
96+
$quote->getPayment()->setMethod('');
97+
98+
$this->quoteValidator->validateBeforeSubmit($quote);
99+
}
100+
101+
/**
102+
* @expectedException \Magento\Framework\Exception\LocalizedException
103+
* @magentoConfigFixture current_store sales/minimum_order/active 1
104+
* @magentoConfigFixture current_store sales/minimum_order/amount 100
105+
*/
106+
public function testValidateBeforeSubmitMinimumAmountInvalid()
107+
{
108+
$quote = $this->getQuote();
109+
110+
$this->quoteValidator->validateBeforeSubmit($quote);
111+
}
112+
113+
/**
114+
* @return void
115+
*/
116+
public function testValidateBeforeSubmitWithoutMinimumOrderAmount()
117+
{
118+
$this->quoteValidator->validateBeforeSubmit($this->getQuote());
119+
}
120+
121+
/**
122+
* @return Quote
123+
*/
124+
private function getQuote(): Quote
125+
{
126+
/** @var Quote $quote */
127+
$quote = Bootstrap::getObjectManager()->create(Quote::class);
128+
129+
/** @var AddressInterface $billingAddress */
130+
$billingAddress = Bootstrap::getObjectManager()->create(AddressInterface::class);
131+
$billingAddress->setFirstname('Joe')
132+
->setLastname('Doe')
133+
->setCountryId('US')
134+
->setRegion('TX')
135+
->setCity('Austin')
136+
->setStreet('1000 West Parmer Line')
137+
->setPostcode('11501')
138+
->setTelephone('123456789');
139+
$quote->setBillingAddress($billingAddress);
140+
141+
/** @var AddressInterface $shippingAddress */
142+
$shippingAddress = Bootstrap::getObjectManager()->create(AddressInterface::class);
143+
$shippingAddress->setFirstname('Joe')
144+
->setLastname('Doe')
145+
->setCountryId('US')
146+
->setRegion('TX')
147+
->setCity('Austin')
148+
->setStreet('1000 West Parmer Line')
149+
->setPostcode('11501')
150+
->setTelephone('123456789');
151+
$quote->setShippingAddress($shippingAddress);
152+
153+
$quote->getShippingAddress()
154+
->setShippingMethod('flatrate_flatrate')
155+
->setCollectShippingRates(true);
156+
/** @var Rate $shippingRate */
157+
$shippingRate = Bootstrap::getObjectManager()->create(Rate::class);
158+
$shippingRate->setMethod('flatrate')
159+
->setCarrier('flatrate')
160+
->setPrice('5')
161+
->setCarrierTitle('Flat Rate')
162+
->setCode('flatrate_flatrate');
163+
$quote->getShippingAddress()
164+
->addShippingRate($shippingRate);
165+
166+
$quote->getPayment()->setMethod('CC');
167+
168+
/** @var QuoteRepository $quoteRepository */
169+
$quoteRepository = Bootstrap::getObjectManager()->create(QuoteRepository::class);
170+
$quoteRepository->save($quote);
171+
172+
return $quote;
173+
}
174+
}

0 commit comments

Comments
 (0)