framework icon indicating copy to clipboard operation
framework copied to clipboard

OrderItem returns product of wrong type

Open csavelief opened this issue 2 years ago • 4 comments

Hi!

I overrided the concord model Product using

$this->app->concord->registerModel(\Vanilo\Product\Contracts\Product::class, Product::class);

When I try to get the Product associated to a given OrderItem, the object returned is of type \Vanilo\Product\Contracts\Product instead of being of type \App\Models\Product :

class SendOrderCompletedNotification
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function handle(OrderWasCompleted $event): void
    {
        $order = $event->getOrder();
        foreach ($order->getItems() as $orderItem) {
            $product = $orderItem->product;
            Log::debug($product::class) // <-- HERE !
        }
    }
}

I believe that here the code should be rewritten as :

public function product()
{
        return $this->morphTo(ProductProxy::modelClass());
}

Best,

Cyrille

csavelief avatar Dec 12 '23 05:12 csavelief

Please check the object type again, as it can't be \Vanilo\Product\Contracts\Product since that is an interface. In case it doesn't resolve properly the override, then the object should be either a \Vanilo\Product\Models\Product or a \Vanilo\Foundation\Models\Product.

Do you use the entire framework or just modules from it?

fulopattila122 avatar Dec 12 '23 14:12 fulopattila122

First, thank you for your answer.

You are right, the type is Vanilo\Foundation\Models\Product.

I ran more tests and the Order and OrderItem types are correct though :

    public function handle(OrderWasCompleted $event): void
    {
        $order = $event->getOrder();
        Log::info($order::class); // <-- OK : App\Models\Order  
        
        foreach ($order->getItems() as $orderItem) {
            Log::info($orderItem::class); // <-- OK : App\Models\OrderItem
            Log::info($orderItem->product::class); // <-- KO : Vanilo\Foundation\Models\Product instead of App\Models\Product
        }
    }

My laravel.log file :

[2023-12-13 08:45:22] local.INFO: App\Models\Order  
[2023-12-13 08:45:22] local.INFO: App\Models\OrderItem  
[2023-12-13 08:45:22] local.INFO: Vanilo\Foundation\Models\Product   

I cloned this project and overrided some types.

Not the point here, but I believe there are more bugs in the demo project (for example, in the admin UI selecting the checkbox associated to an order item inside an order has no impact and is not saved).

csavelief avatar Dec 13 '23 08:12 csavelief

Got it; thank you for the details, this helps a lot!

One last thing, could you please give me the output of php artisan concord:modules? Thx!

fulopattila122 avatar Dec 13 '23 09:12 fulopattila122

Of course! Here it is :

+-----+-------------------------------+--------+---------+-------------------+-------------------+
| #   | Name                          | Kind   | Version | Id                | Namespace         |
+-----+-------------------------------+--------+---------+-------------------+-------------------+
| 1.  | AppShell                      | Box    | 3.9.0   | konekt.app_shell  | Konekt\AppShell   |
| 2.  | Vanilo Foundation             | Box    | 3.8.2   | vanilo.foundation | Vanilo\Foundation |
| 3.  | Vanilo Admin                  | Box    | 3.6.0   | vanilo.admin      | Vanilo\Admin      |
| 4.  | Adyen Payments for Vanilo     | Module | 1.0.0   | vanilo.adyen      | Vanilo\Adyen      |
| 5.  | Braintree Payments for Vanilo | Module | 1.5.1   | vanilo.braintree  | Vanilo\Braintree  |
| 6.  | Mollie Payments for Vanilo    | Module | 1.0.0   | vanilo.mollie     | Vanilo\Mollie     |
| 7.  | Euplatesc Payments for Vanilo | Module | 3.0.0   | vanilo.euplatesc  | Vanilo\Euplatesc  |
| 8.  | Netopia Payments for Vanilo   | Module | 2.1.0   | vanilo.netopia    | Vanilo\Netopia    |
| 9.  | PayPal Payments for Vanilo    | Module | 1.0.0   | vanilo.paypal     | Vanilo\Paypal     |
| 10. | SimplePay Payments for Vanilo | Module | 1.0-dev | vanilo.simplepay  | Vanilo\Simplepay  |
| 11. | Stripe Payments for Vanilo    | Module | 1.0-dev | vanilo.stripe     | Vanilo\Stripe     |
+-----+-------------------------------+--------+---------+-------------------+-------------------+

csavelief avatar Dec 13 '23 11:12 csavelief

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

github-actions[bot] avatar Apr 15 '24 11:04 github-actions[bot]

Closing because of being stalled for 3 days without activity.

github-actions[bot] avatar Apr 22 '24 11:04 github-actions[bot]