diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml
index 0206c18b819c2..cbe71e9cffa60 100644
--- a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml
+++ b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml
@@ -54,5 +54,6 @@
+
diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontCheckoutPaymentMethodSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontCheckoutPaymentMethodSection.xml
index 55c4385706ba9..9d9a96d2ea5e6 100644
--- a/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontCheckoutPaymentMethodSection.xml
+++ b/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontCheckoutPaymentMethodSection.xml
@@ -12,5 +12,6 @@
+
diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/DefaultBillingAddressShouldBeCheckedOnPaymentPageTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/DefaultBillingAddressShouldBeCheckedOnPaymentPageTest.xml
new file mode 100644
index 0000000000000..166f5022d5aeb
--- /dev/null
+++ b/app/code/Magento/Checkout/Test/Mftf/Test/DefaultBillingAddressShouldBeCheckedOnPaymentPageTest.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerCheckoutTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerCheckoutTest.xml
index e7c2ad3dd28a4..fadc9ec50ad8d 100644
--- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerCheckoutTest.xml
+++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerCheckoutTest.xml
@@ -186,20 +186,20 @@
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
@@ -216,16 +216,18 @@
-
-
+
+
+
-
-
-
+
+
+
+
@@ -253,16 +255,18 @@
-
-
-
-
-
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerPlaceOrderWithNewAddressesThatWasEditedTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerPlaceOrderWithNewAddressesThatWasEditedTest.xml
index 8537e10ce5a03..651c5bd8d4375 100644
--- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerPlaceOrderWithNewAddressesThatWasEditedTest.xml
+++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerPlaceOrderWithNewAddressesThatWasEditedTest.xml
@@ -71,6 +71,7 @@
+
@@ -89,7 +90,7 @@
-
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js b/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js
index 9cc60a3645d58..e54f464f24d02 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js
@@ -243,7 +243,7 @@ define([
return;
}
- if (quote.isVirtual()) {
+ if (quote.isVirtual() || !quote.billingAddress()) {
isBillingAddressInitialized = addressList.some(function (addrs) {
if (addrs.isDefaultBilling()) {
selectBillingAddress(addrs);
diff --git a/app/code/Magento/Persistent/Model/QuoteManager.php b/app/code/Magento/Persistent/Model/QuoteManager.php
index 35c2c70be30dc..8ae22e4c26c6f 100644
--- a/app/code/Magento/Persistent/Model/QuoteManager.php
+++ b/app/code/Magento/Persistent/Model/QuoteManager.php
@@ -7,6 +7,8 @@
/**
* Class QuoteManager
+ *
+ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class QuoteManager
{
@@ -87,6 +89,7 @@ public function setGuest($checkQuote = false)
->setCustomerLastname(null)
->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)
->setIsPersistent(false)
+ ->setCustomerIsGuest(true)
->removeAllAddresses();
//Create guest addresses
$quote->getShippingAddress();
diff --git a/app/code/Magento/Persistent/Observer/CheckExpirePersistentQuoteObserver.php b/app/code/Magento/Persistent/Observer/CheckExpirePersistentQuoteObserver.php
index f3720960ca6e5..79fdf44c3c551 100644
--- a/app/code/Magento/Persistent/Observer/CheckExpirePersistentQuoteObserver.php
+++ b/app/code/Magento/Persistent/Observer/CheckExpirePersistentQuoteObserver.php
@@ -1,6 +1,5 @@
_persistentSession->isPersistent() &&
!$this->_customerSession->isLoggedIn() &&
$this->_checkoutSession->getQuoteId() &&
- !$this->isRequestFromCheckoutPage($this->request)
+ !$this->isRequestFromCheckoutPage($this->request) &&
// persistent session does not expire on onepage checkout page
+ (
+ $this->_checkoutSession->getQuote()->getIsPersistent() ||
+ $this->_checkoutSession->getQuote()->getCustomerIsGuest()
+ )
) {
$this->_eventManager->dispatch('persistent_session_expired');
$this->quoteManager->expire();
diff --git a/app/code/Magento/Persistent/Observer/SetQuotePersistentDataObserver.php b/app/code/Magento/Persistent/Observer/SetQuotePersistentDataObserver.php
index db6b6d1ee370d..2803bc998dcbe 100644
--- a/app/code/Magento/Persistent/Observer/SetQuotePersistentDataObserver.php
+++ b/app/code/Magento/Persistent/Observer/SetQuotePersistentDataObserver.php
@@ -1,6 +1,5 @@
_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn())
- && !$this->_persistentData->isShoppingCartPersist()
+ ($this->_persistentSession->isPersistent())
+ && $this->_persistentData->isShoppingCartPersist()
)
&& $this->quoteManager->isPersistent()
) {
diff --git a/app/code/Magento/Persistent/Test/Mftf/Test/ShippingQuotePersistedForGuestTest.xml b/app/code/Magento/Persistent/Test/Mftf/Test/ShippingQuotePersistedForGuestTest.xml
new file mode 100644
index 0000000000000..e5c77ee414362
--- /dev/null
+++ b/app/code/Magento/Persistent/Test/Mftf/Test/ShippingQuotePersistedForGuestTest.xml
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 150
+
+
+
+ John1
+ Doe1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{US_Address_CA.postcode}}
+ grabTextPostCode
+
+
+
diff --git a/app/code/Magento/Persistent/Test/Unit/Observer/CheckExpirePersistentQuoteObserverTest.php b/app/code/Magento/Persistent/Test/Unit/Observer/CheckExpirePersistentQuoteObserverTest.php
index 46dda1be365d4..b096dd2317a33 100644
--- a/app/code/Magento/Persistent/Test/Unit/Observer/CheckExpirePersistentQuoteObserverTest.php
+++ b/app/code/Magento/Persistent/Test/Unit/Observer/CheckExpirePersistentQuoteObserverTest.php
@@ -1,12 +1,16 @@
checkoutSessionMock,
$this->requestMock
);
+ $this->quoteMock = $this->getMockBuilder(Quote::class)
+ ->setMethods(['getCustomerIsGuest', 'getIsPersistent'])
+ ->disableOriginalConstructor()
+ ->getMock();
}
public function testExecuteWhenCanNotApplyPersistentData()
@@ -133,6 +146,11 @@ public function testExecuteWhenPersistentIsEnabled(
->willReturn(true);
$this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn(true);
$this->sessionMock->expects($this->once())->method('isPersistent')->willReturn(false);
+ $this->checkoutSessionMock
+ ->method('getQuote')
+ ->willReturn($this->quoteMock);
+ $this->quoteMock->method('getCustomerIsGuest')->willReturn(true);
+ $this->quoteMock->method('getIsPersistent')->willReturn(true);
$this->customerSessionMock
->expects($this->atLeastOnce())
->method('isLoggedIn')
diff --git a/app/code/Magento/Persistent/Test/Unit/Observer/SetQuotePersistentDataObserverTest.php b/app/code/Magento/Persistent/Test/Unit/Observer/SetQuotePersistentDataObserverTest.php
index 6724743789cea..ffa829e8456cc 100644
--- a/app/code/Magento/Persistent/Test/Unit/Observer/SetQuotePersistentDataObserverTest.php
+++ b/app/code/Magento/Persistent/Test/Unit/Observer/SetQuotePersistentDataObserverTest.php
@@ -7,6 +7,9 @@
namespace Magento\Persistent\Test\Unit\Observer;
+/**
+ * Observer test for setting "is_persistent" value to quote
+ */
class SetQuotePersistentDataObserverTest extends \PHPUnit\Framework\TestCase
{
/**
@@ -83,7 +86,6 @@ public function testExecuteWhenQuoteNotExist()
->method('getEvent')
->will($this->returnValue($this->eventManagerMock));
$this->eventManagerMock->expects($this->once())->method('getQuote');
- $this->customerSessionMock->expects($this->never())->method('isLoggedIn');
$this->model->execute($this->observerMock);
}
@@ -98,8 +100,7 @@ public function testExecuteWhenSessionIsPersistent()
->expects($this->once())
->method('getQuote')
->will($this->returnValue($this->quoteMock));
- $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
- $this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(false));
+ $this->helperMock->expects($this->once())->method('isShoppingCartPersist')->will($this->returnValue(true));
$this->quoteManagerMock->expects($this->once())->method('isPersistent')->will($this->returnValue(true));
$this->quoteMock->expects($this->once())->method('setIsPersistent')->with(true);
$this->model->execute($this->observerMock);
diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php
index bff489ee50c2f..77b3cfa3a08bb 100644
--- a/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php
+++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php
@@ -348,7 +348,7 @@ public function mapItems(
$useBaseCurrency
) {
$items = $shippingAssignment->getItems();
- if (!count($items)) {
+ if (empty($items)) {
return [];
}
@@ -478,7 +478,7 @@ protected function prepareQuoteDetails(ShippingAssignmentInterface $shippingAssi
{
$items = $shippingAssignment->getItems();
$address = $shippingAssignment->getShipping()->getAddress();
- if (!count($items)) {
+ if (empty($items)) {
return $this->quoteDetailsDataObjectFactory->create();
}
@@ -688,6 +688,9 @@ public function updateItemTaxInfo($quoteItem, $itemTaxDetails, $baseItemTaxDetai
{
//The price should be base price
$quoteItem->setPrice($baseItemTaxDetails->getPrice());
+ if ($quoteItem->getCustomPrice() && $this->taxHelper->applyTaxOnCustomPrice()) {
+ $quoteItem->setCustomPrice($baseItemTaxDetails->getPrice());
+ }
$quoteItem->setConvertedPrice($itemTaxDetails->getPrice());
$quoteItem->setPriceInclTax($itemTaxDetails->getPriceInclTax());
$quoteItem->setRowTotal($itemTaxDetails->getRowTotal());
diff --git a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php
index 9325ec10dc627..50d45ad662bd4 100644
--- a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php
+++ b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php
@@ -3,79 +3,106 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
namespace Magento\Tax\Test\Unit\Model\Sales\Total\Quote;
-/**
- * Test class for \Magento\Tax\Model\Sales\Total\Quote\Tax
- */
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
+use Magento\Tax\Helper\Data as TaxHelper;
+use Magento\Tax\Api\Data\TaxDetailsItemInterface;
+use Magento\Quote\Model\Quote\Item as QuoteItem;
+use Magento\Store\Model\Store;
+use Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector;
+use Magento\Tax\Model\Config;
+use Magento\Quote\Model\Quote\Address as QuoteAddress;
+use Magento\Quote\Model\Quote;
+use Magento\Tax\Api\Data\QuoteDetailsItemInterface;
+use Magento\Tax\Api\Data\TaxClassKeyInterface;
+use Magento\Tax\Model\Sales\Quote\ItemDetails;
+use Magento\Tax\Model\TaxClass\Key as TaxClassKey;
+use Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory;
+use Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory;
+use Magento\Quote\Api\Data\ShippingAssignmentInterface;
+use Magento\Quote\Api\Data\ShippingInterface;
+use Magento\Quote\Model\Quote\Address\Total as QuoteAddressTotal;
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
/**
+ * Common tax collector test
+ *
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
-class CommonTaxCollectorTest extends \PHPUnit\Framework\TestCase
+class CommonTaxCollectorTest extends TestCase
{
/**
- * @var \Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector
+ * @var CommonTaxCollector
*/
private $commonTaxCollector;
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Tax\Model\Config
+ * @var MockObject|Config
*/
private $taxConfig;
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote\Address
+ * @var MockObject|QuoteAddress
*/
private $address;
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote
+ * @var MockObject|Quote
*/
private $quote;
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
+ * @var MockObject|Store
*/
private $store;
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|
+ * @var MockObject
*/
protected $taxClassKeyDataObjectFactoryMock;
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|
+ * @var MockObject
*/
protected $quoteDetailsItemDataObjectFactoryMock;
/**
- * @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface
+ * @var QuoteDetailsItemInterface
*/
protected $quoteDetailsItemDataObject;
/**
- * @var \Magento\Tax\Api\Data\TaxClassKeyInterface
+ * @var TaxClassKeyInterface
*/
protected $taxClassKeyDataObject;
+ /**
+ * @var TaxHelper
+ */
+ private $taxHelper;
+
+ /**
+ * {@inheritdoc}
+ */
protected function setUp()
{
$objectManager = new ObjectManager($this);
- $this->taxConfig = $this->getMockBuilder(\Magento\Tax\Model\Config::class)
+ $this->taxConfig = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
- ->setMethods(['getShippingTaxClass', 'shippingPriceIncludesTax'])
+ ->setMethods(['getShippingTaxClass', 'shippingPriceIncludesTax', 'discountTax'])
->getMock();
- $this->store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
+ $this->store = $this->getMockBuilder(Store::class)
->disableOriginalConstructor()
->setMethods(['__wakeup'])
->getMock();
- $this->quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
+ $this->quote = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->setMethods(['__wakeup', 'getStore'])
->getMock();
@@ -84,7 +111,7 @@ protected function setUp()
->method('getStore')
->will($this->returnValue($this->store));
- $this->address = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address::class)
+ $this->address = $this->getMockBuilder(QuoteAddress::class)
->disableOriginalConstructor()
->getMock();
@@ -92,35 +119,41 @@ protected function setUp()
->method('getQuote')
->will($this->returnValue($this->quote));
$methods = ['create'];
- $this->quoteDetailsItemDataObject = $objectManager->getObject(
- \Magento\Tax\Model\Sales\Quote\ItemDetails::class
- );
- $this->taxClassKeyDataObject = $objectManager->getObject(\Magento\Tax\Model\TaxClass\Key::class);
+ $this->quoteDetailsItemDataObject = $objectManager->getObject(ItemDetails::class);
+ $this->taxClassKeyDataObject = $objectManager->getObject(TaxClassKey::class);
$this->quoteDetailsItemDataObjectFactoryMock
- = $this->createPartialMock(\Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory::class, $methods);
+ = $this->createPartialMock(QuoteDetailsItemInterfaceFactory::class, $methods);
$this->quoteDetailsItemDataObjectFactoryMock->expects($this->any())
->method('create')
->willReturn($this->quoteDetailsItemDataObject);
$this->taxClassKeyDataObjectFactoryMock =
- $this->createPartialMock(\Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory::class, $methods);
+ $this->createPartialMock(TaxClassKeyInterfaceFactory::class, $methods);
$this->taxClassKeyDataObjectFactoryMock->expects($this->any())
->method('create')
->willReturn($this->taxClassKeyDataObject);
+ $this->taxHelper = $this->getMockBuilder(TaxHelper::class)
+ ->disableOriginalConstructor()
+ ->getMock();
$this->commonTaxCollector = $objectManager->getObject(
- \Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector::class,
+ CommonTaxCollector::class,
[
'taxConfig' => $this->taxConfig,
'quoteDetailsItemDataObjectFactory' => $this->quoteDetailsItemDataObjectFactoryMock,
- 'taxClassKeyDataObjectFactory' => $this->taxClassKeyDataObjectFactoryMock
+ 'taxClassKeyDataObjectFactory' => $this->taxClassKeyDataObjectFactoryMock,
+ 'taxHelper' => $this->taxHelper,
]
);
}
/**
+ * Test for GetShippingDataObject
+ *
* @param array $addressData
* @param bool $useBaseCurrency
* @param string $shippingTaxClass
* @param bool $shippingPriceInclTax
+ *
+ * @return void
* @dataProvider getShippingDataObjectDataProvider
*/
public function testGetShippingDataObject(
@@ -128,8 +161,8 @@ public function testGetShippingDataObject(
$useBaseCurrency,
$shippingTaxClass,
$shippingPriceInclTax
- ) {
- $shippingAssignmentMock = $this->createMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class);
+ ): void {
+ $shippingAssignmentMock = $this->createMock(ShippingAssignmentInterface::class);
$methods = [
'getShippingDiscountAmount',
'getShippingTaxCalculationAmount',
@@ -139,8 +172,10 @@ public function testGetShippingDataObject(
'getBaseShippingAmount',
'getBaseShippingDiscountAmount'
];
- $totalsMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address\Total::class, $methods);
- $shippingMock = $this->createMock(\Magento\Quote\Api\Data\ShippingInterface::class);
+ /** @var MockObject|QuoteAddressTotal $totalsMock */
+ $totalsMock = $this->createPartialMock(QuoteAddressTotal::class, $methods);
+ $shippingMock = $this->createMock(ShippingInterface::class);
+ /** @var MockObject|ShippingAssignmentInterface $shippingAssignmentMock */
$shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
$shippingMock->expects($this->once())->method('getAddress')->willReturn($this->address);
$baseShippingAmount = $addressData['base_shipping_amount'];
@@ -184,9 +219,44 @@ public function testGetShippingDataObject(
}
/**
+ * Update item tax info
+ *
+ * @return void
+ */
+ public function testUpdateItemTaxInfo(): void
+ {
+ /** @var MockObject|QuoteItem $quoteItem */
+ $quoteItem = $this->getMockBuilder(QuoteItem::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getPrice', 'setPrice', 'getCustomPrice', 'setCustomPrice'])
+ ->getMock();
+ $this->taxHelper->method('applyTaxOnCustomPrice')->willReturn(true);
+ $quoteItem->method('getCustomPrice')->willReturn(true);
+ /** @var MockObject|TaxDetailsItemInterface $itemTaxDetails */
+ $itemTaxDetails = $this->getMockBuilder(TaxDetailsItemInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ /** @var MockObject|TaxDetailsItemInterface $baseItemTaxDetails */
+ $baseItemTaxDetails = $this->getMockBuilder(TaxDetailsItemInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $quoteItem->expects($this->once())->method('setCustomPrice');
+
+ $this->commonTaxCollector->updateItemTaxInfo(
+ $quoteItem,
+ $itemTaxDetails,
+ $baseItemTaxDetails,
+ $this->store
+ );
+ }
+
+ /**
+ * Data for testGetShippingDataObject
+ *
* @return array
*/
- public function getShippingDataObjectDataProvider()
+ public function getShippingDataObjectDataProvider(): array
{
$data = [
'free_shipping' => [
diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml
index 0edd8f4183f30..daf9aaae50580 100644
--- a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml
+++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml
@@ -15,13 +15,11 @@
- 1
-
- - 1
-
- 565.00
Flat Rate
+
false
Fixed
checkmo
checkmo
@@ -43,6 +41,7 @@
- 565.00
Flat Rate
+
false
Fixed
checkmo
checkmo
@@ -61,7 +60,7 @@
UK_address_without_email
Flat Rate
Fixed
-
Yes
+
false
US_address_1_without_email
checkmo
checkmo
diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillBillingInformationStep.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillBillingInformationStep.php
index aa7eba634145f..52b296c2e01fa 100644
--- a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillBillingInformationStep.php
+++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillBillingInformationStep.php
@@ -126,11 +126,15 @@ public function run()
if ($this->billingCheckboxState) {
$this->assertBillingAddressCheckbox->processAssert($this->checkoutOnepage, $this->billingCheckboxState);
}
- if ($this->billingCheckboxState === 'Yes' && !$this->editBillingInformation) {
- return [
- 'billingAddress' => $this->shippingAddress
- ];
+
+ if (!$this->editBillingInformation) {
+ $billingAddress = $this->billingCheckboxState === 'Yes'
+ ? $this->shippingAddress
+ : $this->getDefaultBillingAddress();
+
+ return ['billingAddress' => $billingAddress];
}
+
if ($this->billingAddress) {
$selectedPaymentMethod = $this->checkoutOnepage->getPaymentBlock()->getSelectedPaymentMethodBlock();
if ($this->shippingAddress) {
@@ -139,9 +143,11 @@ public function run()
$selectedPaymentMethod->getBillingBlock()->fillBilling($this->billingAddress);
$billingAddress = $this->billingAddress;
}
+
if (isset($this->billingAddressCustomer['added'])) {
$addressIndex = $this->billingAddressCustomer['added'];
- $billingAddress = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[$addressIndex];
+ $billingAddress = $this->customer->getDataFieldConfig('address')['source']
+ ->getAddresses()[$addressIndex];
$address = $this->objectManager->create(
\Magento\Customer\Test\Block\Address\Renderer::class,
['address' => $billingAddress, 'type' => 'html_for_select_element']
@@ -156,4 +162,25 @@ public function run()
'billingAddress' => $billingAddress
];
}
+
+ /**
+ * Get default billing address
+ *
+ * @return Address|null
+ */
+ private function getDefaultBillingAddress()
+ {
+ $addresses = $this->customer->hasData('address')
+ ? $this->customer->getDataFieldConfig('address')['source']->getAddresses()
+ : [];
+ $defaultAddress = null;
+ foreach ($addresses as $address) {
+ if ($address->getDefaultBilling() === 'Yes') {
+ $defaultAddress = $address;
+ break;
+ }
+ }
+
+ return $defaultAddress;
+ }
}
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/PriceTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/PriceTest.php
index 2a68ff48e5f9a..4a5757aae3134 100644
--- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/PriceTest.php
+++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/PriceTest.php
@@ -6,7 +6,7 @@
namespace Magento\Bundle\Model\Product;
/**
- * @magentoDataFixture Magento/Bundle/_files/product_with_tier_pricing.php
+ * Class to test bundle prices
*/
class PriceTest extends \PHPUnit\Framework\TestCase
{
@@ -22,6 +22,9 @@ protected function setUp()
);
}
+ /**
+ * @magentoDataFixture Magento/Bundle/_files/product_with_tier_pricing.php
+ */
public function testGetTierPrice()
{
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
@@ -37,4 +40,50 @@ public function testGetTierPrice()
$this->assertEquals(20.0, $this->_model->getTierPrice(4, $product));
$this->assertEquals(30.0, $this->_model->getTierPrice(5, $product));
}
+
+ /**
+ * Test calculation final price for bundle product with tire price in simple product
+ *
+ * @param float $bundleQty
+ * @param float $selectionQty
+ * @param float $finalPrice
+ * @magentoDataFixture Magento/Bundle/_files/product_with_simple_tier_pricing.php
+ * @dataProvider getSelectionFinalTotalPriceWithSimpleTierPriceDataProvider
+ */
+ public function testGetSelectionFinalTotalPriceWithSimpleTierPrice(
+ float $bundleQty,
+ float $selectionQty,
+ float $finalPrice
+ ) {
+ /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
+ $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
+ ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
+ $bundleProduct = $productRepository->get('bundle-product');
+ $simpleProduct = $productRepository->get('simple');
+ $simpleProduct->setCustomerGroupId(\Magento\Customer\Model\Group::CUST_GROUP_ALL);
+
+ $this->assertEquals(
+ $finalPrice,
+ $this->_model->getSelectionFinalTotalPrice(
+ $bundleProduct,
+ $simpleProduct,
+ $bundleQty,
+ $selectionQty,
+ false
+ ),
+ 'Tier price calculation for Simple product is wrong'
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function getSelectionFinalTotalPriceWithSimpleTierPriceDataProvider(): array
+ {
+ return [
+ [1, 1, 10],
+ [2, 1, 8],
+ [5, 1, 5],
+ ];
+ }
}
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_simple_tier_pricing.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_simple_tier_pricing.php
new file mode 100644
index 0000000000000..30f0978480701
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_simple_tier_pricing.php
@@ -0,0 +1,43 @@
+create(\Magento\Catalog\Model\ProductFactory::class);
+/** @var $bundleProduct \Magento\Catalog\Model\Product */
+$bundleProduct = $productFactory->create();
+$bundleProduct->setTypeId('bundle')
+ ->setAttributeSetId($product->getDefaultAttributeSetId())
+ ->setWebsiteIds([1])
+ ->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)
+ ->setPriceView(1)
+ ->setName('Bundle Product')
+ ->setSku('bundle-product')
+ ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
+ ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
+ ->setStockData([
+ 'use_config_manage_stock' => 1,
+ 'qty' => 100,
+ 'is_qty_decimal' => 0,
+ 'is_in_stock' => 1,
+ ])
+ ->setBundleOptionsData(
+ [
+ [
+ 'title' => 'Bundle Product Items',
+ 'default_title' => 'Bundle Product Items',
+ 'type' => 'checkbox',
+ 'required' => 1,
+ 'delete' => '',
+ ],
+ ]
+ )
+ ->setBundleSelectionsData(
+ [[['product_id' => $product->getId(), 'selection_qty' => 1, 'delete' => '']]]
+ );
+$productRepository->save($bundleProduct);
diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_simple_tier_pricing_rollback.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_simple_tier_pricing_rollback.php
new file mode 100644
index 0000000000000..aa661c7412d42
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/product_with_simple_tier_pricing_rollback.php
@@ -0,0 +1,24 @@
+get(\Magento\Framework\Registry::class);
+
+$registry->unregister('isSecureArea');
+$registry->register('isSecureArea', true);
+
+try {
+ $product = $productRepository->get('bundle-product');
+ $productRepository->delete($product);
+} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
+ //Product already removed
+}
+
+$registry->unregister('isSecureArea');
+$registry->register('isSecureArea', false);
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php b/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php
index a934372bfd907..9980f40239f8c 100644
--- a/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php
+++ b/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php
@@ -4,41 +4,51 @@
* See COPYING.txt for license details.
*/
+namespace Magento\Framework\Data\Form\Element;
+
+use Magento\Framework\Data\Form\ElementFactory;
+use Magento\TestFramework\Helper\Bootstrap;
+
/**
* Tests for \Magento\Framework\Data\Form\Element\Date
*/
-namespace Magento\Framework\Data\Form\Element;
-
class DateTest extends \PHPUnit\Framework\TestCase
{
/**
- * @var \Magento\Framework\Data\Form\ElementFactory
+ * @var ElementFactory
*/
- protected $_elementFactory;
+ private $elementFactory;
/**
- * SetUp method
+ * @inheritdoc
*/
protected function setUp()
{
- $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
- $this->_elementFactory = $objectManager->create(\Magento\Framework\Data\Form\ElementFactory::class);
+ $objectManager = Bootstrap::getObjectManager();
+ $this->elementFactory = $objectManager->create(ElementFactory::class);
}
/**
+ * Test get value
+ *
+ * @param array $data
+ * @param string $expect
+ * @return void
* @dataProvider getValueDataProvider
*/
- public function testGetValue(array $data, $expect)
+ public function testGetValue(array $data, string $expect): void
{
- /** @var $date \Magento\Framework\Data\Form\Element\Date */
- $date = $this->_elementFactory->create(\Magento\Framework\Data\Form\Element\Date::class, $data);
+ /** @var $date Date */
+ $date = $this->elementFactory->create(Date::class, $data);
$this->assertEquals($expect, $date->getValue());
}
/**
+ * Get value test data provider
+ *
* @return array
*/
- public function getValueDataProvider()
+ public function getValueDataProvider(): array
{
$testTimestamp = strtotime('2014-05-18 12:08:16');
$date = new \DateTime('@' . $testTimestamp);
@@ -56,15 +66,22 @@ public function getValueDataProvider()
'time_format' => 'h:mm a',
'value' => $testTimestamp,
],
- $date->format('g:i A')
+ $date->format('g:i A'),
],
[
[
'date_format' => 'MM/d/yy',
'value' => $testTimestamp,
],
- $date->format('m/j/y')
- ]
+ $date->format('m/j/y'),
+ ],
+ [
+ [
+ 'date_format' => 'd-MM-Y',
+ 'value' => $date->format('d-m-Y'),
+ ],
+ $date->format('d-m-Y'),
+ ],
];
}
}
diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php
index bd505fd4db035..985019b687ce0 100644
--- a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php
+++ b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php
@@ -7,10 +7,19 @@
namespace Magento\Tax\Model\Sales\Total\Quote;
use Magento\Framework\App\Config\ScopeConfigInterface;
+use Magento\Quote\Model\Quote;
use Magento\Tax\Model\Config;
use Magento\Tax\Model\Calculation;
+use Magento\Quote\Model\Quote\Item\Updater;
+use Magento\Catalog\Api\ProductRepositoryInterface;
+use Magento\Catalog\Api\Data\ProductInterface;
+use Magento\Framework\Api\Filter;
+use Magento\Framework\Api\Search\FilterGroup;
+use Magento\Framework\Api\SearchCriteriaInterface;
/**
+ * Setup utility for quote
+ *
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SetupUtil
@@ -594,7 +603,7 @@ protected function createCartRule($ruleDataOverride)
*
* @param array $quoteData
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
- * @return \Magento\Quote\Model\Quote
+ * @return Quote
*/
protected function createQuote($quoteData, $customer)
{
@@ -619,8 +628,8 @@ protected function createQuote($quoteData, $customer)
$quoteBillingAddress = $this->objectManager->create(\Magento\Quote\Model\Quote\Address::class);
$quoteBillingAddress->importCustomerAddressData($addressService->getById($billingAddress->getId()));
- /** @var \Magento\Quote\Model\Quote $quote */
- $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
+ /** @var Quote $quote */
+ $quote = $this->objectManager->create(Quote::class);
$quote->setStoreId(1)
->setIsActive(true)
->setIsMultiShipping(false)
@@ -634,7 +643,7 @@ protected function createQuote($quoteData, $customer)
/**
* Add products to quote
*
- * @param \Magento\Quote\Model\Quote $quote
+ * @param Quote $quote
* @param array $itemsData
* @return $this
*/
@@ -657,7 +666,8 @@ protected function addProductToQuote($quote, $itemsData)
* Create a quote based on given data
*
* @param array $quoteData
- * @return \Magento\Quote\Model\Quote
+ *
+ * @return Quote
*/
public function setupQuote($quoteData)
{
@@ -666,7 +676,9 @@ public function setupQuote($quoteData)
$quote = $this->createQuote($quoteData, $customer);
$this->addProductToQuote($quote, $quoteData['items']);
-
+ if (isset($quoteData['update_items'])) {
+ $this->updateItems($quote, $quoteData['update_items']);
+ }
//Set shipping amount
if (isset($quoteData['shipping_method'])) {
$quote->getShippingAddress()->setShippingMethod($quoteData['shipping_method']);
@@ -683,4 +695,33 @@ public function setupQuote($quoteData)
return $quote;
}
+
+ /**
+ * Update quote items
+ *
+ * @param Quote $quote
+ * @param array $items
+ *
+ * @return void
+ */
+ private function updateItems(Quote $quote, array $items): void
+ {
+ $updater = $this->objectManager->get(Updater::class);
+ $productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
+ $filter = $this->objectManager->create(Filter::class);
+ $filter->setField('sku')->setValue(array_keys($items));
+ $filterGroup = $this->objectManager->create(FilterGroup::class);
+ $filterGroup->setFilters([$filter]);
+ $searchCriteria = $this->objectManager->create(SearchCriteriaInterface::class);
+ $searchCriteria->setFilterGroups([$filterGroup]);
+ $products = $productRepository->getList($searchCriteria)->getItems();
+ /** @var ProductInterface $product */
+ foreach ($products as $product) {
+ $quoteItem = $quote->getItemByProduct($product);
+ $updater->update(
+ $quoteItem,
+ $items[$product->getSku()]
+ );
+ }
+ }
}
diff --git a/dev/tests/integration/testsuite/Magento/Tax/_files/scenarios/including_tax_with_custom_price.php b/dev/tests/integration/testsuite/Magento/Tax/_files/scenarios/including_tax_with_custom_price.php
new file mode 100644
index 0000000000000..290c133f455f6
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Tax/_files/scenarios/including_tax_with_custom_price.php
@@ -0,0 +1,93 @@
+ [
+ SetupUtil::CONFIG_OVERRIDES => [
+ Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX => 1,
+ Config::CONFIG_XML_PATH_APPLY_ON => 0,
+ ],
+ SetupUtil::TAX_RATE_OVERRIDES => [
+ SetupUtil::TAX_RATE_TX => 8.25,
+ SetupUtil::TAX_STORE_RATE => 8.25,
+ ],
+ SetupUtil::TAX_RULE_OVERRIDES => [
+ ],
+ ],
+ 'quote_data' => [
+ 'billing_address' => [
+ 'region_id' => SetupUtil::REGION_TX,
+ ],
+ 'shipping_address' => [
+ 'region_id' => SetupUtil::REGION_TX,
+ ],
+ 'items' => [
+ [
+ 'sku' => 'simple1',
+ 'price' => 16.24,
+ 'qty' => 1,
+ ],
+ ],
+ 'update_items' => [
+ 'simple1' => [
+ 'custom_price' => 14,
+ 'qty' => 1,
+ ],
+ ],
+ ],
+ 'expected_results' => [
+ 'address_data' => [
+ 'subtotal' => 12.93,
+ 'base_subtotal' => 12.93,
+ 'subtotal_incl_tax' => 14,
+ 'base_subtotal_incl_tax' => 14,
+ 'tax_amount' => 1.07,
+ 'base_tax_amount' => 1.07,
+ 'shipping_amount' => 0,
+ 'base_shipping_amount' => 0,
+ 'shipping_incl_tax' => 0,
+ 'base_shipping_incl_tax' => 0,
+ 'shipping_taxable' => 0,
+ 'base_shipping_taxable' => 0,
+ 'shipping_tax_amount' => 0,
+ 'base_shipping_tax_amount' => 0,
+ 'discount_amount' => 0,
+ 'base_discount_amount' => 0,
+ 'discount_tax_compensation_amount' => 0,
+ 'base_discount_tax_compensation_amount' => 0,
+ 'shipping_discount_tax_compensation_amount' => 0,
+ 'base_shipping_discount_tax_compensation_amount' => 0,
+ 'grand_total' => 14,
+ 'base_grand_total' => 14,
+ ],
+ 'items_data' => [
+ 'simple1' => [
+ 'row_total' => 12.93,
+ 'base_row_total' => 12.93,
+ 'tax_percent' => 8.25,
+ 'price' => 12.93,
+ 'custom_price' => 12.93,
+ 'original_custom_price' => 14,
+ 'base_price' => 12.93,
+ 'price_incl_tax' => 14,
+ 'base_price_incl_tax' => 14,
+ 'row_total_incl_tax' => 14,
+ 'base_row_total_incl_tax' => 14,
+ 'tax_amount' => 1.07,
+ 'base_tax_amount' => 1.07,
+ 'discount_amount' => 0,
+ 'base_discount_amount' => 0,
+ 'discount_percent' => 0,
+ 'discount_tax_compensation_amount' => 0,
+ 'base_discount_tax_compensation_amount' => 0,
+ ],
+ ],
+ ],
+];
diff --git a/dev/tests/integration/testsuite/Magento/Tax/_files/tax_calculation_data_aggregated.php b/dev/tests/integration/testsuite/Magento/Tax/_files/tax_calculation_data_aggregated.php
index f22b48a259685..3c56b1bf815a6 100644
--- a/dev/tests/integration/testsuite/Magento/Tax/_files/tax_calculation_data_aggregated.php
+++ b/dev/tests/integration/testsuite/Magento/Tax/_files/tax_calculation_data_aggregated.php
@@ -3,14 +3,15 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
/**
- * Global array that holds test scenarios data
+ * Global array that holds test scenarios data.
*
* @var array
*/
$taxCalculationData = [];
-
+//phpcs:disable Magento2.Security.IncludeFile
require_once __DIR__ . '/scenarios/excluding_tax_apply_tax_after_discount.php';
require_once __DIR__ . '/scenarios/excluding_tax_apply_tax_after_discount_discount_tax.php';
require_once __DIR__ . '/scenarios/excluding_tax_apply_tax_before_discount.php';
@@ -31,3 +32,4 @@
require_once __DIR__ . '/scenarios/multi_tax_rule_two_row_calculate_subtotal_yes_row.php';
require_once __DIR__ . '/scenarios/multi_tax_rule_two_row_calculate_subtotal_yes_total.php';
require_once __DIR__ . '/scenarios/including_tax_apply_tax_after_discount.php';
+require_once __DIR__ . '/scenarios/including_tax_with_custom_price.php';
diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/cc-form.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/cc-form.test.js
index 8fdef2cbaadbb..429342b43bcb2 100644
--- a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/cc-form.test.js
+++ b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/cc-form.test.js
@@ -15,6 +15,18 @@ define([
describe('Magento_Braintree/js/view/payment/method-renderer/cc-form', function () {
var injector = new Squire(),
mocks = {
+ 'Magento_Checkout/js/model/checkout-data-resolver': {
+
+ /** Stub */
+ applyBillingAddress: function () {
+ return true;
+ },
+
+ /** Stub */
+ resolveBillingAddress: function () {
+ return true;
+ }
+ },
'Magento_Checkout/js/model/quote': {
billingAddress: ko.observable(),
shippingAddress: ko.observable(),
diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js
index 4fc73caf7e14b..6ba0ed0b58f03 100644
--- a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js
+++ b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js
@@ -14,6 +14,18 @@ define([
var injector = new Squire(),
mocks = {
+ 'Magento_Checkout/js/model/checkout-data-resolver': {
+
+ /** Stub */
+ applyBillingAddress: function () {
+ return true;
+ },
+
+ /** Stub */
+ resolveBillingAddress: function () {
+ return true;
+ }
+ },
'Magento_Checkout/js/model/quote': {
billingAddress: ko.observable(),
shippingAddress: ko.observable({
diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Paypal/frontend/js/view/payment/method-renderer/paypal-express-abstract.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Paypal/frontend/js/view/payment/method-renderer/paypal-express-abstract.test.js
index 29a2e8db914a7..7bc9a2a0113aa 100644
--- a/dev/tests/js/jasmine/tests/app/code/Magento/Paypal/frontend/js/view/payment/method-renderer/paypal-express-abstract.test.js
+++ b/dev/tests/js/jasmine/tests/app/code/Magento/Paypal/frontend/js/view/payment/method-renderer/paypal-express-abstract.test.js
@@ -24,6 +24,18 @@ define([
return true;
}).and.callThrough(),
mocks = {
+ 'Magento_Checkout/js/model/checkout-data-resolver': {
+
+ /** Stub */
+ applyBillingAddress: function () {
+ return true;
+ },
+
+ /** Stub */
+ resolveBillingAddress: function () {
+ return true;
+ }
+ },
'Magento_Checkout/js/model/quote': {
billingAddress: ko.observable(),
shippingAddress: ko.observable(),
diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Date.php b/lib/internal/Magento/Framework/Data/Form/Element/Date.php
index 897617e560be5..6e4e97dbac79d 100644
--- a/lib/internal/Magento/Framework/Data/Form/Element/Date.php
+++ b/lib/internal/Magento/Framework/Data/Form/Element/Date.php
@@ -53,6 +53,19 @@ public function __construct(
}
}
+ /**
+ * Check if a string is a date value
+ *
+ * @param string $value
+ * @return bool
+ */
+ private function isDate(string $value): bool
+ {
+ $date = date_parse($value);
+
+ return !empty($date['year']) && !empty($date['month']) && !empty($date['day']);
+ }
+
/**
* If script executes on x64 system, converts large numeric values to timestamp limit
*
@@ -85,13 +98,13 @@ public function setValue($value)
$this->_value = $value;
return $this;
}
-
try {
if (preg_match('/^[0-9]+$/', $value)) {
$this->_value = (new \DateTime())->setTimestamp($this->_toTimestamp($value));
+ } elseif (is_string($value) && $this->isDate($value)) {
+ $this->_value = new \DateTime($value, new \DateTimeZone($this->localeDate->getConfigTimezone()));
} else {
- $this->_value = new \DateTime($value);
- $this->_value->setTimezone(new \DateTimeZone($this->localeDate->getConfigTimezone()));
+ $this->_value = '';
}
} catch (\Exception $e) {
$this->_value = '';