Skip to content

Commit f361fb7

Browse files
committed
MAGETWO-54963: Extensibility and modularity improvements
- Placeholders added to orders list - Unit test fix
1 parent 3be18f3 commit f361fb7

File tree

9 files changed

+155
-13
lines changed

9 files changed

+155
-13
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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class History extends \Magento\Framework\View\Element\Template
3535

3636
/**
3737
* @param \Magento\Framework\View\Element\Template\Context $context
38-
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
38+
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory
3939
* @param \Magento\Customer\Model\Session $customerSession
4040
* @param \Magento\Sales\Model\Order\Config $orderConfig
4141
* @param array $data
4242
*/
4343
public function __construct(
4444
\Magento\Framework\View\Element\Template\Context $context,
45-
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
45+
\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory,
4646
\Magento\Customer\Model\Session $customerSession,
4747
\Magento\Sales\Model\Order\Config $orderConfig,
4848
array $data = []
@@ -71,11 +71,8 @@ public function getOrders()
7171
return false;
7272
}
7373
if (!$this->orders) {
74-
$this->orders = $this->_orderCollectionFactory->create()->addFieldToSelect(
74+
$this->orders = $this->_orderCollectionFactory->create($customerId)->addFieldToSelect(
7575
'*'
76-
)->addFieldToFilter(
77-
'customer_id',
78-
$customerId
7976
)->addFieldToFilter(
8077
'status',
8178
['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: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,10 @@ public function testConstructMethod()
9494
->with($this->equalTo('*'))
9595
->will($this->returnSelf());
9696
$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))
10197
->method('addFieldToFilter')
10298
->with('status', $this->equalTo(['in' => $statuses]))
10399
->will($this->returnSelf());
104-
$orderCollection->expects($this->at(3))
100+
$orderCollection->expects($this->at(2))
105101
->method('setOrder')
106102
->with('created_at', 'desc')
107103
->will($this->returnSelf());

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)