Skip to content

Commit bf52401

Browse files
committed
Fixed Bundle Options Issue
1 parent a961bdd commit bf52401

File tree

2 files changed

+76
-33
lines changed

2 files changed

+76
-33
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Catalog\Model\Product\Type\AbstractType;
99
use Magento\Framework\Serialize\Serializer\Json;
10+
use Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory;
11+
use Magento\Sales\Api\Data\OrderItemInterface;
1012

1113
/**
1214
* Order item render block
@@ -20,22 +22,31 @@ class Renderer extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer
2022
*/
2123
private $serializer;
2224

25+
/**
26+
* @var CollectionFactory
27+
*/
28+
private $itemCollectionFactory;
29+
2330
/**
2431
* @param \Magento\Framework\View\Element\Template\Context $context
2532
* @param \Magento\Framework\Stdlib\StringUtils $string
2633
* @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
2734
* @param array $data
2835
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
36+
* @param \Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory $itemCollectionFactory
2937
*/
3038
public function __construct(
3139
\Magento\Framework\View\Element\Template\Context $context,
3240
\Magento\Framework\Stdlib\StringUtils $string,
3341
\Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
3442
array $data = [],
35-
Json $serializer = null
43+
Json $serializer = null,
44+
CollectionFactory $itemCollectionFactory = null
3645
) {
3746
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
3847
->get(Json::class);
48+
$this->itemCollectionFactory = $itemCollectionFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
49+
->get(CollectionFactory::class);
3950

4051
parent::__construct($context, $string, $productOptionFactory, $data);
4152
}
@@ -221,4 +232,34 @@ public function getItemPrice($item)
221232
$block->setItem($item);
222233
return $block->toHtml();
223234
}
235+
236+
/**
237+
* Get Bundle Order Item Collection.
238+
*
239+
* @param int $orderId
240+
* @param int $parentId
241+
*
242+
* @return array|null
243+
*/
244+
public function getOrderItems(int $orderId, int $parentId): ?array
245+
{
246+
$collection = $this->itemCollectionFactory->create();
247+
$collection->setOrderFilter($orderId);
248+
$collection->addFieldToFilter(
249+
[OrderItemInterface::ITEM_ID, OrderItemInterface::PARENT_ITEM_ID],
250+
[
251+
['eq' => $parentId],
252+
['eq' => $parentId]
253+
]
254+
);
255+
256+
$items = [];
257+
258+
foreach ($collection ?? [] as $item) {
259+
$items[] = $item;
260+
}
261+
$collection->clear();
262+
263+
return $items;
264+
}
224265
}

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

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,47 @@
66
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
77
/** @var $block \Magento\Bundle\Block\Sales\Order\Items\Renderer */
88
$parentItem = $block->getItem();
9-
$items = array_merge([$parentItem], $parentItem->getChildrenItems());
9+
$items = $block->getOrderItems((int)$parentItem->getOrderId(), (int)$parentItem->getId());
10+
1011
$index = 0;
1112
$prevOptionId = '';
1213
?>
1314

14-
<?php foreach ($items as $item) : ?>
15+
<?php foreach ($items as $item): ?>
1516

1617
<?php if ($block->getItemOptions()
1718
|| $parentItem->getDescription()
1819
|| $this->helper(Magento\GiftMessage\Helper\Message::class)->isMessagesAllowed('order_item', $parentItem)
19-
&& $parentItem->getGiftMessageId()) : ?>
20+
&& $parentItem->getGiftMessageId()): ?>
2021
<?php $showLastRow = true; ?>
21-
<?php else : ?>
22+
<?php else: ?>
2223
<?php $showLastRow = false; ?>
2324
<?php endif; ?>
2425

