Skip to content

Commit 0d59cf4

Browse files
authored
Merge pull request #132 from magento-troll/sprint14
EPAM - Sprint 14
2 parents 4d8ec01 + fc00bcd commit 0d59cf4

File tree

9 files changed

+193
-12
lines changed

9 files changed

+193
-12
lines changed

app/code/Magento/Customer/view/frontend/templates/widget/name.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $middle = $block->showMiddlename();
3030
$suffix = $block->showSuffix();
3131
?>
3232

33-
<?php if ($prefix || $middle || $suffix && !$block->getNoWrap()): ?>
33+
<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
3434
<div class="field required fullname <?php /* @escapeNotVerified */ echo $block->getContainerClassName() ?>">
3535
<label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('firstname') ?>" class="label">
3636
<span><?php /* @escapeNotVerified */ echo __('Name') ?></span>
@@ -139,7 +139,7 @@ $suffix = $block->showSuffix();
139139
</div>
140140
<?php endif; ?>
141141

142-
<?php if ($prefix || $middle || $suffix && !$block->getNoWrap()): ?>
142+
<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
143143
</div>
144144
</fieldset>
145145
</div>

app/code/Magento/Sales/Block/Order/History.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Sales\Block\Order;
77

8+
use \Magento\Framework\App\ObjectManager;
9+
use \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
10+
811
/**
912
* Sales order history block
1013
*/
@@ -33,6 +36,11 @@ class History extends \Magento\Framework\View\Element\Template
3336
/** @var \Magento\Sales\Model\ResourceModel\Order\Collection */
3437
protected $orders;
3538

