# How can we show in admin line items with parentId somehow in relation with parent products?

**URL:** https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677
**Category:** Programming (EN)
**Created:** [4. Mai 2020 um 07:22 UTC](https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677 "2020-05-04T07:22:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![SorinSologics2019](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SorinSologics2019](https://forum.shopware.com/u/SorinSologics2019)
#### Post date: [4. Mai 2020 um 07:22 UTC](https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677/1 "2020-05-04T07:22:37Z")

</div>

Hello everybody!

We’ve implemented a plugin that allows you to add same product to basket and add children(as individual products) to those ‚main‘ products. Everything looks ok in storefront, in order\_line\_item childrens are saved as separate line items which gets an ‚parentId‘. Our problem is that in admin area and also on documents generation, line items are shown totally random and we do not know which products are ‚seen‘ as childrens and which are main.

Does anyone knows how we can achieve a proper view based on the main/child relation based on parentId? Somehow a grouping by parentId…

Best regards,

Sorin

---

<div class="post-metadata">

### Author: ![SorinSologics2019](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SorinSologics2019](https://forum.shopware.com/u/SorinSologics2019)
#### Post date: [5. Mai 2020 um 11:06 UTC](https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677/2 "2020-05-05T11:06:28Z")

</div>

Hello everyone !

For order documents I’ve found a solution and I’ll post it here maybe will help someone, but for admin order detail view I’m still struggle to get it work right.

Here’s the solution for order documents:

In services.xml:

In DocumentSubscriber.php

```
 'onDocumentTemplateRendererParameterEvent'
        ];
    }

    /**
     * Handle document generation grouping parent/child line items
     *
     * @param DocumentTemplateRendererParameterEvent $event
     */
    public function onDocumentTemplateRendererParameterEvent(DocumentTemplateRendererParameterEvent $event): void
    {
        //get event parameters
        $parameters = $event->getParameters();

        //get order
        $order = array_key_exists('order', $parameters) ? $parameters['order'] : null;

        if(!is_null($order)) {
            $aLineItems = [];
            $root = new OrderLineItemCollection();

            $orderLineItems = $order->getLineItems()->getElements();
            foreach ($order->getLineItems()->getElements() as $lineItemId => $lineItemEntity){
                if(array_key_exists($lineItemEntity->getParentId(), $orderLineItems)) {
                    $aLineItems[$lineItemEntity->getParentId()][] = $lineItemEntity->getId();
                } else {
                    $aLineItems[$lineItemEntity->getId()][] = $lineItemEntity->getId();
                }

            }

            foreach($aLineItems as $lineItemId => $childIds){
                foreach($childIds as $childId){
                    $root->add($orderLineItems[$childId]);
                }
            }

            $order->setLineItems($root);

        }

    }

}

```

Best regards,

Sorin

---

<div class="post-metadata">

### Author: ![SorinSologics2019](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SorinSologics2019](https://forum.shopware.com/u/SorinSologics2019)
#### Post date: [6. Mai 2020 um 09:26 UTC](https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677/3 "2020-05-06T09:26:26Z")

</div>

Hello everyone!

I’m trying to get this view work also in admin vue js based on the logic for order documents but I’m getting stuck to vue js code.

I’ve tried to change the order line items in '…\shopware\administration\Resources\app\administration\src\module\sw-order\component\sw-order-line-items-grid\index.js

in&nbsp;

```
data() {
        return {
            isLoading: false,
            selectedItems: {},
            newOrderedLineItems: [[]]
        };
    },
computed: {
        
        orderLineItems() {
            this.order.lineItems.forEach((orderLineItem) => {
                if(this.inArray(orderLineItem.parentId, this.order.lineItems.getIds())) {
                    this.newOrderedLineItems[orderLineItem.parentId] = [];
                    this.newOrderedLineItems[orderLineItem.parentId].push(orderLineItem.id);
                } else {
                    this.newOrderedLineItems[orderLineItem.id] = [];
                    this.newOrderedLineItems[orderLineItem.id].push(orderLineItem.id);
                }
            });
            console.log(this.newOrderedLineItems);

            return this.order.lineItems;
        },

```

The multidimensional array gets populated but only with the last element for childs.

I do not have too much experience with vue js and any help will be apreaciatted.

Best regards,

Sorin

---

<div class="post-metadata">

### Author: ![arash.yazdani59](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/arash.yazdani59/32/13954_2.png) [@arash.yazdani59](https://forum.shopware.com/u/arash.yazdani59)
#### Post date: [25. Juni 2021 um 07:01 UTC](https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677/4 "2021-06-25T07:01:15Z")

</div>

Hi Sorin,

I need to group children Products too.  
Can you please share your code.  
Services.xml and subscriber or …

Thanks

---

<div class="post-metadata">

### Author: ![ashleylopez199581](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@ashleylopez199581](https://forum.shopware.com/u/ashleylopez199581)
#### Post date: [6. Juli 2021 um 04:33 UTC](https://forum.shopware.com/t/how-can-we-show-in-admin-line-items-with-parentid-somehow-in-relation-with-parent-products/66677/5 "2021-07-06T04:33:16Z")

</div>

Thanks for the information. I’ll be sure to keep an eye on this thread. looking for the same issue.

[MyAARPMedicare](https://www.myaarpmedicare.work/)
