concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Order sent by the "on_community_store_order" event doesn't have orderItems initialized #881

Closed Quentindeve closed 1 month ago

Quentindeve commented 1 month ago

What went wrong

I did a simple package for ConcreteCMS that subscribes to the "on_community_store_order" event. The function called on trigger is here:

public function orderPlaced(OrderEvent $event) {
        $order = $event->getOrder();
        $dataToSend = $order->getOrderItems();
        Log::addInfo("Order: " . $dataToSend);
    } 

However, the array returned by this Order is empty. Moreover, fetching it with Order::getByID(int $id) doesn't solve the issue. Therefore this code snippet doesn't work too:

public function orderPlaced(OrderEvent $event) {
        $order = $event->getOrder();
        $order = Order::getByID($order->getOrderID()); // This is supposed to fetch all related data with the ORM, so to load Order::$orderItems
        $dataToSend = new OrderTransform($order);
        Log::addInfo("Order: " . $dataToSend);
    }
Mesuva commented 1 month ago

That's odd - I just tried logging some things from an order using that event, on version 2.6.5, and it worked as expected.

I tried something like this:

Screenshot 2024-06-10 at 09 20 07

And I had both the order ID, and the name of the product I had in the order output in the logs.

Whatever Community Store version are you running?

Quentindeve commented 1 month ago

I use CS version 2.6.4 with Concrete 9.2.8.

Mesuva commented 1 month ago

Is it the same for the Invoice method, as for other payment methods?

On Mon, 10 Jun 2024, 09:26 Quentin, @.***> wrote:

I use CS version 2.6.4.

— Reply to this email directly, view it on GitHub https://github.com/concretecms-community-store/community_store/issues/881#issuecomment-2157689748, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIHSMDU55WBVL2ST7KL7WLZGVPKXAVCNFSM6AAAAABJBYMXL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJXGY4DSNZUHA . You are receiving this because you commented.Message ID: @.*** com>

Quentindeve commented 1 month ago

Yes, the issue is unrelated to payment methods unfortunately

Mesuva commented 1 month ago

How strange.

If you want to send me the add-on you're working on I'm happy to take a look. Or if you've got a development environment to debug, happy to look at that too. Shoot a message to ryan@mesuva.co.uk

Quentindeve commented 1 month ago

Done !

Quentindeve commented 1 month ago

After few emails with @Mesuva the solution was found:

It solved the issue on my side !