diff --git a/app/code/Magento/Shipping/Model/Config/Source/Allmethods.php b/app/code/Magento/Shipping/Model/Config/Source/Allmethods.php index f64c24856eba5..e25e2b41bb63e 100644 --- a/app/code/Magento/Shipping/Model/Config/Source/Allmethods.php +++ b/app/code/Magento/Shipping/Model/Config/Source/Allmethods.php @@ -45,11 +45,14 @@ public function __construct( public function toOptionArray($isActiveOnlyFlag = false) { $methods = [['value' => '', 'label' => '']]; - $carriers = $this->_shippingConfig->getAllCarriers(); + + if ($isActiveOnlyFlag) { + $carriers = $this->_shippingConfig->getActiveCarriers(); + } else { + $carriers = $this->_shippingConfig->getAllCarriers(); + } + foreach ($carriers as $carrierCode => $carrierModel) { - if (!$carrierModel->isActive() && (bool)$isActiveOnlyFlag === true) { - continue; - } $carrierMethods = $carrierModel->getAllowedMethods(); if (!$carrierMethods) { continue; diff --git a/app/code/Magento/Shipping/Test/Unit/Model/Config/Source/AllmethodsTest.php b/app/code/Magento/Shipping/Test/Unit/Model/Config/Source/AllmethodsTest.php index 0fe75f040fb1d..d0ba47bb9b5db 100644 --- a/app/code/Magento/Shipping/Test/Unit/Model/Config/Source/AllmethodsTest.php +++ b/app/code/Magento/Shipping/Test/Unit/Model/Config/Source/AllmethodsTest.php @@ -58,28 +58,45 @@ protected function setUp(): void } /** - * Ensure that options converted correctly + * Ensure that options converted correctly when isActiveOnlyFlag=false * * @dataProvider getCarriersMethodsProvider * @param array $expectedArray * @return void */ - public function testToOptionArray(array $expectedArray): void + public function testToOptionArrayGetAllCarriers(array $expectedArray): void { $expectedArray['getAllCarriers'] = [$this->carriersMock]; $this->shippingConfig->expects($this->once()) ->method('getAllCarriers') ->willReturn($expectedArray['getAllCarriers']); - $this->carriersMock->expects($this->once()) - ->method('isActive') - ->willReturn(true); $this->carriersMock->expects($this->once()) ->method('getAllowedMethods') ->willReturn($expectedArray['allowedMethods']); $this->assertEquals([$expectedArray['expected_result']], $this->allmethods->toOptionArray()); } + /** + * Ensure that options converted correctly when isActiveOnlyFlag=true + * + * @dataProvider getCarriersMethodsProvider + * @param array $expectedArray + * @return void + */ + public function testToOptionArrayGetActiveCarriers(array $expectedArray): void + { + $expectedArray['getActiveCarriers'] = [$this->carriersMock]; + + $this->shippingConfig->expects($this->once()) + ->method('getActiveCarriers') + ->willReturn($expectedArray['getActiveCarriers']); + $this->carriersMock->expects($this->once()) + ->method('getAllowedMethods') + ->willReturn($expectedArray['allowedMethods']); + $this->assertEquals([$expectedArray['expected_result']], $this->allmethods->toOptionArray(true)); + } + /** * Returns providers data for test * @@ -92,12 +109,14 @@ public static function getCarriersMethodsProvider(): array [ 'allowedMethods' => [null => 'method_title'], 'expected_result' => [ 'value' => [], 'label' => null], - 'getAllCarriers' => [] + 'getAllCarriers' => [], + 'getActiveCarriers' => [] ], [ 'allowedMethods' => ['method_code' => 'method_title'], 'expected_result' => [ 'value' => [], 'label' => 'method_code'], - 'getAllCarriers' => [] + 'getAllCarriers' => [], + 'getActiveCarriers' => [] ] ]