Skip to content

Commit 5630fc0

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-369' into L3_Arrows_PR_20220314
2 parents 1a0a0a6 + 09c4efc commit 5630fc0

File tree

7 files changed

+126
-42
lines changed

7 files changed

+126
-42
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\ViewModel\Sales\Order\Items;
9+
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory;
12+
use Magento\Sales\Api\Data\OrderItemInterface;
13+
14+
/**
15+
* ViewModel for Bundle Items
16+
*/
17+
class Renderer implements ArgumentInterface
18+
{
19+
/**
20+
* @var CollectionFactory
21+
*/
22+
private $itemCollectionFactory;
23+
24+
/**
25+
* @param CollectionFactory $itemCollectionFactory
26+
*/
27+
public function __construct(
28+
CollectionFactory $itemCollectionFactory
29+
) {
30+
$this->itemCollectionFactory = $itemCollectionFactory;
31+
}
32+
33+
/**
34+
* Get Bundle Order Item Collection.
35+
*
36+
* @param int $orderId
37+
* @param int $parentId
38+
*
39+
* @return array|null
40+
*/
41+
public function getOrderItems(int $orderId, int $parentId): ?array
42+
{
43+
$collection = $this->itemCollectionFactory->create();
44+
$collection->setOrderFilter($orderId);
45+
$collection->addFieldToFilter(
46+
[OrderItemInterface::ITEM_ID, OrderItemInterface::PARENT_ITEM_ID],
47+
[
48+
['eq' => $parentId],
49+
['eq' => $parentId]
50+
]
51+
);
52+
53+
$items = [];
54+
55+
foreach ($collection ?? [] as $item) {
56+
$items[] = $item;
57+
}
58+
$collection->clear();
59+
60+
return $items;
61+
}
62+
}

app/code/Magento/Bundle/view/frontend/layout/sales_order_item_renderers.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@
1010
<referenceBlock name="sales.order.items.renderers">
1111
<block class="Magento\Bundle\Block\Sales\Order\Items\Renderer" name="sales.order.items.renderers.bundle" as="bundle" template="Magento_Bundle::sales/order/items/renderer.phtml"/>
1212
</referenceBlock>
13+
<referenceBlock name="sales.order.items.renderers.bundle">
14+
<arguments>
15+
<argument name="view_model" xsi:type="object">Magento\Bundle\ViewModel\Sales\Order\Items\Renderer</argument>
16+
</arguments>
17+
</referenceBlock>
1318
</body>
1419
</page>

app/code/Magento/Bundle/view/frontend/layout/sales_order_print_renderers.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@
1010
<referenceBlock name="sales.order.print.renderers">
1111
<block class="Magento\Bundle\Block\Sales\Order\Items\Renderer" name="sales.order.print.renderers.bundle" as="bundle" template="Magento_Bundle::sales/order/items/renderer.phtml"/>
1212
</referenceBlock>
13+
<referenceBlock name="sales.order.print.renderers.bundle">
14+
<arguments>
15+
<argument name="view_model" xsi:type="object">Magento\Bundle\ViewModel\Sales\Order\Items\Renderer</argument>
16+
</arguments>
17+
</referenceBlock>
1318
</body>
1419
</page>

app/code/Magento/Bundle/view/frontend/templates/sales/order/items/renderer.phtml

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,51 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
6+
// phpcs:disable Magento2.Templates.ThisInTemplate
77
/** @var $block \Magento\Bundle\Block\Sales\Order\Items\Renderer */
8+
/** @var $viewModel \Magento\Bundle\ViewModel\Sales\Order\Items\Renderer */
89
$parentItem = $block->getItem();
9-
$items = array_merge([$parentItem], $parentItem->getChildrenItems());
10+
$viewModel = $block->getViewModel();
11+
$items = $viewModel->getOrderItems((int)$parentItem->getOrderId(), (int)$parentItem->getId());
1012
$index = 0;
1113
$prevOptionId = '';
1214
?>
1315

14-
<?php foreach ($items as $item) : ?>
16+
<?php foreach ($items as $item): ?>
1517

