Skip to content

Commit 876fab1

Browse files
Merge pull request #1722 from magento-borg/PR2.1_20171115
[Borg] Bug fixes porting for 2.1
2 parents 1c6d457 + 8681609 commit 876fab1

File tree

59 files changed

+2558
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2558
-46
lines changed

app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* "Reset to Defaults" button renderer
1515
*
16+
* @deprecated
1617
* @author Magento Core Team <core@magentocommerce.com>
1718
*/
1819
class Reset extends \Magento\Config\Block\System\Config\Form\Field

app/code/Magento/Backend/Test/Unit/Block/Page/System/Config/Robots/ResetTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
namespace Magento\Backend\Test\Unit\Block\Page\System\Config\Robots;
1111

12+
/**
13+
* Class ResetTest
14+
* @deprecated
15+
* @package Magento\Backend\Test\Unit\Block\Page\System\Config\Robots
16+
*/
1217
class ResetTest extends \PHPUnit_Framework_TestCase
1318
{
1419
/**

app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
use Magento\Framework\App\Filesystem\DirectoryList;
1313

14+
/**
15+
* @deprecated robots.txt file is no longer stored in filesystem. It generates as response on request.
16+
*/
1417
class Robots extends \Magento\Framework\App\Config\Value
1518
{
1619
/**

app/code/Magento/Config/view/adminhtml/templates/page/system/config/robots/reset.phtml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @codingStandardsIgnoreFile
88

99
/**
10+
* @deprecated
1011
* @var $block \Magento\Backend\Block\Page\System\Config\Robots\Reset
1112
* @var $jsonHelper \Magento\Framework\Json\Helper\Data
1213
*/

app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\OfflineShipping\Model\Quote\Address;
77

8-
use Magento\Quote\Model\Quote\Address;
9-
108
class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInterface
119
{
1210
/**
@@ -49,6 +47,8 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
4947
$quote->getCouponCode()
5048
);
5149

50+
$shippingAddress = $quote->getShippingAddress();
51+
$shippingAddress->setFreeShipping(0);
5252
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
5353
foreach ($items as $item) {
5454
if ($item->getNoDiscount()) {
@@ -66,10 +66,14 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
6666
$itemFreeShipping = (bool)$item->getFreeShipping();
6767
$addressFreeShipping = $addressFreeShipping && $itemFreeShipping;
6868

69+
if ($addressFreeShipping && !$item->getAddress()->getFreeShipping()) {
70+
$item->getAddress()->setFreeShipping(true);
71+
}
72+
6973
/** Parent free shipping we apply to all children*/
7074
$this->applyToChildren($item, $itemFreeShipping);
7175
}
72-
return $addressFreeShipping;
76+
return (bool)$quote->getShippingAddress()->getFreeShipping();
7377
}
7478

7579
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\OfflineShipping\Test\Unit\Model\Quote\Address;
8+
9+
class FreeShippingTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\OfflineShipping\Model\Quote\Address\FreeShipping
13+
*/
14+
private $model;
15+
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
18+
*/
19+
private $storeManagerMock;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\OfflineShipping\Model\SalesRule\Calculator
23+
*/
24+
private $calculatorMock;
25+
26+
protected function setUp()
27+
{
28+
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
29+
$this->calculatorMock = $this->getMock(
30+
\Magento\OfflineShipping\Model\SalesRule\Calculator::class,
31+
[],
32+
[],
33+
'',
34+
false
35+
);
36+
37+
$this->model = new \Magento\OfflineShipping\Model\Quote\Address\FreeShipping(
38+
$this->storeManagerMock,
39+
$this->calculatorMock
40+
);
41+
}
42+
43+
public function testIsFreeShippingIfNoItems()
44+
{
45+
$quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false);
46+
$this->assertFalse($this->model->isFreeShipping($quoteMock, []));
47+
}
48+
49+
public function testIsFreeShipping()
50+
{
51+
$storeId = 100;
52+
$websiteId = 200;
53+
$customerGroupId = 300;
54+
$quoteMock = $this->getMock(
55+
\Magento\Quote\Model\Quote::class,
56+
['getShippingAddress', 'getStoreId', 'getCustomerGroupId', 'getCouponCode'],
57+
[],
58+
'',
59+
false
60+
);
61+
$itemMock = $this->getMock(
62+
\Magento\Quote\Model\Quote\Item::class,
63+
[
64+
'getNoDiscount',
65+
'getParentItemId',
66+
'getFreeShipping',
67+
'getAddress',
68+
'isChildrenCalculated',
69+
'getHasChildren',
70+
'getChildren'
71+
],
72+
[],
73+
'',
74+
false
75+
);
76+
77+
$quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
78+
$storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class);
79+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
80+
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);
81+
82+
$quoteMock->expects($this->once())->method('getCustomerGroupId')->willReturn($customerGroupId);
83+
$quoteMock->expects($this->once())->method('getCouponCode')->willReturn(null);
84+
85+
$this->calculatorMock->expects($this->once())
86+
->method('init')
87+
->with($websiteId, $customerGroupId, null)
88+
->willReturnSelf();
89+
90+
$itemMock->expects($this->once())->method('getNoDiscount')->willReturn(false);
91+
$itemMock->expects($this->once())->method('getParentItemId')->willReturn(false);
92+
$this->calculatorMock->expects($this->exactly(2))->method('processFreeShipping')->willReturnSelf();
93+
$itemMock->expects($this->once())->method('getFreeShipping')->willReturn(true);
94+
95+
$addressMock = $this->getMock(
96+
\Magento\Quote\Model\Quote\Address::class,
97+
['getFreeShipping', 'setFreeShipping'],
98+
[],
99+
'',
100+
false
101+
);
102+
$itemAddressMock = $this->getMock(
103+
\Magento\Quote\Model\Quote\Address::class,
104+
['getFreeShipping', 'setFreeShipping'],
105+
[],
106+
'',
107+
false
108+
);
109+
$itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($itemAddressMock);
110+
$itemAddressMock->expects($this->once())->method('getFreeShipping')->willReturn(false);
111+
$addressMock->expects($this->once())->method('getFreeShipping')->willReturn(true);
112+
$addressMock->expects($this->once())->method('setFreeShipping')->with(0)->willReturnSelf();
113+
$itemAddressMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf();
114+
$quoteMock->expects($this->any())->method('getShippingAddress')->willReturn($addressMock);
115+
116+
$itemMock->expects($this->once())->method('getHasChildren')->willReturn(true);
117+
$itemMock->expects($this->once())->method('isChildrenCalculated')->willReturn(true);
118+
119+
$childMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, ['setFreeShipping'], [], '', false);
120+
$childMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf();
121+
$itemMock->expects($this->once())->method('getChildren')->willReturn([$childMock]);
122+
123+
$this->assertTrue($this->model->isFreeShipping($quoteMock, [$itemMock]));
124+
}
125+
}

