From 5327ddc4b706de9dc573194acf3481dfc8e33cb5 Mon Sep 17 00:00:00 2001 From: Nicolas D <50154923+nicolasddev@users.noreply.github.com> Date: Fri, 25 Feb 2022 18:23:51 -0500 Subject: [PATCH 1/3] Calculate Accurate Shipping Cost The shipping cost wasn't accurate when a shipment contained multiple packages as only the prices from the different packages were compiled, while the cost remained the one returned for a first package. --- app/code/Magento/Shipping/Model/Rate/PackageResult.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Shipping/Model/Rate/PackageResult.php b/app/code/Magento/Shipping/Model/Rate/PackageResult.php index 4fd4ce63a7e87..ec5582ba0b361 100644 --- a/app/code/Magento/Shipping/Model/Rate/PackageResult.php +++ b/app/code/Magento/Shipping/Model/Rate/PackageResult.php @@ -68,6 +68,7 @@ public function getAllRates() throw new \InvalidArgumentException('Same object received from carrier.'); } $rate->setPrice($rate->getPrice() + $currentRate->getPrice()); + $rate->setCost($rate->getCost() + $currentRate->getCost()); continue 2; } } From 0cd802b0bc0c98562c272660b1ce70a7ae4f98bd Mon Sep 17 00:00:00 2001 From: Nicolas D <50154923+nicolasddev@users.noreply.github.com> Date: Fri, 25 Feb 2022 18:27:41 -0500 Subject: [PATCH 2/3] Calculate Accurate Shipping Cost Related to commit #5327ddc4b706de9dc573194acf3481dfc8e33cb5 (https://github.com/magento/magento2/commit/5327ddc4b706de9dc573194acf3481dfc8e33cb5) The shipping cost wasn't accurate when a shipment contained multiple packages as only the prices from the different packages were compiled, while the cost remained the one returned for a first package. (One request mode) --- app/code/Magento/Shipping/Model/Rate/Result.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Shipping/Model/Rate/Result.php b/app/code/Magento/Shipping/Model/Rate/Result.php index c4ba502b346e8..bbdbe77aba8db 100644 --- a/app/code/Magento/Shipping/Model/Rate/Result.php +++ b/app/code/Magento/Shipping/Model/Rate/Result.php @@ -224,6 +224,7 @@ public function updateRatePrice($packageCount) if ($packageCount > 1) { foreach ($this->_rates as $rate) { $rate->setPrice($rate->getPrice() * $packageCount); + $rate->setCost($rate->getCost() * $packageCount); } } From 431c578a779479b81057508c9bf7588bd74119ba Mon Sep 17 00:00:00 2001 From: Nicolas D <50154923+nicolasddev@users.noreply.github.com> Date: Wed, 16 Mar 2022 15:33:21 -0400 Subject: [PATCH 3/3] Cost Values Missing for Rates as Array The cost values are missing when calling the Magento\Shipping\Model\Rate\Result::asArray() function, which is commonly called through Magento\Shipping\Model\Shipping::getResult(). --- app/code/Magento/Shipping/Model/Rate/Result.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Shipping/Model/Rate/Result.php b/app/code/Magento/Shipping/Model/Rate/Result.php index bbdbe77aba8db..3a99b68f3754d 100644 --- a/app/code/Magento/Shipping/Model/Rate/Result.php +++ b/app/code/Magento/Shipping/Model/Rate/Result.php @@ -163,6 +163,8 @@ public function asArray() 'title' => $rate->getMethodTitle(), 'price' => $rate->getPrice(), 'price_formatted' => $currencyFilter->filter($rate->getPrice()), + 'cost' => $rate->getCost(), + 'cost_formatted' => $currencyFilter->filter($rate->getCost()), ]; } return $rates;