1618
<?php if ($block->getItemOptions()
1719
|| $parentItem->getDescription()
1820
|| $this->helper(Magento\GiftMessage\Helper\Message::class)->isMessagesAllowed('order_item', $parentItem)
19-
&& $parentItem->getGiftMessageId()) : ?>
21+
&& $parentItem->getGiftMessageId()): ?>
2022
<?php $showLastRow = true; ?>
21-
<?php else : ?>
23+
<?php else: ?>
2224
<?php $showLastRow = false; ?>
2325
<?php endif; ?>
2426

25-
<?php if ($item->getParentItem()) : ?>
27+
<?php if ($item->getParentItem()): ?>
2628
<?php $attributes = $block->getSelectionAttributes($item) ?>
27-
<?php if ($prevOptionId != $attributes['option_id']) : ?>
29+
30+
<?php if (isset($attributes['option_id']) && $prevOptionId != $attributes['option_id']): ?>
2831
<tr class="options-label">
2932
<td class="col label" colspan="5"><?= $block->escapeHtml($attributes['option_label']); ?></td>
3033
</tr>
3134
<?php $prevOptionId = $attributes['option_id'] ?>
3235
<?php endif; ?>
3336
<?php endif; ?>
3437
<tr id="order-item-row-<?= /* @noEscape */ $item->getId() ?>"
35-
class="<?php if ($item->getParentItem()) : ?>
38+
class="<?php if ($item->getParentItem()): ?>
3639
item-options-container
37-
<?php else : ?>
40+
<?php else: ?>
3841
item-parent
3942
<?php endif; ?>"
40-
<?php if ($item->getParentItem()) : ?>
41-
data-th="<?= $block->escapeHtmlAttr($attributes['option_label']); ?>"
43+
<?php if ($item->getParentItem()): ?>
44+
data-th="<?= $block->escapeHtmlAttr($attributes['option_label'] ?? ''); ?>"
4245
<?php endif; ?>>
43-
<?php if (!$item->getParentItem()) : ?>
46+
<?php if (!$item->getParentItem()): ?>
4447
<td class="col name" data-th="<?= $block->escapeHtmlAttr(__('Product Name')); ?>">
4548
<strong class="product name product-item-name"><?= $block->escapeHtml($item->getName()); ?></strong>
4649
</td>
47-
<?php else : ?>
50+
<?php else: ?>
4851
<td class="col value" data-th="<?= $block->escapeHtmlAttr(__('Product Name')); ?>">
4952
<?= $block->getValueHtml($item); ?>
5053
</td>
@@ -53,82 +56,82 @@ $prevOptionId = '';
5356
<?= /* @noEscape */ $block->prepareSku($item->getSku()); ?>
5457
</td>
5558
<td class="col price" data-th="<?= $block->escapeHtmlAttr(__('Price')); ?>">
56-
<?php if (!$item->getParentItem()) : ?>
59+
<?php if (!$item->getParentItem()): ?>
5760
<?= /* @noEscape */ $block->getItemPriceHtml(); ?>
58-
<?php else : ?>
61+
<?php else: ?>
5962
&nbsp;
6063
<?php endif; ?>
6164
</td>
6265
<td class="col qty" data-th="<?= $block->escapeHtmlAttr(__('Quantity')); ?>">
6366
<?php if (($item->getParentItem() && $block->isChildCalculated()) ||
6467
(!$item->getParentItem() && !$block->isChildCalculated()) ||
65-
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())) : ?>
68+
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())): ?>
6669
<ul class="items-qty">
6770
<?php endif; ?>
6871
<?php if (($item->getParentItem() && $block->isChildCalculated()) ||
69-
(!$item->getParentItem() && !$block->isChildCalculated())) : ?>
70-
<?php if ($item->getQtyOrdered() > 0) : ?>
72+
(!$item->getParentItem() && !$block->isChildCalculated())): ?>
73+
<?php if ($item->getQtyOrdered() > 0): ?>
7174
<li class="item">
7275
<span class="title"><?= $block->escapeHtml(__('Ordered')); ?></span>
7376
<span class="content"><?= /* @noEscape */ $item->getQtyOrdered() * 1; ?></span>
7477
</li>
7578
<?php endif; ?>
76-
<?php if ($item->getQtyShipped() > 0 && !$block->isShipmentSeparately()) : ?>
79+
<?php if ($item->getQtyShipped() > 0 && !$block->isShipmentSeparately()): ?>
7780
<li class="item">
7881
<span class="title"><?= $block->escapeHtml(__('Shipped')); ?></span>
7982
<span class="content"><?= /* @noEscape */ $item->getQtyShipped() * 1; ?></span>
8083
</li>
8184
<?php endif; ?>
82-
<?php if ($item->getQtyCanceled() > 0) : ?>
85+
<?php if ($item->getQtyCanceled() > 0): ?>
8386
<li class="item">
8487
<span class="title"><?= $block->escapeHtml(__('Canceled')); ?></span>
8588
<span class="content"><?= /* @noEscape */ $item->getQtyCanceled() * 1; ?></span>
8689
</li>
8790
<?php endif; ?>
88-
<?php if ($item->getQtyRefunded() > 0) : ?>
91+
<?php if ($item->getQtyRefunded() > 0): ?>
8992
<li class="item">
9093
<span class="title"><?= $block->escapeHtml(__('Refunded')); ?></span>
9194
<span class="content"><?= /* @noEscape */ $item->getQtyRefunded() * 1; ?></span>
9295
</li>
9396
<?php endif; ?>
94-
<?php elseif ($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately()) : ?>
97+
<?php elseif ($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately()): ?>
9598
<li class="item">
9699
<span class="title"><?= $block->escapeHtml(__('Shipped')); ?></span>
97100
<span class="content"><?= /* @noEscape */ $item->getQtyShipped() * 1; ?></span>
98101
</li>
99-
<?php else : ?>
102+
<?php else: ?>
100103
<span class="content"><?= /* @noEscape */ $parentItem->getQtyOrdered() * 1; ?></span>
101104
<?php endif; ?>
102105
<?php if (($item->getParentItem() && $block->isChildCalculated()) ||
103106
(!$item->getParentItem() && !$block->isChildCalculated()) ||
104-
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())) :?>
107+
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())):?>
105108
</ul>
106109
<?php endif; ?>
107110
</td>
108111
<td class="col subtotal" data-th="<?= $block->escapeHtmlAttr(__('Subtotal')) ?>">
109-
<?php if (!$item->getParentItem()) : ?>
112+
<?php if (!$item->getParentItem()): ?>
110113
<?= /* @noEscape */ $block->getItemRowTotalHtml(); ?>
111-
<?php else : ?>
114+
<?php else: ?>
112115
&nbsp;
113116
<?php endif; ?>
114117
</td>
115118
</tr>
116119
<?php endforeach; ?>
117120