25-
<?php if ($item->getParentItem()) : ?>
26+
<?php if ($item->getParentItem()): ?>
2627
<?php $attributes = $block->getSelectionAttributes($item) ?>
27-
<?php if ($prevOptionId != $attributes['option_id']) : ?>
28+
29+
<?php if (isset($attributes['option_id']) && $prevOptionId != $attributes['option_id']): ?>
2830
<tr class="options-label">
2931
<td class="col label" colspan="5"><?= $block->escapeHtml($attributes['option_label']); ?></td>
3032
</tr>
3133
<?php $prevOptionId = $attributes['option_id'] ?>
3234
<?php endif; ?>
3335
<?php endif; ?>
3436
<tr id="order-item-row-<?= /* @noEscape */ $item->getId() ?>"
35-
class="<?php if ($item->getParentItem()) : ?>
37+
class="<?php if ($item->getParentItem()): ?>
3638
item-options-container
37-
<?php else : ?>
39+
<?php else: ?>
3840
item-parent
3941
<?php endif; ?>"
40-
<?php if ($item->getParentItem()) : ?>
41-
data-th="<?= $block->escapeHtmlAttr($attributes['option_label']); ?>"
42+
<?php if ($item->getParentItem()): ?>
43+
data-th="<?= $block->escapeHtmlAttr($attributes['option_label'] ?? ''); ?>"
4244
<?php endif; ?>>
43-
<?php if (!$item->getParentItem()) : ?>
45+
<?php if (!$item->getParentItem()): ?>
4446
<td class="col name" data-th="<?= $block->escapeHtmlAttr(__('Product Name')); ?>">
4547
<strong class="product name product-item-name"><?= $block->escapeHtml($item->getName()); ?></strong>
4648
</td>
47-
<?php else : ?>
49+
<?php else: ?>
4850
<td class="col value" data-th="<?= $block->escapeHtmlAttr(__('Product Name')); ?>">
4951
<?= $block->getValueHtml($item); ?>
5052
</td>
@@ -53,82 +55,82 @@ $prevOptionId = '';
5355
<?= /* @noEscape */ $block->prepareSku($item->getSku()); ?>
5456
</td>
5557
<td class="col price" data-th="<?= $block->escapeHtmlAttr(__('Price')); ?>">
56-
<?php if (!$item->getParentItem()) : ?>
58+
<?php if (!$item->getParentItem()): ?>
5759
<?= /* @noEscape */ $block->getItemPriceHtml(); ?>
58-
<?php else : ?>
60+
<?php else: ?>
5961
&nbsp;
6062
<?php endif; ?>
6163
</td>
6264
<td class="col qty" data-th="<?= $block->escapeHtmlAttr(__('Quantity')); ?>">
6365
<?php if (($item->getParentItem() && $block->isChildCalculated()) ||
6466
(!$item->getParentItem() && !$block->isChildCalculated()) ||
65-
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())) : ?>
67+
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())): ?>
6668
<ul class="items-qty">
6769
<?php endif; ?>
6870
<?php if (($item->getParentItem() && $block->isChildCalculated()) ||
69-
(!$item->getParentItem() && !$block->isChildCalculated())) : ?>
70-
<?php if ($item->getQtyOrdered() > 0) : ?>
71+
(!$item->getParentItem() && !$block->isChildCalculated())): ?>
72+
<?php if ($item->getQtyOrdered() > 0): ?>
7173
<li class="item">
7274
<span class="title"><?= $block->escapeHtml(__('Ordered')); ?></span>
7375
<span class="content"><?= /* @noEscape */ $item->getQtyOrdered() * 1; ?></span>
7476
</li>
7577
<?php endif; ?>
76-
<?php if ($item->getQtyShipped() > 0 && !$block->isShipmentSeparately()) : ?>
78+
<?php if ($item->getQtyShipped() > 0 && !$block->isShipmentSeparately()): ?>
7779
<li class="item">
7880
<span class="title"><?= $block->escapeHtml(__('Shipped')); ?></span>
7981
<span class="content"><?= /* @noEscape */ $item->getQtyShipped() * 1; ?></span>
8082
</li>
8183
<?php endif; ?>
82-
<?php if ($item->getQtyCanceled() > 0) : ?>
84+
<?php if ($item->getQtyCanceled() > 0): ?>
8385
<li class="item">
8486
<span class="title"><?= $block->escapeHtml(__('Canceled')); ?></span>
8587
<span class="content"><?= /* @noEscape */ $item->getQtyCanceled() * 1; ?></span>
8688
</li>
8789
<?php endif; ?>
88-
<?php if ($item->getQtyRefunded() > 0) : ?>
90+
<?php if ($item->getQtyRefunded() > 0): ?>
8991
<li class="item">
9092
<span class="title"><?= $block->escapeHtml(__('Refunded')); ?></span>
9193
<span class="content"><?= /* @noEscape */ $item->getQtyRefunded() * 1; ?></span>
9294
</li>
9395
<?php endif; ?>
94-
<?php elseif ($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately()) : ?>
96+
<?php elseif ($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately()): ?>
9597
<li class="item">
9698
<span class="title"><?= $block->escapeHtml(__('Shipped')); ?></span>
9799
<span class="content"><?= /* @noEscape */ $item->getQtyShipped() * 1; ?></span>
98100
</li>
99-
<?php else : ?>
101+
<?php else: ?>
100102
<span class="content"><?= /* @noEscape */ $parentItem->getQtyOrdered() * 1; ?></span>
101103
<?php endif; ?>
102104
<?php if (($item->getParentItem() && $block->isChildCalculated()) ||
103105
(!$item->getParentItem() && !$block->isChildCalculated()) ||
104-
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())) :?>
106+
($item->getQtyShipped() > 0 && $item->getParentItem() && $block->isShipmentSeparately())):?>
105107
</ul>
106108
<?php endif; ?>
107109
</td>
108110
<td class="col subtotal" data-th="<?= $block->escapeHtmlAttr(__('Subtotal')) ?>">
109-
<?php if (!$item->getParentItem()) : ?>
111+
<?php if (!$item->getParentItem()): ?>
110112
<?= /* @noEscape */ $block->getItemRowTotalHtml(); ?>
111-
<?php else : ?>
113+
<?php else: ?>
112114
&nbsp;
113115
<?php endif; ?>
114116
</td>
115117
</tr>
116118
<?php endforeach; ?>
117119