39+
/**
40+
* @var CollectionFactoryInterface
41+
*/
42+
private $orderCollectionFactory;
43+
3644
/**
3745
* @param \Magento\Framework\View\Element\Template\Context $context
3846
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
@@ -62,6 +70,19 @@ protected function _construct()
6270
$this->pageConfig->getTitle()->set(__('My Orders'));
6371
}
6472

73+
/**
74+
* @return CollectionFactoryInterface
75+
*
76+
* @deprecated
77+
*/
78+
private function getOrderCollectionFactory()
79+
{
80+
if ($this->orderCollectionFactory === null) {
81+
$this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class);
82+
}
83+
return $this->orderCollectionFactory;
84+
}
85+
6586
/**
6687
* @return bool|\Magento\Sales\Model\ResourceModel\Order\Collection
6788
*/
@@ -71,11 +92,8 @@ public function getOrders()
7192
return false;
7293
}
7394
if (!$this->orders) {
74-
$this->orders = $this->_orderCollectionFactory->create()->addFieldToSelect(
95+
$this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
7596
'*'
76-
)->addFieldToFilter(
77-
'customer_id',
78-
$customerId
7997
)->addFieldToFilter(
8098
'status',
8199
['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Block\Order\History;
7+
8+
/**
9+
* Sales order history extra container block
10+
*/
11+
class Container extends \Magento\Framework\View\Element\Template
12+
{
13+
/**
14+
* @var \Magento\Sales\Api\Data\OrderInterface
15+
*/
16+
private $order;
17+
18+
/**
19+
* Set order
20+
*
21+
* @param \Magento\Sales\Api\Data\OrderInterface $order
22+
* @return $this
23+
*/
24+
public function setOrder(\Magento\Sales\Api\Data\OrderInterface $order)
25+
{
26+
$this->order = $order;
27+
return $this;
28+
}
29+
30+
/**
31+
* Get order
32+
*
33+
* @return \Magento\Sales\Api\Data\OrderInterface
34+
*/
35+
private function getOrder()
36+
{
37+
return $this->order;
38+
}
39+
40+
/**
41+
* Here we set an order for children during retrieving their HTML
42+
*
43+
* @param string $alias
44+
* @param bool $useCache
45+
* @return string
46+
* @throws \Magento\Framework\Exception\LocalizedException
47+
*/
48+
public function getChildHtml($alias = '', $useCache = false)
49+
{
50+
$layout = $this->getLayout();
51+
if ($layout) {
52+
$name = $this->getNameInLayout();
53+
foreach ($layout->getChildBlocks($name) as $child) {
54+
$child->setOrder($this->getOrder());
55+
}
56+
}
57+
return parent::getChildHtml($alias, $useCache);
58+
}
59+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\ResourceModel\Order;
8+
9+
/**
10+
* Class CollectionFactory
11+
*/
12+
class CollectionFactory implements CollectionFactoryInterface
13+
{
14+
/**
15+
* Object Manager instance
16+
*
17+
* @var \Magento\Framework\ObjectManagerInterface
18+
*/
19+
private $objectManager = null;
20+
21+
/**
22+
* Instance name to create
23+
*
24+
* @var string
25+
*/
26+
private $instanceName = null;
27+
28+
/**
29+
* Factory constructor
30+
*
31+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
32+
* @param string $instanceName
33+
*/
34+
public function __construct(
35+
\Magento\Framework\ObjectManagerInterface $objectManager,
36+
$instanceName = '\\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection'
37+
) {
38+
$this->objectManager = $objectManager;
39+
$this->instanceName = $instanceName;
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function create($customerId = null)
46+
{
47+
/** @var \Magento\Sales\Model\ResourceModel\Order\Collection $collection */
48+
$collection = $this->objectManager->create($this->instanceName);
49+
50+
if ($customerId) {
51+
$collection->addFieldToFilter('customer_id', $customerId);
52+
}
53+
54+
return $collection;
55+
}
56+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\ResourceModel\Order;
8+
9+
/**
10+
* Class CollectionFactoryInterface
11+
*/
12+
interface CollectionFactoryInterface
13+
{
14+
/**
15+
* Create class instance with specified parameters
16+
*
17+
* @param int $customerId
18+
* @return \Magento\Sales\Model\ResourceModel\Order\Collection
19+
*/
20+
public function create($customerId = null);
21+
}

app/code/Magento/Sales/Test/Unit/Block/Order/HistoryTest.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
2222
*/
2323
protected $orderCollectionFactory;
2424

25+
/**
26+
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $orderCollectionFactoryInterface;
29+
30+
/**
31+
* @var \Magento\Framework\App\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $objectManager;
34+
2535
/**
2636
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
2737
*/
@@ -48,6 +58,14 @@ protected function setUp()
4858
$this->orderCollectionFactory =
4959
$this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\CollectionFactory')
5060
->disableOriginalConstructor()->setMethods(['create'])->getMock();
61+
$this->orderCollectionFactoryInterface =
62+
$this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)
63+
->disableOriginalConstructor()->setMethods(['create'])->getMock();
64+
$this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false);
65+
$this->objectManager->expects($this->any())
66+
->method('get')
67+
->will($this->returnValue($this->orderCollectionFactoryInterface));
68+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManager);
5169

5270
$this->customerSession = $this->getMockBuilder('Magento\Customer\Model\Session')
5371
->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock();
@@ -94,18 +112,14 @@ public function testConstructMethod()
94112
->with($this->equalTo('*'))
95113
->will($this->returnSelf());
96114
$orderCollection->expects($this->at(1))
97-
->method('addFieldToFilter')
98-
->with('customer_id', $this->equalTo($customerId))
99-
->will($this->returnSelf());
100-
$orderCollection->expects($this->at(2))
101115
->method('addFieldToFilter')
102116
->with('status', $this->equalTo(['in' => $statuses]))
103117
->will($this->returnSelf());
104-
$orderCollection->expects($this->at(3))
118+
$orderCollection->expects($this->at(2))
105119
->method('setOrder')
106120
->with('created_at', 'desc')
107121
->will($this->returnSelf());
108-
$this->orderCollectionFactory->expects($this->atLeastOnce())
122+
$this->orderCollectionFactoryInterface->expects($this->atLeastOnce())
109123
->method('create')
110124
->will($this->returnValue($orderCollection));
111125
$this->pageConfig->expects($this->atLeastOnce())

app/code/Magento/Sales/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<preference for="Magento\Sales\Model\Spi\ShipmentResourceInterface" type="Magento\Sales\Model\ResourceModel\Order\Shipment"/>
8181
<preference for="Magento\Sales\Model\Spi\ShipmentTrackResourceInterface" type="Magento\Sales\Model\ResourceModel\Order\Shipment\Track"/>
8282
<preference for="Magento\Sales\Model\Spi\TransactionResourceInterface" type="Magento\Sales\Model\ResourceModel\Order\Payment\Transaction"/>
83+
<preference for="Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface" type="Magento\Sales\Model\ResourceModel\Order\CollectionFactory"/>
8384
<type name="Magento\Sales\Model\ResourceModel\Report" shared="false"/>
8485
<type name="Magento\Sales\Model\Order\Pdf\Config\Reader">
8586
<arguments>

app/code/Magento/Sales/view/frontend/layout/sales_order_history.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
<referenceContainer name="content">
1212
<block class="Magento\Sales\Block\Order\History" name="sales.order.history" cacheable="false">
1313
<container name="sales.order.history.info" as="info" label="Order History Info"/>
14+
<container name="sales.order.history.extra.column.header" as="extra.column.header" label="Order History Extra Column Header"/>
15+
<block class="Magento\Sales\Block\Order\History\Container"
16+
name="sales.order.history.extra.container" as="extra.container">
17+
<block class="Magento\Framework\View\Element\Template"
18+
name="sales.order.history.extra.container.data" as="extra.container.data"/>
19+
</block>
1420
</block>
1521
<block class="Magento\Customer\Block\Account\Dashboard" name="customer.account.link.back" template="account/link/back.phtml" cacheable="false"/>
1622
</referenceContainer>

app/code/Magento/Sales/view/frontend/templates/order/history.phtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<tr>
1818
<th scope="col" class="col id"><?php /* @escapeNotVerified */ echo __('Order #') ?></th>
1919
<th scope="col" class="col date"><?php /* @escapeNotVerified */ echo __('Date') ?></th>
20+
<?php /* @noEscape */ echo $block->getChildHtml('extra.column.header');?>
2021
<th scope="col" class="col shipping"><?php /* @escapeNotVerified */ echo __('Ship To') ?></th>
2122
<th scope="col" class="col total"><?php /* @escapeNotVerified */ echo __('Order Total') ?></th>
2223
<th scope="col" class="col status"><?php /* @escapeNotVerified */ echo __('Status') ?></th>
@@ -28,6 +29,11 @@
2829
<tr>
2930
<td data-th="<?php echo $block->escapeHtml(__('Order #')) ?>" class="col id"><?php /* @escapeNotVerified */ echo $_order->getRealOrderId() ?></td>
3031
<td data-th="<?php echo $block->escapeHtml(__('Date')) ?>" class="col date"><?php /* @escapeNotVerified */ echo $block->formatDate($_order->getCreatedAt()) ?></td>
32+
<?php $extra = $block->getChildBlock('extra.container'); ?>
33+
<?php if ($extra): ?>
34+
<?php $extra->setOrder($_order); ?>
35+
<?php /* @noEscape */ echo $extra->getChildHtml() ?>
36+
<?php endif; ?>
3137
<td data-th="<?php echo $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?php echo $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
3238
<td data-th="<?php echo $block->escapeHtml(__('Order Total')) ?>" class="col total"><?php /* @escapeNotVerified */ echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
3339
<td data-th="<?php echo $block->escapeHtml(__('Status')) ?>" class="col status"><?php /* @escapeNotVerified */ echo $_order->getStatusLabel() ?></td>

0 commit comments

Comments
 (0)