Skip to content

Commit 0b8fc26

Browse files
committed
Merge pull request #466 from magento-firedrakes/last_bugs
[Firedrakes] Bugfixes
2 parents b498e5f + d354780 commit 0b8fc26

File tree

21 files changed

+826
-364
lines changed

21 files changed

+826
-364
lines changed

app/code/Magento/Checkout/Block/Cart/Shipping.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
7676
*/
7777
protected $quoteRepository;
7878

79+
/**
80+
* @var \Magento\Checkout\Model\Cart\CollectQuote
81+
*/
82+
protected $collectQuote;
83+
7984
/**
8085
* @param \Magento\Framework\View\Element\Template\Context $context
8186
* @param \Magento\Customer\Model\Session $customerSession
@@ -88,6 +93,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
8893
* @param AddressRepositoryInterface $addressRepository
8994
* @param CustomerRepositoryInterface $customerRepository
9095
* @param QuoteRepository $quoteRepository
96+
* @param \Magento\Checkout\Model\Cart\CollectQuote $collectQuote
9197
* @param array $data
9298
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9399
*/
@@ -103,6 +109,7 @@ public function __construct(
103109
AddressRepositoryInterface $addressRepository,
104110
CustomerRepositoryInterface $customerRepository,
105111
QuoteRepository $quoteRepository,
112+
\Magento\Checkout\Model\Cart\CollectQuote $collectQuote,
106113
array $data = []
107114
) {
108115
$this->priceCurrency = $priceCurrency;
@@ -113,12 +120,12 @@ public function __construct(
113120
$this->addressRepository = $addressRepository;
114121
$this->customerRepository = $customerRepository;
115122
$this->quoteRepository = $quoteRepository;
123+
$this->collectQuote = $collectQuote;
116124
parent::__construct($context, $customerSession, $checkoutSession, $data);
117125
$this->_isScopePrivate = true;
118126
}
119127

120-
/**
121-
* Get config
128+
/** Get config
122129
*
123130
* @param string $path
124131
* @return string|null
@@ -364,22 +371,7 @@ public function getShippingPriceHtml(\Magento\Quote\Model\Quote\Address\Rate $sh
364371
*/
365372
protected function _beforeToHtml()
366373
{
367-
if ($this->_customerSession->isLoggedIn()) {
368-
$customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
369-
if ($defaultShipping = $customer->getDefaultShipping()) {
370-
$address = $this->addressRepository->getById($defaultShipping);
371-
if ($address) {
372-
/** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
373-
$estimatedAddress = $this->estimatedAddressFactory->create();
374-
$estimatedAddress->setCountryId($address->getCountryId());
375-
$estimatedAddress->setPostcode($address->getPostcode());
376-
$estimatedAddress->setRegion((string)$address->getRegion()->getRegion());
377-
$estimatedAddress->setRegionId($address->getRegionId());
378-
$this->shippingMethodManager->estimateByAddress($this->getQuote()->getId(), $estimatedAddress);
379-
$this->quoteRepository->save($this->getQuote());
380-
}
381-
}
382-
}
374+
$this->collectQuote->collect($this->getQuote());
383375
return parent::_beforeToHtml();
384376
}
385377

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Model\Cart;
7+
8+
class CollectQuote
9+
{
10+
/**
11+
* @var \Magento\Customer\Model\Session
12+
*/
13+
protected $customerSession;
14+
15+
/**
16+
* @var \Magento\Customer\Api\CustomerRepositoryInterface
17+
*/
18+
protected $customerRepository;
19+
20+
/**
21+
* @var \Magento\Customer\Api\AddressRepositoryInterface
22+
*/
23+
protected $addressRepository;
24+
25+
/**
26+
* @var \Magento\Quote\Api\Data\EstimateAddressInterfaceFactory
27+
*/
28+
protected $estimatedAddressFactory;
29+
30+
/**
31+
* @var \Magento\Quote\Api\ShippingMethodManagementInterface
32+
*/
33+
protected $shippingMethodManager;
34+
35+
/**
36+
* @var \Magento\Quote\Model\QuoteRepository
37+
*/
38+
protected $quoteRepository;
39+
40+
/**
41+
* @param \Magento\Customer\Model\Session $customerSession
42+
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
43+
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
44+
* @param \Magento\Quote\Api\Data\EstimateAddressInterfaceFactory $estimatedAddressFactory
45+
* @param \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManager
46+
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
47+
*/
48+
public function __construct(
49+
\Magento\Customer\Model\Session $customerSession,
50+
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
51+
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
52+
\Magento\Quote\Api\Data\EstimateAddressInterfaceFactory $estimatedAddressFactory,
53+
\Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManager,
54+
\Magento\Quote\Model\QuoteRepository $quoteRepository
55+
) {
56+
$this->customerSession = $customerSession;
57+
$this->customerRepository = $customerRepository;
58+
$this->addressRepository = $addressRepository;
59+
$this->estimatedAddressFactory = $estimatedAddressFactory;
60+
$this->shippingMethodManager = $shippingMethodManager;
61+
$this->quoteRepository = $quoteRepository;
62+
}
63+
64+
/**
65+
* @param \Magento\Quote\Model\Quote $quote
66+
* @return void
67+
*/
68+
public function collect(\Magento\Quote\Model\Quote $quote)
69+
{
70+
if ($this->customerSession->isLoggedIn()) {
71+
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
72+
if ($defaultShipping = $customer->getDefaultShipping()) {
73+
$address = $this->addressRepository->getById($defaultShipping);
74+
if ($address) {
75+
/** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
76+
$estimatedAddress = $this->estimatedAddressFactory->create();
77+
$estimatedAddress->setCountryId($address->getCountryId());
78+
$estimatedAddress->setPostcode($address->getPostcode());
79+
$estimatedAddress->setRegion((string)$address->getRegion()->getRegion());
80+
$estimatedAddress->setRegionId($address->getRegionId());
81+
$this->shippingMethodManager->estimateByAddress($quote->getId(), $estimatedAddress);
82+
$this->quoteRepository->save($quote);
83+
}
84+
}
85+
}
86+
}
87+
}

app/code/Magento/Checkout/Test/Unit/Block/Cart/ShippingTest.php

Lines changed: 18 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class ShippingTest extends \PHPUnit_Framework_TestCase
8585
/** @var Quote |\PHPUnit_Framework_MockObject_MockObject */
8686
protected $quote;
8787

88+
/** @var \PHPUnit_Framework_MockObject_MockObject */
89+
protected $collectQuote;
90+
8891
protected function setUp()
8992
{
9093
$this->prepareContext();
@@ -117,8 +120,13 @@ protected function setUp()
117120
$this->customerRepository = $this->getMockBuilder('Magento\Customer\Api\CustomerRepositoryInterface')
118121
->getMockForAbstractClass();
119122

123+
$this->collectQuote = $this->getMockBuilder('Magento\Checkout\Model\Cart\CollectQuote')
124+
->disableOriginalConstructor()
125+
->getMock();
126+
120127
$this->prepareQuoteRepository();
121128

129+
122130
$this->model = new Shipping(
123131
$this->context,
124132
$this->customerSession,
@@ -130,7 +138,8 @@ protected function setUp()
130138
$this->shippingMethodManager,
131139
$this->addressReporitory,
132140
$this->customerRepository,
133-
$this->quoteRepository
141+
$this->quoteRepository,
142+
$this->collectQuote
134143
);
135144
}
136145

@@ -259,182 +268,19 @@ public function testBeforeToHtmlCustomerNotLoggedIn()
259268
->with('advanced/modules_disable_output/Magento_Checkout', ScopeInterface::SCOPE_STORE)
260269
->willReturn(false);
261270

262-
$this->customerSession->expects($this->once())
263-
->method('isLoggedIn')
264-
->willReturn(false);
265-
266-
$this->assertEquals('', $this->model->toHtml());
267-
}
268-
269-
public function testBeforeToHtmlNoDefaultShippingAddress()
270-
{
271-
$customerId = 1;
272-
$defaultShipping = 0;
273-
274-
$this->eventManager->expects($this->once())
275-
->method('dispatch')
276-
->with('view_block_abstract_to_html_before', ['block' => $this->model])
277-
->willReturnSelf();
278-
279-
$this->scopeConfig->expects($this->once())
280-
->method('getValue')
281-
->with('advanced/modules_disable_output/Magento_Checkout', ScopeInterface::SCOPE_STORE)
282-
->willReturn(false);
283-
284-
$this->customerSession->expects($this->once())
285-
->method('isLoggedIn')
286-
->willReturn(true);
287-
$this->customerSession->expects($this->once())
288-
->method('getCustomerId')
289-
->willReturn($customerId);
290-
291-
$customerData = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
292-
->setMethods([
293-
'getDefaultShipping',
294-
])
295-
->getMockForAbstractClass();
296-
$customerData->expects($this->once())
297-
->method('getDefaultShipping')
298-
->willReturn($defaultShipping);
299-
300-
$this->customerRepository->expects($this->once())
301-
->method('getById')
302-
->with($customerId)
303-
->willReturn($customerData);
304-
305-
$this->assertEquals('', $this->model->toHtml());
306-
}
307-
308-
/**
309-
* @param int $customerId
310-
* @param int $defaultShipping
311-
* @param int $countryId
312-
* @param string $postcode
313-
* @param string $region
314-
* @param int $regionId
315-
* @param int $quoteId
316-
* @dataProvider dataProviderBeforeToHtml
317-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
318-
*/
319-
public function testBeforeToHtml(
320-
$customerId,
321-
$defaultShipping,
322-
$countryId,
323-
$postcode,
324-
$region,
325-
$regionId,
326-
$quoteId
327-
) {
328-
$this->eventManager->expects($this->once())
329-
->method('dispatch')
330-
->with('view_block_abstract_to_html_before', ['block' => $this->model])
331-
->willReturnSelf();
332-
333-
$this->scopeConfig->expects($this->once())
334-
->method('getValue')
335-
->with('advanced/modules_disable_output/Magento_Checkout', ScopeInterface::SCOPE_STORE)
336-
->willReturn(false);
337-
338-
$this->customerSession->expects($this->once())
339-
->method('isLoggedIn')
340-
->willReturn(true);
341-
$this->customerSession->expects($this->once())
342-
->method('getCustomerId')
343-
->willReturn($customerId);
344-
345-
$customerDataMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
346-
->setMethods([
347-
'getDefaultShipping',
348-
])
349-
->getMockForAbstractClass();
350-
$customerDataMock->expects($this->once())
351-
->method('getDefaultShipping')
352-
->willReturn($defaultShipping);
353-
354-
$this->customerRepository->expects($this->once())
355-
->method('getById')
356-
->with($customerId)
357-
->willReturn($customerDataMock);
358-
359-
$this->addressReporitory->expects($this->once())
360-
->method('getById')
361-
->with($defaultShipping)
362-
->willReturn($this->address);
363-
364-
$regionMock = $this->getMockBuilder('Magento\Customer\Api\Data\RegionInterface')
365-
->setMethods([
366-
'getRegion',
367-
])
368-
->getMockForAbstractClass();
369-
$regionMock->expects($this->once())
370-
->method('getRegion')
371-
->willReturn($region);
372-
373-
$this->address->expects($this->once())
374-
->method('getCountryId')
375-
->willReturn($countryId);
376-
$this->address->expects($this->once())
377-
->method('getPostcode')
378-
->willReturn($postcode);
379-
$this->address->expects($this->once())
380-
->method('getRegion')
381-
->willReturn($regionMock);
382-
$this->address->expects($this->once())
383-
->method('getRegionId')
384-
->willReturn($regionId);
385-
386-
$this->estimatedAddress->expects($this->once())
387-
->method('setCountryId')
388-
->with($countryId)
389-
->willReturnSelf();
390-
$this->estimatedAddress->expects($this->once())
391-
->method('setPostcode')
392-
->with($postcode)
393-
->willReturnSelf();
394-
$this->estimatedAddress->expects($this->once())
395-
->method('setRegion')
396-
->with($region)
397-
->willReturnSelf();
398-
$this->estimatedAddress->expects($this->once())
399-
->method('setRegionId')
400-
->with($regionId)
401-
->willReturnSelf();
402-
403-
$this->checkoutSession->expects($this->once())
271+
$quote = $this->getMockBuilder('Magento\Quote\Model\Quote')
272+
->disableOriginalConstructor()
273+
->getMock();
274+
$this->checkoutSession->expects($this->any())
404275
->method('getQuote')
405-
->willReturn($this->quote);
406-
407-
$this->quote->expects($this->once())
408-
->method('getId')
409-
->willReturn($quoteId);
410-
411-
$this->shippingMethodManager->expects($this->once())
412-
->method('estimateByAddress')
413-
->with($quoteId, $this->estimatedAddress)
414-
->willReturnSelf();
415-
416-
$this->quoteRepository->expects($this->once())
417-
->method('save')
418-
->with($this->quote)
419-
->willReturnSelf();
276+
->willReturn($quote);
277+
$this->collectQuote->expects($this->once())
278+
->method('collect')
279+
->with($quote);
420280

421281
$this->assertEquals('', $this->model->toHtml());
422282
}
423283

424-
/**
425-
* @return array
426-
*/
427-
public function dataProviderBeforeToHtml()
428-
{
429-
return [
430-
[1, 1, 1, '12345', '', 1, 1],
431-
[1, 1, 1, '12345', '', 0, 1],
432-
[1, 1, 1, '', '', 0, 1],
433-
[1, 1, 1, '12345', 'California', 0, 1],
434-
[1, 1, 1, '12345', 'California', 1, 1],
435-
];
436-
}
437-
438284
/**
439285
* @param int $count
440286
* @param bool $expectedResult

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ public function getJsonConfig()
187187
'amount' => $this->_registerJsPrice($this->_convertPrice($regularPrice->getAmount()->getValue())),
188188
],
189189
'basePrice' => [
190-
'amount' =>
191-
$this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getBaseAmount())),
190+
'amount' => $this->_registerJsPrice(
191+
$this->_convertPrice($finalPrice->getAmount()->getBaseAmount())
192+
),
192193
],
193194
'finalPrice' => [
194195
'amount' => $this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getValue())),
@@ -197,7 +198,6 @@ public function getJsonConfig()
197198
'productId' => $currentProduct->getId(),
198199
'chooseText' => __('Choose an Option...'),
199200
'images' => isset($options['images']) ? $options['images'] : [],
200-
'baseImage' => $options['baseImage'],
201201
];
202202

203203
if ($currentProduct->hasPreconfiguredValues() && !empty($attributesData['defaultValues'])) {

0 commit comments

Comments
 (0)