118-
<?php if ($showLastRow && (($options = $block->getItemOptions()) || $block->escapeHtml($item->getDescription()))) : ?>
120+
<?php if ($showLastRow && (($options = $block->getItemOptions()) || $block->escapeHtml($item->getDescription()))): ?>
119121
<tr>
120122
<td class="col options" colspan="5">
121-
<?php if ($options = $block->getItemOptions()) : ?>
123+
<?php if ($options = $block->getItemOptions()): ?>
122124
<dl class="item-options">
123-
<?php foreach ($options as $option) : ?>
125+
<?php foreach ($options as $option): ?>
124126
<dt><?= $block->escapeHtml($option['label']) ?></dt>
125-
<?php if (!$block->getPrintStatus()) : ?>
127+
<?php if (!$block->getPrintStatus()): ?>
126128
<?php $formattedOptionValue = $block->getFormatedOptionValue($option) ?>
127-
<dd<?php if (isset($formattedOptionValue['full_view'])) : ?>
129+
<dd<?php if (isset($formattedOptionValue['full_view'])): ?>
128130
class="tooltip wrapper"
129131
<?php endif; ?>>
130132
<?= /* @noEscape */ $formattedOptionValue['value'] ?>
131-
<?php if (isset($formattedOptionValue['full_view'])) : ?>
133+
<?php if (isset($formattedOptionValue['full_view'])): ?>
132134
<div class="tooltip content">
133135
<dl class="item options">
134136
<dt><?= $block->escapeHtml($option['label']); ?></dt>
@@ -137,7 +139,7 @@ $prevOptionId = '';
137139
</div>
138140
<?php endif; ?>
139141
</dd>
140-
<?php else : ?>
142+
<?php else: ?>
141143
<dd><?= $block->escapeHtml((isset($option['print_value']) ?
142144
$option['print_value'] :
143145
$option['value'])); ?>

0 commit comments

Comments
 (0)