118-
<?php if ($showLastRow && (($options = $block->getItemOptions()) || $block->escapeHtml($item->getDescription()))) : ?>
121+
<?php if ($showLastRow && (($options = $block->getItemOptions()) || $block->escapeHtml($item->getDescription()))): ?>
119122
<tr>
120123
<td class="col options" colspan="5">
121-
<?php if ($options = $block->getItemOptions()) : ?>
124+
<?php if ($options = $block->getItemOptions()): ?>
122125
<dl class="item-options">
123-
<?php foreach ($options as $option) : ?>
126+
<?php foreach ($options as $option): ?>
124127
<dt><?= $block->escapeHtml($option['label']) ?></dt>
125-
<?php if (!$block->getPrintStatus()) : ?>
128+
<?php if (!$block->getPrintStatus()): ?>
126129
<?php $formattedOptionValue = $block->getFormatedOptionValue($option) ?>
127-
<dd<?php if (isset($formattedOptionValue['full_view'])) : ?>
130+
<dd<?php if (isset($formattedOptionValue['full_view'])): ?>
128131
class="tooltip wrapper"
129132
<?php endif; ?>>
130133
<?= /* @noEscape */ $formattedOptionValue['value'] ?>
131-
<?php if (isset($formattedOptionValue['full_view'])) : ?>
134+
<?php if (isset($formattedOptionValue['full_view'])): ?>
132135
<div class="tooltip content">
133136
<dl class="item options">
134137
<dt><?= $block->escapeHtml($option['label']); ?></dt>
@@ -137,7 +140,7 @@ $prevOptionId = '';
137140
</div>
138141
<?php endif; ?>
139142
</dd>
140-
<?php else : ?>
143+
<?php else: ?>
141144
<dd><?= $block->escapeHtml((isset($option['print_value']) ?
142145
$option['print_value'] :
143146
$option['value'])); ?>

