Sylius: Null reference to cart when order item is added twice

Created on 15 May 2018  路  7Comments  路  Source: Sylius/Sylius

| Q | A
| ---------------- | -----
| Bug report? |yes
| Feature request? | no
| BC Break report? | no
| RFC? | no
| Sylius version | 1.1.5

I am not sure if this is a bug or intended, however, in Sylius\Component\Order\Modifier\OrderModifier the method resolveOrderItem receives a single order item.

There are two scenarios: 1) The order item does not exist on the order, 2) the order item already exists on the order.

Ad 1: No problem here
Ad 2: If the item already exists, the order will never be associated with the order item, since this happens in line 80.

This becomes a problem when listening to the event sylius.order_item.post_add in Sylius\Bundle\OrderBundle\Controller\OrderItemController. Here the method getOrder() on the order item will be null, which is not what I would expect when I just added an item to the cart.

Bug

Most helpful comment

Probably not, I'll try to check it out in the nearest days and propose some fix. Thank you for being watchful :)

All 7 comments

I confirm that this problem occurs, any ideas of fast fix?

Maybe we can make OrderModifierInterface::addToOrder to return correct OrderItem and then putting it into the event?

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

was it fixed?

Probably not, I'll try to check it out in the nearest days and propose some fix. Thank you for being watchful :)

As I'm sure you probably already know, the item being created from the addAction is lost here: https://github.com/Sylius/Sylius/blob/master/src/Sylius/Component/Order/Modifier/OrderModifier.php#L67 as $item is basically discarded and just used to pass information into here. You'd need to pass back $existingItem to get access to the cart and everything else, but then there's also the problem of retrieving the quantity that was actually added and not the new total. If you do come up with something for this might I also request that we somehow get access to the OrderItemUnit's that get created as well? I am working on adding the ability to "engrave" products when checking out and get the data into the OrderItem, but then it is lost after that, and doing that way anyway with multiple engravings would lose the first one as well. It would probably be nice to have a custom event here instead of the ResourceControllerEvent so you could access the original add command, the final order item, and the new order item units.

The only kind of sloppy solution I can see now for me to do (without changing any core code) = is to find the OrderItem in the actual cart and then try to modify the x latest OrderItemUnits but this seems a little sloppy.

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikemix picture mikemix  路  3Comments

ping86 picture ping86  路  3Comments

Chrysweel picture Chrysweel  路  3Comments

inssein picture inssein  路  3Comments

xleliberty picture xleliberty  路  3Comments