From c9502a2995e0b3f475ebeca45f019d7597578daf Mon Sep 17 00:00:00 2001 From: Nikita Shcherbatykh Date: Mon, 18 Nov 2019 16:44:43 +0200 Subject: [PATCH 01/10] MC-22972: Credit memo without refunded shipment produces the negative Grand Total --- app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php b/app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php index d4c2e7b2d6854..95dace13d832f 100644 --- a/app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php +++ b/app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php @@ -41,7 +41,7 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo) $baseOrderItemTax = (double)$orderItem->getBaseTaxInvoiced(); $orderItemQty = (double)$orderItem->getQtyInvoiced(); - if ($orderItemTax && $orderItemQty) { + if ($orderItemQty) { /** * Check item tax amount */ From fa416396e8fa14426077bc0de5150d1ca8d9fc45 Mon Sep 17 00:00:00 2001 From: Serhiy Yelahin Date: Tue, 19 Nov 2019 10:53:47 +0200 Subject: [PATCH 02/10] MC-23193: Tier Prices error on product update --- .../Product/Attribute/Backend/TierPrice/UpdateHandler.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php index f1943bc108878..0daa1dfb5c8eb 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php @@ -96,12 +96,7 @@ public function execute($entity, $arguments = []) $productId = (int)$entity->getData($identifierField); // prepare original data to compare - $origPrices = []; - $originalId = $entity->getOrigData($identifierField); - if (empty($originalId) || $entity->getData($identifierField) == $originalId) { - $origPrices = $entity->getOrigData($attribute->getName()); - } - + $origPrices = $entity->getOrigData($attribute->getName()); $old = $this->prepareOldTierPriceToCompare($origPrices); // prepare data for save $new = $this->prepareNewDataForSave($priceRows, $isGlobal); From f2bfadee7b32e72800025f3f74e5ee7b97e7f6db Mon Sep 17 00:00:00 2001 From: Serhiy Yelahin Date: Tue, 19 Nov 2019 13:37:11 +0200 Subject: [PATCH 03/10] MC-23193: Tier Prices error on product update --- .../Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php index cce00c50d37af..fde793d5c5f89 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php @@ -108,6 +108,7 @@ public function testExecute(): void ]; $linkField = 'entity_id'; $productId = 10; + $originalProductId = 11; /** @var \PHPUnit_Framework_MockObject_MockObject $product */ $product = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class) @@ -124,7 +125,7 @@ public function testExecute(): void ->willReturnMap( [ ['tier_price', $originalTierPrices], - ['entity_id', $productId] + ['entity_id', $originalProductId] ] ); $product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(0); From 3872f5f63fcb26e13565694392b9feb88c4df9c9 Mon Sep 17 00:00:00 2001 From: Nikita Shcherbatykh Date: Thu, 21 Nov 2019 13:14:39 +0200 Subject: [PATCH 04/10] MC-22972: Credit memo without refunded shipment produces the negative Grand Total --- .../Model/Order/Creditmemo/Total/TaxTest.php | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php index 565d51ff515a2..7d1096b4c9ea1 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php @@ -610,6 +610,143 @@ public function collectDataProvider() ], ]; + // scenario 6: 2 items, 2 invoiced, price includes tax, full discount, free shipping + // partial credit memo, make sure that discount tax compensation (with 100 % discount) is calculated correctly + $result['collect_with_full_discount_product_price'] = [ + 'order_data' => [ + 'data_fields' => [ + 'discount_amount' => -200.00, + 'discount_invoiced' => -200.00, + 'subtotal' => 181.82, + 'subtotal_incl_tax' => 200, + 'base_subtotal' => 181.82, + 'base_subtotal_incl_tax' => 200, + 'subtotal_invoiced' => 181.82, + 'discount_tax_compensation_amount' => 18.18, + 'discount_tax_compensation_invoiced' => 18.18, + 'base_discount_tax_compensation_amount' => 18.18, + 'base_discount_tax_compensation_invoiced' => 18.18, + 'grand_total' => 0, + 'base_grand_total' => 0, + 'shipping_tax_amount' => 0, + 'base_shipping_tax_amount' => 0, + 'shipping_discount_tax_compensation_amount' => 0, + 'base_shipping_discount_tax_compensation_amount' => 0, + 'tax_amount' => 0, + 'base_tax_amount' => 0, + 'tax_invoiced' => 0, + 'base_tax_invoiced' => 0, + 'tax_refunded' => 0, + 'base_tax_refunded' => 0, + 'base_shipping_amount' => 0, + ], + ], + 'creditmemo_data' => [ + 'items' => [ + 'item_1' => [ + 'order_item' => [ + 'qty_invoiced' => 1, + 'tax_amount' => 0, + 'tax_invoiced' => 0, + 'tax_refunded' => null, + 'base_tax_amount' => 0, + 'base_tax_invoiced' => 0, + 'base_tax_refunded' => 0, + 'tax_percent' => 10, + 'qty_refunded' => 0, + 'discount_percent' => 100, + 'discount_amount' => 100, + 'base_discount_amount' => 100, + 'discount_invoiced' => 100, + 'base_discount_invoiced' => 100, + 'row_total' => 90.91, + 'base_row_total' => 90.91, + 'row_invoiced' => 90.91, + 'base_row_invoiced' => 90.91, + 'price_incl_tax' => 100, + 'base_price_incl_tax' => 100, + 'row_total_incl_tax' => 100, + 'base_row_total_incl_tax' => 100, + 'discount_tax_compensation_amount' => 9.09, + 'base_discount_tax_compensation_amount' => 9.09, + 'discount_tax_compensation_invoiced' => 9.09, + 'base_discount_tax_compensation_invoiced' => 9.09, + ], + 'is_last' => true, + 'qty' => 1, + ], + 'item_2' => [ + 'order_item' => [ + 'qty_invoiced' => 1, + 'tax_amount' => 0, + 'tax_invoiced' => 0, + 'tax_refunded' => null, + 'base_tax_amount' => 0, + 'base_tax_invoiced' => 0, + 'base_tax_refunded' => null, + 'tax_percent' => 10, + 'qty_refunded' => 0, + 'discount_percent' => 100, + 'discount_amount' => 100, + 'base_discount_amount' => 100, + 'discount_invoiced' => 100, + 'base_discount_invoiced' => 100, + 'row_total' => 90.91, + 'base_row_total' => 90.91, + 'row_invoiced' => 90.91, + 'base_row_invoiced' => 90.91, + 'price_incl_tax' => 100, + 'base_price_incl_tax' => 100, + 'row_total_incl_tax' => 100, + 'base_row_total_incl_tax' => 100, + 'discount_tax_compensation_amount' => 9.09, + 'base_discount_tax_compensation_amount' => 9.09, + 'discount_tax_compensation_invoiced' => 9.09, + 'base_discount_tax_compensation_invoiced' => 9.09, + ], + 'is_last' => false, + 'qty' => 0, + ], + ], + 'is_last' => false, + 'data_fields' => [ + 'grand_total' => -9.09, + 'base_grand_total' => -9.09, + 'base_shipping_amount' => 0, + 'tax_amount' => 0, + 'base_tax_amount' => 0, + 'invoice' => new MagentoObject( + [ + 'shipping_tax_amount' => 0, + 'base_shipping_tax_amount' => 0, + 'shipping_discount_tax_compensation_amount' => 0, + 'base_shipping_discount_tax_compensation_amount' => 0, + ] + ), + ], + ], + 'expected_results' => [ + 'creditmemo_items' => [ + 'item_1' => [ + 'tax_amount' => 0, + 'base_tax_amount' => 0, + ], + 'item_2' => [ + 'tax_amount' => 0, + 'base_tax_amount' => 0, + ], + ], + 'creditmemo_data' => [ + 'grand_total' => 0, + 'base_grand_total' => 0, + 'tax_amount' => 0, + 'base_tax_amount' => 0, + 'shipping_tax_amount' => 0, + 'base_shipping_tax_amount' => 0, + ], + ], + ]; + return $result; } From 277bde305a1637f488fc867a47efe8bb247b0962 Mon Sep 17 00:00:00 2001 From: Nikita Shcherbatykh Date: Thu, 21 Nov 2019 15:35:42 +0200 Subject: [PATCH 05/10] MC-22972: Credit memo without refunded shipment produces the negative Grand Total --- .../Model/Order/Creditmemo/Total/TaxTest.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php index 7d1096b4c9ea1..f32ce7aa4715b 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php @@ -100,16 +100,18 @@ public function testCollect($orderData, $creditmemoData, $expectedResults) } $this->creditmemo->expects($this->any()) ->method('roundPrice') - ->will($this->returnCallback( - function ($price, $type) use (&$roundingDelta) { - if (!isset($roundingDelta[$type])) { - $roundingDelta[$type] = 0; + ->will( + $this->returnCallback( + function ($price, $type) use (&$roundingDelta) { + if (!isset($roundingDelta[$type])) { + $roundingDelta[$type] = 0; + } + $roundedPrice = round($price + $roundingDelta[$type], 2); + $roundingDelta[$type] = $price - $roundedPrice; + return $roundedPrice; } - $roundedPrice = round($price + $roundingDelta[$type], 2); - $roundingDelta[$type] = $price - $roundedPrice; - return $roundedPrice; - } - )); + ) + ); $this->model->collect($this->creditmemo); From 4e3e5bd5d387cdb4ba6358c7d9e3a49a2cd8a3d8 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" Date: Mon, 25 Nov 2019 12:52:23 +0200 Subject: [PATCH 06/10] MC-21860: Partial sitemaps have wrong urls in sitemap index --- app/code/Magento/Sitemap/Model/Sitemap.php | 20 ++++-- .../Magento/Sitemap/Model/SitemapTest.php | 69 +++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php index 0d69634ccfa5e..2baa6ff2c71a7 100644 --- a/app/code/Magento/Sitemap/Model/Sitemap.php +++ b/app/code/Magento/Sitemap/Model/Sitemap.php @@ -10,6 +10,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Filesystem; use Magento\Framework\UrlInterface; use Magento\Robots\Model\Config\Value; use Magento\Sitemap\Model\ItemProvider\ItemProviderInterface; @@ -191,6 +192,16 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento */ private $lastModMinTsVal; + /** + * @var Filesystem + */ + private $filesystem; + + /** + * @var DocumentRoot + */ + private $documentRoot; + /** * Initialize dependencies. * @@ -238,8 +249,9 @@ public function __construct( ) { $this->_escaper = $escaper; $this->_sitemapData = $sitemapData; - $documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class); - $this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath()); + $this->documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class); + $this->filesystem = $filesystem; + $this->_directory = $filesystem->getDirectoryWrite($this->documentRoot->getPath()); $this->_categoryFactory = $categoryFactory; $this->_productFactory = $productFactory; $this->_cmsFactory = $cmsFactory; @@ -727,8 +739,8 @@ protected function _getFormattedLastmodDate($date) */ protected function _getDocumentRoot() { - // phpcs:ignore Magento2.Functions.DiscouragedFunction - return realpath($this->_request->getServer('DOCUMENT_ROOT')); + return $this->filesystem->getDirectoryRead($this->documentRoot->getPath()) + ->getAbsolutePath(); } /** diff --git a/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php b/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php new file mode 100644 index 0000000000000..8b9c4229d2b28 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php @@ -0,0 +1,69 @@ +objectManager = Bootstrap::getObjectManager(); + $this->model = $this->objectManager->get(Sitemap::class); + } + + /** + * Test get sitemap URL from parent root directory path + * + * @return void + */ + public function testGetSitemapUrlFromParentRootDirectoryPath(): void + { + /** @var Value $configValue */ + $configValue = $this->objectManager->get(Value::class); + $configValue->load('web/unsecure/base_url', 'path'); + $baseUrl = $configValue->getValue() ?: 'http://localhost/'; + + /** @var Filesystem $filesystem */ + $filesystem = $this->objectManager->create(Filesystem::class); + $rootDir = $filesystem->getDirectoryRead(DirectoryList::ROOT) + ->getAbsolutePath(); + $requestPath = dirname($rootDir); + + /** @var Request $request */ + $request = $this->objectManager->get(Request::class); + //imitation run script from parent root directory + $request->setServer(new Parameters(['DOCUMENT_ROOT' => $requestPath])); + + $sitemapUrl = $this->model->getSitemapUrl('/', 'sitemap.xml'); + + $this->assertEquals($baseUrl.'sitemap.xml', $sitemapUrl); + } +} From 071b47b38d08fe8c092625a19dca09bb6059e211 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" Date: Mon, 25 Nov 2019 15:33:23 +0200 Subject: [PATCH 07/10] MC-21860: Partial sitemaps have wrong urls in sitemap index --- .../Magento/Sitemap/Model/SitemapTest.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php b/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php index 8b9c4229d2b28..a051bfc4dad45 100644 --- a/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php +++ b/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php @@ -8,7 +8,6 @@ namespace Magento\Sitemap\Model; -use Magento\Framework\App\Config\Value; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\ObjectManagerInterface; @@ -18,6 +17,9 @@ use Zend\Stdlib\Parameters; use PHPUnit\Framework\TestCase; +/** + * Test for Sitemap + */ class SitemapTest extends TestCase { /** @@ -30,6 +32,11 @@ class SitemapTest extends TestCase */ private $objectManager; + /** + * @var Filesystem + */ + private $filesystem; + /** * @inheritdoc */ @@ -37,6 +44,7 @@ protected function setUp() { $this->objectManager = Bootstrap::getObjectManager(); $this->model = $this->objectManager->get(Sitemap::class); + $this->filesystem = $this->objectManager->get(Filesystem::class); } /** @@ -46,14 +54,9 @@ protected function setUp() */ public function testGetSitemapUrlFromParentRootDirectoryPath(): void { - /** @var Value $configValue */ - $configValue = $this->objectManager->get(Value::class); - $configValue->load('web/unsecure/base_url', 'path'); - $baseUrl = $configValue->getValue() ?: 'http://localhost/'; + $baseUrl = 'http://localhost/'; - /** @var Filesystem $filesystem */ - $filesystem = $this->objectManager->create(Filesystem::class); - $rootDir = $filesystem->getDirectoryRead(DirectoryList::ROOT) + $rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT) ->getAbsolutePath(); $requestPath = dirname($rootDir); From 8036f49046955af249dbae8037495a42c78c05a9 Mon Sep 17 00:00:00 2001 From: Mastiuhin Olexandr Date: Mon, 25 Nov 2019 15:43:33 +0200 Subject: [PATCH 08/10] MC-28956: Discounted shipping price is incorrectly displayed on multishipping review order page --- .../Magento/Multishipping/Model/Checkout/Type/Multishipping.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php index 4c5f666805570..7fa674505461e 100644 --- a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php @@ -625,6 +625,7 @@ public function setShippingMethods($methods) $addressId = $address->getId(); if (isset($methods[$addressId])) { $address->setShippingMethod($methods[$addressId]); + $address->setCollectShippingRates(true); } elseif (!$address->getShippingMethod()) { throw new \Magento\Framework\Exception\LocalizedException( __('Set shipping methods for all addresses. Verify the shipping methods and try again.') From 61303b69a2ea96d20db1f5b728af7ca5e714510d Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" Date: Tue, 26 Nov 2019 10:56:53 +0200 Subject: [PATCH 09/10] MC-21860: Partial sitemaps have wrong urls in sitemap index --- .../testsuite/Magento/Sitemap/Model/SitemapTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php b/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php index a051bfc4dad45..73863e0915c66 100644 --- a/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php +++ b/dev/tests/integration/testsuite/Magento/Sitemap/Model/SitemapTest.php @@ -18,7 +18,7 @@ use PHPUnit\Framework\TestCase; /** - * Test for Sitemap + * Tests \Magento\Sitemap\Model\Sitemap functionality. */ class SitemapTest extends TestCase { @@ -54,8 +54,6 @@ protected function setUp() */ public function testGetSitemapUrlFromParentRootDirectoryPath(): void { - $baseUrl = 'http://localhost/'; - $rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT) ->getAbsolutePath(); $requestPath = dirname($rootDir); @@ -67,6 +65,6 @@ public function testGetSitemapUrlFromParentRootDirectoryPath(): void $sitemapUrl = $this->model->getSitemapUrl('/', 'sitemap.xml'); - $this->assertEquals($baseUrl.'sitemap.xml', $sitemapUrl); + $this->assertEquals('http://localhost/sitemap.xml', $sitemapUrl); } } From e6ea90ef32bff884a97c34b48ff5c9400fa5891f Mon Sep 17 00:00:00 2001 From: Mastiuhin Olexandr Date: Wed, 27 Nov 2019 11:52:37 +0200 Subject: [PATCH 10/10] MC-28956: Discounted shipping price is incorrectly displayed on multishipping review order page --- .../Test/Unit/Model/Checkout/Type/MultishippingTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php index 731365974c235..fba3245bec68d 100644 --- a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php +++ b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php @@ -420,13 +420,16 @@ public function testSetShippingMethods() $methodsArray = [1 => 'flatrate_flatrate', 2 => 'tablerate_bestway']; $addressId = 1; $addressMock = $this->getMockBuilder(QuoteAddress::class) - ->setMethods(['getId', 'setShippingMethod']) + ->setMethods(['getId', 'setShippingMethod', 'setCollectShippingRates']) ->disableOriginalConstructor() ->getMock(); $addressMock->expects($this->once())->method('getId')->willReturn($addressId); $this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]); $addressMock->expects($this->once())->method('setShippingMethod')->with($methodsArray[$addressId]); + $addressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true); $this->quoteMock->expects($this->once()) ->method('__call') ->with('setTotalsCollectedFlag', [false])