Skip to content

Commit 448acba

Browse files
committed
MAGETWO-52069: Customer can't place Order using FedEx
- Fixed shipping method exploder
1 parent 1aa5f73 commit 448acba

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

app/code/Magento/Quote/Model/Quote/ShippingAssignment/ShippingProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public function save(ShippingInterface $shipping, CartInterface $quote)
6565
{
6666
$this->shippingAddressManagement->assign($quote->getId(), $shipping->getAddress());
6767
if (!empty($shipping->getMethod()) && $quote->getItemsCount() > 0) {
68-
list($carrierCode, $methodCode) = explode("_", $shipping->getMethod());
68+
$nameComponents = explode('_', $shipping->getMethod());
69+
$carrierCode = array_shift($nameComponents);
70+
// carrier method code can contains more one name component
71+
$methodCode = implode('_', $nameComponents);
6972
$this->shippingMethodManagement->apply($quote->getId(), $carrierCode, $methodCode);
7073
}
7174
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Test\Unit\Model\Quote\ShippingAssignment;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\Quote\Api\Data\AddressInterface;
10+
use Magento\Quote\Api\Data\CartInterface;
11+
use Magento\Quote\Api\Data\ShippingInterface;
12+
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor;
13+
use Magento\Quote\Model\ShippingAddressManagement;
14+
use Magento\Quote\Model\ShippingMethodManagement;
15+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
16+
17+
/**
18+
* Class ShippingProcessorTest
19+
*/
20+
class ShippingProcessorTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @var ShippingAddressManagement|MockObject
24+
*/
25+
private $shippingAddressManagement;
26+
27+
/**
28+
* @var ShippingMethodManagement|MockObject
29+
*/
30+
private $shippingMethodManagement;
31+
32+
/**
33+
* @var ShippingProcessor
34+
*/
35+
private $shippingProcessor;
36+
37+
protected function setUp()
38+
{
39+
$this->shippingAddressManagement = $this->getMockBuilder(ShippingAddressManagement::class)
40+
->disableOriginalConstructor()
41+
->setMethods(['assign'])
42+
->getMock();
43+
44+
$this->shippingMethodManagement = $this->getMockBuilder(ShippingMethodManagement::class)
45+
->disableOriginalConstructor()
46+
->setMethods(['apply'])
47+
->getMock();
48+
49+
$objectManager = new ObjectManager($this);
50+
51+
$this->shippingProcessor = $objectManager->getObject(ShippingProcessor::class, [
52+
'shippingAddressManagement' => $this->shippingAddressManagement,
53+
'shippingMethodManagement' => $this->shippingMethodManagement
54+
]);
55+
}
56+
57+
/**
58+
* @param string $method
59+
* @param string $carrierCode
60+
* @param string $methodCode
61+
* @dataProvider saveDataProvider
62+
*/
63+
public function testSave($method, $carrierCode, $methodCode)
64+
{
65+
$shipping = $this->getMockForAbstractClass(ShippingInterface::class);
66+
$quote = $this->getMockForAbstractClass(CartInterface::class);
67+
$quoteId = 1;
68+
69+
$address = $this->getMockForAbstractClass(AddressInterface::class);
70+
71+
$quote->expects(static::exactly(2))
72+
->method('getId')
73+
->willReturn($quoteId);
74+
75+
$shipping->expects(static::once())
76+
->method('getAddress')
77+
->willReturn($address);
78+
79+
$this->shippingAddressManagement->expects(static::once())
80+
->method('assign')
81+
->with($quoteId, $address);
82+
83+
$shipping->expects(static::exactly(2))
84+
->method('getMethod')
85+
->willReturn($method);
86+
87+
$quote->expects(static::once())
88+
->method('getItemsCount')
89+
->willReturn(1);
90+
91+
$this->shippingMethodManagement->expects(static::once())
92+
->method('apply')
93+
->with($quoteId, $carrierCode, $methodCode);
94+
95+
$this->shippingProcessor->save($shipping, $quote);
96+
}
97+
98+
/**
99+
* Get variations for save method testing
100+
* @return array
101+
*/
102+
public function saveDataProvider()
103+
{
104+
return [
105+
['carrier_Global_World_Economy', 'carrier', 'Global_World_Economy'],
106+
['carrier_International_Economy', 'carrier', 'International_Economy'],
107+
['carrier_Express', 'carrier', 'Express'],
108+
['flat_rate', 'flat', 'rate'],
109+
];
110+
}
111+
}

0 commit comments

Comments
 (0)