diff --git a/app/code/Magento/Customer/view/frontend/templates/widget/name.phtml b/app/code/Magento/Customer/view/frontend/templates/widget/name.phtml
index f46d111b5b0587d36329fb4ff515da437e9e0ecd..f1f1416c2f4e4bedfd54db3fe4afdb5c56c5317d 100644
--- a/app/code/Magento/Customer/view/frontend/templates/widget/name.phtml
+++ b/app/code/Magento/Customer/view/frontend/templates/widget/name.phtml
@@ -30,7 +30,7 @@ $middle = $block->showMiddlename();
$suffix = $block->showSuffix();
?>
-<?php if ($prefix || $middle || $suffix && !$block->getNoWrap()): ?>
+<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
<div class="field required fullname <?php /* @escapeNotVerified */ echo $block->getContainerClassName() ?>">
<label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('firstname') ?>" class="label">
<span><?php /* @escapeNotVerified */ echo __('Name') ?></span>
@@ -139,7 +139,7 @@ $suffix = $block->showSuffix();
</div>
<?php endif; ?>
- <?php if ($prefix || $middle || $suffix && !$block->getNoWrap()): ?>
+ <?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
</div>
</fieldset>
</div>
diff --git a/app/code/Magento/Sales/Block/Order/History.php b/app/code/Magento/Sales/Block/Order/History.php
index 683234666262a7d2cc86b70a8d2c64d4b824b48a..9b212d40bfa6af7937f14aa31746b84a7ab507db 100644
--- a/app/code/Magento/Sales/Block/Order/History.php
+++ b/app/code/Magento/Sales/Block/Order/History.php
@@ -5,6 +5,9 @@
*/
namespace Magento\Sales\Block\Order;
+use \Magento\Framework\App\ObjectManager;
+use \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
+
/**
* Sales order history block
*/
@@ -33,6 +36,11 @@ class History extends \Magento\Framework\View\Element\Template
/** @var \Magento\Sales\Model\ResourceModel\Order\Collection */
protected $orders;
+ /**
+ * @var CollectionFactoryInterface
+ */
+ private $orderCollectionFactory;
+
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
@@ -62,6 +70,19 @@ class History extends \Magento\Framework\View\Element\Template
$this->pageConfig->getTitle()->set(__('My Orders'));
}
+ /**
+ * @return CollectionFactoryInterface
+ *
+ * @deprecated
+ */
+ private function getOrderCollectionFactory()
+ {
+ if ($this->orderCollectionFactory === null) {
+ $this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class);
+ }
+ return $this->orderCollectionFactory;
+ }
+
/**
* @return bool|\Magento\Sales\Model\ResourceModel\Order\Collection
*/
@@ -71,11 +92,8 @@ class History extends \Magento\Framework\View\Element\Template
return false;
}
if (!$this->orders) {
- $this->orders = $this->_orderCollectionFactory->create()->addFieldToSelect(
+ $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
'*'
- )->addFieldToFilter(
- 'customer_id',
- $customerId
)->addFieldToFilter(
'status',
['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
diff --git a/app/code/Magento/Sales/Block/Order/History/Container.php b/app/code/Magento/Sales/Block/Order/History/Container.php
new file mode 100644
index 0000000000000000000000000000000000000000..cc20f20ea84c085d62588bca6dfd265e8de224c8
--- /dev/null
+++ b/app/code/Magento/Sales/Block/Order/History/Container.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Sales\Block\Order\History;
+
+/**
+ * Sales order history extra container block
+ */
+class Container extends \Magento\Framework\View\Element\Template
+{
+ /**
+ * @var \Magento\Sales\Api\Data\OrderInterface
+ */
+ private $order;
+
+ /**
+ * Set order
+ *
+ * @param \Magento\Sales\Api\Data\OrderInterface $order
+ * @return $this
+ */
+ public function setOrder(\Magento\Sales\Api\Data\OrderInterface $order)
+ {
+ $this->order = $order;
+ return $this;
+ }
+
+ /**
+ * Get order
+ *
+ * @return \Magento\Sales\Api\Data\OrderInterface
+ */
+ private function getOrder()
+ {
+ return $this->order;
+ }
+
+ /**
+ * Here we set an order for children during retrieving their HTML
+ *
+ * @param string $alias
+ * @param bool $useCache
+ * @return string
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ public function getChildHtml($alias = '', $useCache = false)
+ {
+ $layout = $this->getLayout();
+ if ($layout) {
+ $name = $this->getNameInLayout();
+ foreach ($layout->getChildBlocks($name) as $child) {
+ $child->setOrder($this->getOrder());
+ }
+ }
+ return parent::getChildHtml($alias, $useCache);
+ }
+}
diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFactory.php b/app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFactory.php
new file mode 100644
index 0000000000000000000000000000000000000000..c2b9886e3fa52f54c0ba5f6b1456d5d493631313
--- /dev/null
+++ b/app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFactory.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+namespace Magento\Sales\Model\ResourceModel\Order;
+
+/**
+ * Class CollectionFactory
+ */
+class CollectionFactory implements CollectionFactoryInterface
+{
+ /**
+ * Object Manager instance
+ *
+ * @var \Magento\Framework\ObjectManagerInterface
+ */
+ private $objectManager = null;
+
+ /**
+ * Instance name to create
+ *
+ * @var string
+ */
+ private $instanceName = null;
+
+ /**
+ * Factory constructor
+ *
+ * @param \Magento\Framework\ObjectManagerInterface $objectManager
+ * @param string $instanceName
+ */
+ public function __construct(
+ \Magento\Framework\ObjectManagerInterface $objectManager,
+ $instanceName = '\\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection'
+ ) {
+ $this->objectManager = $objectManager;
+ $this->instanceName = $instanceName;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function create($customerId = null)
+ {
+ /** @var \Magento\Sales\Model\ResourceModel\Order\Collection $collection */
+ $collection = $this->objectManager->create($this->instanceName);
+
+ if ($customerId) {
+ $collection->addFieldToFilter('customer_id', $customerId);
+ }
+
+ return $collection;
+ }
+}
diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFactoryInterface.php b/app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFactoryInterface.php
new file mode 100644
index 0000000000000000000000000000000000000000..27a9a640906b214705833c9f53ef25b157f89802
--- /dev/null
+++ b/app/code/Magento/Sales/Model/ResourceModel/Order/CollectionFactoryInterface.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+namespace Magento\Sales\Model\ResourceModel\Order;
+
+/**
+ * Class CollectionFactoryInterface
+ */
+interface CollectionFactoryInterface
+{
+ /**
+ * Create class instance with specified parameters
+ *
+ * @param int $customerId
+ * @return \Magento\Sales\Model\ResourceModel\Order\Collection
+ */
+ public function create($customerId = null);
+}
diff --git a/app/code/Magento/Sales/Test/Unit/Block/Order/HistoryTest.php b/app/code/Magento/Sales/Test/Unit/Block/Order/HistoryTest.php
index 9e8f325857b6bb551f996de278169272c3c01e39..a4709ed7ccc98695e3a4701b7067646bb4b957e6 100644
--- a/app/code/Magento/Sales/Test/Unit/Block/Order/HistoryTest.php
+++ b/app/code/Magento/Sales/Test/Unit/Block/Order/HistoryTest.php
@@ -22,6 +22,16 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
*/
protected $orderCollectionFactory;
+ /**
+ * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ private $orderCollectionFactoryInterface;
+
+ /**
+ * @var \Magento\Framework\App\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
+ */
+ private $objectManager;
+
/**
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
*/
@@ -48,6 +58,14 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
$this->orderCollectionFactory =
$this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\CollectionFactory')
->disableOriginalConstructor()->setMethods(['create'])->getMock();
+ $this->orderCollectionFactoryInterface =
+ $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)
+ ->disableOriginalConstructor()->setMethods(['create'])->getMock();
+ $this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false);
+ $this->objectManager->expects($this->any())
+ ->method('get')
+ ->will($this->returnValue($this->orderCollectionFactoryInterface));
+ \Magento\Framework\App\ObjectManager::setInstance($this->objectManager);
$this->customerSession = $this->getMockBuilder('Magento\Customer\Model\Session')
->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock();
@@ -94,18 +112,14 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo('*'))
->will($this->returnSelf());
$orderCollection->expects($this->at(1))
- ->method('addFieldToFilter')
- ->with('customer_id', $this->equalTo($customerId))
- ->will($this->returnSelf());
- $orderCollection->expects($this->at(2))
->method('addFieldToFilter')
->with('status', $this->equalTo(['in' => $statuses]))
->will($this->returnSelf());
- $orderCollection->expects($this->at(3))
+ $orderCollection->expects($this->at(2))
->method('setOrder')
->with('created_at', 'desc')
->will($this->returnSelf());
- $this->orderCollectionFactory->expects($this->atLeastOnce())
+ $this->orderCollectionFactoryInterface->expects($this->atLeastOnce())
->method('create')
->will($this->returnValue($orderCollection));
$this->pageConfig->expects($this->atLeastOnce())
diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml
index 209e46c3240b675f32622f3547331856bf87a1eb..78dd17256703ad32b852262899a3b3a6b97545b6 100644
--- a/app/code/Magento/Sales/etc/di.xml
+++ b/app/code/Magento/Sales/etc/di.xml
@@ -80,6 +80,7 @@
<preference for="Magento\Sales\Model\Spi\ShipmentResourceInterface" type="Magento\Sales\Model\ResourceModel\Order\Shipment"/>
<preference for="Magento\Sales\Model\Spi\ShipmentTrackResourceInterface" type="Magento\Sales\Model\ResourceModel\Order\Shipment\Track"/>
<preference for="Magento\Sales\Model\Spi\TransactionResourceInterface" type="Magento\Sales\Model\ResourceModel\Order\Payment\Transaction"/>
+ <preference for="Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface" type="Magento\Sales\Model\ResourceModel\Order\CollectionFactory"/>
<type name="Magento\Sales\Model\ResourceModel\Report" shared="false"/>
<type name="Magento\Sales\Model\Order\Pdf\Config\Reader">
<arguments>
diff --git a/app/code/Magento/Sales/view/frontend/layout/sales_order_history.xml b/app/code/Magento/Sales/view/frontend/layout/sales_order_history.xml
index 85b8a83a198f54facd9d931a684881056e12625c..c4c93b9655aa148ed31fdac6aa94c352faf13e9e 100644
--- a/app/code/Magento/Sales/view/frontend/layout/sales_order_history.xml
+++ b/app/code/Magento/Sales/view/frontend/layout/sales_order_history.xml
@@ -11,6 +11,12 @@
<referenceContainer name="content">
<block class="Magento\Sales\Block\Order\History" name="sales.order.history" cacheable="false">
<container name="sales.order.history.info" as="info" label="Order History Info"/>
+ <container name="sales.order.history.extra.column.header" as="extra.column.header" label="Order History Extra Column Header"/>
+ <block class="Magento\Sales\Block\Order\History\Container"
+ name="sales.order.history.extra.container" as="extra.container">
+ <block class="Magento\Framework\View\Element\Template"
+ name="sales.order.history.extra.container.data" as="extra.container.data"/>
+ </block>
</block>
<block class="Magento\Customer\Block\Account\Dashboard" name="customer.account.link.back" template="account/link/back.phtml" cacheable="false"/>
</referenceContainer>
diff --git a/app/code/Magento/Sales/view/frontend/templates/order/history.phtml b/app/code/Magento/Sales/view/frontend/templates/order/history.phtml
index b3723d56ac28dc7b85c9fa2fe1a8aa978b780b9a..a57c68d17258fddb1bd0a4d3f2b6da3758ae690b 100644
--- a/app/code/Magento/Sales/view/frontend/templates/order/history.phtml
+++ b/app/code/Magento/Sales/view/frontend/templates/order/history.phtml
@@ -17,6 +17,7 @@
<tr>
<th scope="col" class="col id"><?php /* @escapeNotVerified */ echo __('Order #') ?></th>
<th scope="col" class="col date"><?php /* @escapeNotVerified */ echo __('Date') ?></th>
+ <?php /* @noEscape */ echo $block->getChildHtml('extra.column.header');?>
<th scope="col" class="col shipping"><?php /* @escapeNotVerified */ echo __('Ship To') ?></th>
<th scope="col" class="col total"><?php /* @escapeNotVerified */ echo __('Order Total') ?></th>
<th scope="col" class="col status"><?php /* @escapeNotVerified */ echo __('Status') ?></th>
@@ -28,6 +29,11 @@
<tr>
<td data-th="<?php echo $block->escapeHtml(__('Order #')) ?>" class="col id"><?php /* @escapeNotVerified */ echo $_order->getRealOrderId() ?></td>
<td data-th="<?php echo $block->escapeHtml(__('Date')) ?>" class="col date"><?php /* @escapeNotVerified */ echo $block->formatDate($_order->getCreatedAt()) ?></td>
+ <?php $extra = $block->getChildBlock('extra.container'); ?>
+ <?php if ($extra): ?>
+ <?php $extra->setOrder($_order); ?>
+ <?php /* @noEscape */ echo $extra->getChildHtml() ?>
+ <?php endif; ?>
<td data-th="<?php echo $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?php echo $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : ' ' ?></td>
<td data-th="<?php echo $block->escapeHtml(__('Order Total')) ?>" class="col total"><?php /* @escapeNotVerified */ echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
<td data-th="<?php echo $block->escapeHtml(__('Status')) ?>" class="col status"><?php /* @escapeNotVerified */ echo $_order->getStatusLabel() ?></td>