app/code/Magento/Quote/Model/Quote/Address/ToOrder.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ public function convert(Address $object, $data = [])
7979
$order->setStoreId($object->getQuote()->getStoreId())
8080
->setQuoteId($object->getQuote()->getId())
8181
->setIncrementId($object->getQuote()->getReservedOrderId());
82-
$this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $object->getQuote(), $order);
82+
$this->objectCopyService->copyFieldsetToTarget(
83+
'sales_convert_quote',
84+
'to_order',
85+
$object->getQuote(),
86+
$order
87+
);
8388
$this->eventManager->dispatch(
8489
'sales_convert_quote_to_order',
8590
['order' => $order, 'quote' => $object->getQuote()]
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Robots\Block;
7+
8+
use Magento\Framework\DataObject\IdentityInterface;
9+
use Magento\Framework\View\Element\AbstractBlock;
10+
use Magento\Framework\View\Element\Context;
11+
use Magento\Robots\Model\Config\Value;
12+
use Magento\Robots\Model\Robots;
13+
use Magento\Store\Model\StoreResolver;
14+
15+
/**
16+
* Robots Block Class.
17+
* Prepares base content for robots.txt and implements Page Cache functionality.
18+
*
19+
* @api
20+
*/
21+
class Data extends AbstractBlock implements IdentityInterface
22+
{
23+
/**
24+
* @var Robots
25+
*/
26+
private $robots;
27+
28+
/**
29+
* @var StoreResolver
30+
*/
31+
private $storeResolver;
32+
33+
/**
34+
* @param Context $context
35+
* @param Robots $robots
36+
* @param StoreResolver $storeResolver
37+
* @param array $data
38+
*/
39+
public function __construct(
40+
Context $context,
41+
Robots $robots,
42+
StoreResolver $storeResolver,
43+
array $data = []
44+
) {
45+
$this->robots = $robots;
46+
$this->storeResolver = $storeResolver;
47+
48+
parent::__construct($context, $data);
49+
}
50+
51+
/**
52+
* Retrieve base content for robots.txt file
53+
*
54+
* @return string
55+
*/
56+
protected function _toHtml()
57+
{
58+
return $this->robots->getData() . PHP_EOL;
59+
}
60+
61+
/**
62+
* Get unique page cache identities
63+
*
64+
* @return array
65+
*/
66+
public function getIdentities()
67+
{
68+
return [
69+
Value::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(),
70+
];
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Robots\Controller\Index;
7+
8+
use Magento\Framework\App\Action\Action;
9+
use Magento\Framework\App\Action\Context;
10+
use Magento\Framework\View\Result\Page;
11+
use Magento\Framework\View\Result\PageFactory;
12+
13+
/**
14+
* Processes request to robots.txt file and returns robots.txt content as result
15+
*/
16+
class Index extends Action
17+
{
18+
/**
19+
* @var PageFactory
20+
*/
21+
private $resultPageFactory;
22+
23+
/**
24+
* @param Context $context
25+
* @param PageFactory $resultPageFactory
26+
*/
27+
public function __construct(
28+
Context $context,
29+
PageFactory $resultPageFactory
30+
) {
31+
$this->resultPageFactory = $resultPageFactory;
32+
33+
parent::__construct($context);
34+
}
35+
36+
/**
37+
* Generates robots.txt data and returns it as result
38+
*
39+
* @return Page
40+
*/
41+
public function execute()
42+
{
43+
/** @var Page $resultPage */
44+
$resultPage = $this->resultPageFactory->create(true);
45+
$resultPage->addHandle('robots_index_index');
46+
return $resultPage;
47+
}
48+
}

0 commit comments

Comments
 (0)