app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderViewSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@
3030
<element name="productQuantityByRow" type="text" parameterized="true" selector="#my-orders-table tbody:nth-of-type({{index}}) td.qty"/>
3131
<element name="productSubtotalByRow" type="text" parameterized="true" selector="#my-orders-table tbody:nth-of-type({{index}}) td.subtotal"/>
3232
<element name="grandTotal" type="text" selector="//tr[@class='grand_total']//td[@data-th='Grand Total']"/>
33+
<element name="pagerLink" type="text" selector=".pager a.page[href*='order_id/{{orderId}}/?p={{pageNumber}}']" parameterized="true"/>
34+
<element name="itemCountOnPage" type="text" selector="#my-orders-table tbody"/>
3335
</section>
3436
</sections>

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828
class Items extends AbstractItems
2929
{
3030
/**
31-
* Core registry
32-
*
3331
* @var Registry
3432
*/
3533
protected $_coreRegistry = null;
3634

3735
/**
38-
* Order items per page.
39-
*
4036
* @var int
4137
*/
4238
private $itemsPerPage;
@@ -148,12 +144,11 @@ public function getOrder()
148144
*/
149145
private function preparePager(AbstractBlock $pagerBlock): void
150146
{
151-
$collectionToPager = $this->createItemsCollection();
147+
$collectionToPager = $this->itemCollection;
152148
$collectionToPager->addFieldToFilter('parent_item_id', ['null' => true]);
153-
$pagerBlock->setCollection($collectionToPager);
154-
155149
$pagerBlock->setLimit($this->itemsPerPage);
156150
$pagerBlock->setAvailableLimit([$this->itemsPerPage]);
151+
$pagerBlock->setCollection($collectionToPager);
157152
$pagerBlock->setShowAmounts($this->isPagerDisplayed());
158153
}
159154

app/code/Magento/Sales/Test/Mftf/Test/StorefrontOrderPagerDisplayedTest.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</annotations>
2121
<before>
2222
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="LoginAsAdmin"/>
23-
23+
2424
<createData entity="_defaultCategory" stepKey="createCategory"/>
2525
<createData entity="SimpleProduct" stepKey="createProduct01">
2626
<requiredEntity createDataKey="createCategory"/>
@@ -247,7 +247,19 @@
247247
<argument name="orderId" value="$createCustomerCart.return$"/>
248248
<argument name="orderNumber" value="$getOrderData.increment_id$"/>
249249
</actionGroup>
250-
250+
251251
<seeElement selector="{{StorefrontCustomerOrderViewSection.pager}}" stepKey="assertPagerIsDisplayed"/>
252+
<executeJS function="var len = document.querySelectorAll('{{StorefrontCustomerOrderViewSection.itemCountOnPage}}').length; return len;" stepKey="orderItemsCountOnFirstPage"/>
253+
<assertEquals stepKey="assertOrderItemsOnFirstPage">
254+
<actualResult type="const">($orderItemsCountOnFirstPage)</actualResult>
255+
<expectedResult type="const">20</expectedResult>
256+
</assertEquals>
257+
<click selector="{{StorefrontCustomerOrderViewSection.pagerLink($createCustomerCart.return$, '2')}}" stepKey="assertPagerLink" />
258+
<waitForPageLoad stepKey="waitForPageLoading"/>
259+
<executeJS function="var len = document.querySelectorAll('{{StorefrontCustomerOrderViewSection.itemCountOnPage}}').length; return len;" stepKey="orderItemsCountOnSecondPage"/>
260+
<assertEquals stepKey="assertOrderItemsOnSecondPage">
261+
<actualResult type="const">($orderItemsCountOnSecondPage)</actualResult>
262+
<expectedResult type="const">1</expectedResult>
263+
</assertEquals>
252264
</test>
253265
</tests>

0 commit comments

Comments
 (0)