Skip to content

Commit 62477e3

Browse files
mpalamarmpalamar
authored andcommitted
Merge remote-tracking branch 'mainline/2.1-develop' into chaika-pr1
2 parents 9da1ba8 + f4da450 commit 62477e3

File tree

17 files changed

+707
-111
lines changed

17 files changed

+707
-111
lines changed

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,19 @@ public function setAttributeSetsFilter(array $setIds)
205205
*/
206206
public function setInAllAttributeSetsFilter(array $setIds)
207207
{
208-
foreach ($setIds as $setId) {
209-
$setId = (int)$setId;
210-
if (!$setId) {
211-
continue;
212-
}
213-
$alias = sprintf('entity_attribute_%d', $setId);
214-
$joinCondition = $this->getConnection()->quoteInto(
215-
"{$alias}.attribute_id = main_table.attribute_id AND {$alias}.attribute_set_id =?",
216-
$setId
217-
);
218-
$this->join([$alias => 'eav_entity_attribute'], $joinCondition, 'attribute_id');
208+
if (!empty($setIds)) {
209+
$this->getSelect()
210+
->join(
211+
['entity_attribute' => $this->getTable('eav_entity_attribute')],
212+
'entity_attribute.attribute_id = main_table.attribute_id',
213+
['count' => new \Zend_Db_Expr('COUNT(*)')]
214+
)
215+
->where(
216+
'entity_attribute.attribute_set_id IN (?)',
217+
$setIds
218+
)
219+
->group('entity_attribute.attribute_id')
220+
->having('count = ' . count($setIds));
219221
}
220222

221223
//$this->getSelect()->distinct(true);
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
namespace Magento\Eav\Test\Unit\Model\ResourceModel\Entity\Attribute;
9+
10+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
13+
/**
14+
* Test for \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection class.
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
*/
18+
class CollectionTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
22+
*/
23+
private $model;
24+
25+
/**
26+
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $entityFactoryMock;
29+
30+
/**
31+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $loggerMock;
34+
35+
/**
36+
* @var \Magento\Framework\Data\Collection\Db\FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $fetchStrategyMock;
39+
40+
/**
41+
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $eventManagerMock;
44+
45+
/**
46+
* @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
private $eavConfigMock;
49+
50+
/**
51+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $storeManagerMock;
54+
55+
/**
56+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $connectionMock;
59+
60+
/**
61+
* @var \Magento\Framework\Model\ResourceModel\Db\AbstractDb|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $resourceMock;
64+
65+
/**
66+
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
private $selectMock;
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
protected function setUp()
74+
{
75+
$this->entityFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\EntityFactory::class)
76+
->disableOriginalConstructor()
77+
->getMock();
78+
79+
$this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
83+
$this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)
84+
->disableOriginalConstructor()
85+
->getMock();
86+
87+
$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
88+
->disableOriginalConstructor()
89+
->getMock();
90+
91+
$this->eavConfigMock = $this->getMockBuilder(\Magento\Eav\Model\Config::class)
92+
->disableOriginalConstructor()
93+
->getMock();
94+
95+
$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
96+
->disableOriginalConstructor()
97+
->getMock();
98+
99+
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
100+
->disableOriginalConstructor()
101+
->getMock();
102+
103+
$this->resourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
104+
->setMethods(['__wakeup', 'getConnection', 'getMainTable', 'getTable'])
105+
->disableOriginalConstructor()
106+
->getMockForAbstractClass();
107+
108+
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
109+
$this->resourceMock->expects($this->any())->method('getMainTable')->willReturn('eav_entity_attribute');
110+
111+
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
112+
->disableOriginalConstructor()
113+
->getMock();
114+
115+
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);
116+
117+
$objectManager = new ObjectManager($this);
118+
$this->model = $objectManager->getObject(
119+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class,
120+
[
121+
'entityFactory' => $this->entityFactoryMock,
122+
'logger' => $this->loggerMock,
123+
'fetchStrategy' => $this->fetchStrategyMock,
124+
'eventManager' => $this->eventManagerMock,
125+
'eavConfig' => $this->eavConfigMock,
126+
'connection' => $this->connectionMock,
127+
'resource' => $this->resourceMock,
128+
]
129+
);
130+
}
131+
132+
/**
133+
* Test method \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::setInAllAttributeSetsFilter
134+
*
135+
* @return void
136+
*/
137+
public function testSetInAllAttributeSetsFilter()
138+
{
139+
$setIds = [1, 2, 3];
140+
141+
$this->selectMock->expects($this->atLeastOnce())
142+
->method('where')
143+
->with('entity_attribute.attribute_set_id IN (?)', $setIds)
144+
->willReturnSelf();
145+
$this->selectMock->expects($this->atLeastOnce())->method('join')->with(
146+
['entity_attribute' => $this->model->getTable('eav_entity_attribute')],
147+
'entity_attribute.attribute_id = main_table.attribute_id',
148+
['count' => new \Zend_Db_Expr('COUNT(*)')]
149+
)->willReturnSelf();
150+
151+
$this->selectMock->expects($this->atLeastOnce())->method('group')->with('entity_attribute.attribute_id')
152+
->willReturnSelf();
153+
154+
$this->selectMock->expects($this->atLeastOnce())->method('having')->with('count = ' . count($setIds))
155+
->willReturnSelf();
156+
157+
$this->model->setInAllAttributeSetsFilter($setIds);
158+
}
159+
}

app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,105 @@
44
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
78
namespace Magento\Sales\Controller\Adminhtml\Order;
89

9-
class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Backend\Model\View\Result\Redirect;
12+
use Magento\Directory\Model\RegionFactory;
13+
use Magento\Sales\Api\OrderManagementInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Api\Data\OrderAddressInterface;
16+
use Magento\Sales\Controller\Adminhtml\Order;
17+
use Magento\Sales\Model\Order\Address as ModelOrderAddress;
18+
use Psr\Log\LoggerInterface;
19+
use Magento\Framework\Registry;
20+
use Magento\Framework\App\Response\Http\FileFactory;
21+
use Magento\Framework\Translate\InlineInterface;
22+
use Magento\Framework\View\Result\PageFactory;
23+
use Magento\Framework\Controller\Result\JsonFactory;
24+
use Magento\Framework\View\Result\LayoutFactory;
25+
use Magento\Framework\Controller\Result\RawFactory;
26+
use Magento\Framework\Exception\LocalizedException;
27+
use Magento\Framework\App\ObjectManager;
28+
29+
/**
30+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
31+
*/
32+
class AddressSave extends Order
1033
{
1134
/**
1235
* Authorization level of a basic admin session
1336
*
1437
* @see _isAllowed()
1538
*/
1639
const ADMIN_RESOURCE = 'Magento_Sales::actions_edit';
40+
41+
/**
42+
* @var RegionFactory
43+
*/
44+
private $regionFactory;
45+
46+
/**
47+
* @param Context $context
48+
* @param Registry $coreRegistry
49+
* @param FileFactory $fileFactory
50+
* @param InlineInterface $translateInline
51+
* @param PageFactory $resultPageFactory
52+
* @param JsonFactory $resultJsonFactory
53+
* @param LayoutFactory $resultLayoutFactory
54+
* @param RawFactory $resultRawFactory
55+
* @param OrderManagementInterface $orderManagement
56+
* @param OrderRepositoryInterface $orderRepository
57+
* @param LoggerInterface $logger
58+
* @param RegionFactory|null $regionFactory
59+
*
60+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
61+
*/
62+
public function __construct(
63+
Context $context,
64+
Registry $coreRegistry,
65+
FileFactory $fileFactory,
66+
InlineInterface $translateInline,
67+
PageFactory $resultPageFactory,
68+
JsonFactory $resultJsonFactory,
69+
LayoutFactory $resultLayoutFactory,
70+
RawFactory $resultRawFactory,
71+
OrderManagementInterface $orderManagement,
72+
OrderRepositoryInterface $orderRepository,
73+
LoggerInterface $logger,
74+
RegionFactory $regionFactory = null
75+
) {
76+
$this->regionFactory = $regionFactory ?: ObjectManager::getInstance()->get(RegionFactory::class);
77+
parent::__construct(
78+
$context,
79+
$coreRegistry,
80+
$fileFactory,
81+
$translateInline,
82+
$resultPageFactory,
83+
$resultJsonFactory,
84+
$resultLayoutFactory,
85+
$resultRawFactory,
86+
$orderManagement,
87+
$orderRepository,
88+
$logger
89+
);
90+
}
1791

1892
/**
1993
* Save order address
2094
*
21-
* @return \Magento\Backend\Model\View\Result\Redirect
95+
* @return Redirect
2296
*/
2397
public function execute()
2498
{
2599
$addressId = $this->getRequest()->getParam('address_id');
26-
/** @var $address \Magento\Sales\Api\Data\OrderAddressInterface|\Magento\Sales\Model\Order\Address */
27-
$address = $this->_objectManager->create('Magento\Sales\Api\Data\OrderAddressInterface')->load($addressId);
100+
/** @var $address OrderAddressInterface|ModelOrderAddress */
101+
$address = $this->_objectManager->create(
102+
OrderAddressInterface::class
103+
)->load($addressId);
28104
$data = $this->getRequest()->getPostValue();
105+
$data = $this->updateRegionData($data);
29106
$resultRedirect = $this->resultRedirectFactory->create();
30107
if ($data && $address->getId()) {
31108
$address->addData($data);
@@ -38,15 +115,34 @@ public function execute()
38115
]
39116
);
40117
$this->messageManager->addSuccess(__('You updated the order address.'));
118+
41119
return $resultRedirect->setPath('sales/*/view', ['order_id' => $address->getParentId()]);
42-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
120+
} catch (LocalizedException $e) {
43121
$this->messageManager->addError($e->getMessage());
44122
} catch (\Exception $e) {
45123
$this->messageManager->addException($e, __('We can\'t update the order address right now.'));
46124
}
125+
47126
return $resultRedirect->setPath('sales/*/address', ['address_id' => $address->getId()]);
48127
} else {
49128
return $resultRedirect->setPath('sales/*/');
50129
}
51130
}
131+
132+
/**
133+
* Update region data
134+
*
135+
* @param array $attributeValues
136+
* @return array
137+
*/
138+
private function updateRegionData($attributeValues)
139+
{
140+
if (!empty($attributeValues['region_id'])) {
141+
$newRegion = $this->regionFactory->create()->load($attributeValues['region_id']);
142+
$attributeValues['region_code'] = $newRegion->getCode();
143+
$attributeValues['region'] = $newRegion->getDefaultName();
144+
}
145+
146+
return $attributeValues;
147+
}
52148
}

app/code/Magento/Sales/Model/Order/Shipment.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ public function register()
257257
if (!$item->getOrderItem()->isDummy(true)) {
258258
$totalQty += $item->getQty();
259259
}
260-
} else {
261-
$item->isDeleted(true);
262260
}
263261
}
264262

0 commit comments

Comments
 (0)