Closed LonnyX closed 3 years ago
menu_items isn't in the right format, see here: https://github.com/tastyigniter/TastyIgniter/blob/ed14ed725e3acc94fceec547f279d1fe0bcb3c3a/app/admin/traits/ManagesOrderItems.php#L111
I'll look into the restAfterSave() issue
@ryanmitchell Thank you for the restAfterSave, it worked.
But the menu_items is still an issue, look here: https://github.com/tastyigniter/ti-ext-api/blob/master/apiresources/Orders.php#L56
You are requiring menu_items
but it's considered as an attribute of Order and it cause this error:
"Array to string conversion","debug":{"line":419,"file":"\/project\/vendor\/laravel\/framework\/src\/Illuminate\/Support\/Str.php",
You can try by yourself, just copy & paste the payload above
I wont have time to get to this for a while - so if you have time to debug feel free to step through it and add to the PR i've opened.
@sampoyigi I traced this back to https://github.com/tastyigniter/TastyIgniter/blob/ed14ed725e3acc94fceec547f279d1fe0bcb3c3a/app/admin/traits/FormModelWidget.php#L152
Might be something you want to handle here - if the value cant be converted to string it throws an error.
As for the actual issue, I'm about to push a change that handles it.
@ryanmitchell sorry I was waiting to be at home to fix this but you did it before me. But wait it's not over :P there is still a bug in this workflow
Sorry my bad. I missed part of my commit - shouldn’t be a need for what you have done.
I've pushed my update now
Still not finished, now that we have Order & Menu items, we also need the totals. Without that the Order list on the Admin panel will crash
I can fix this one but I need to know if we offer a complete freedom to the API (so we accept eventual inconsistency) or we can be a little bit more restrictive and calculate this in the controller
I think we should calculate subtotal and total in the controller. @sampoyigi any thoughts?
To avoid repeating logic, I think we should use the OrderManager
class.
Let's wait for @sampoyigi advices
Using OrderManager
makes sense, but will also affect menu_items
as they will need to be added as cart items (meaning CartManager
will also likely be a requirement depending on the implementation). It also leads to complexities around discounts etc, and we would probably need to validate the order menu_items before inserting the order (currently its after).
It might be worth bringing the ordermanager/cart manager calculation functionality into the main Orders_model so it can be used in both contexts.
As you said, lets see what Sam thinks.
Sorry I’m late.
To avoid repeating logic, I think we should use the OrderManager class.
@LonnyX It will be hard to not repeat logic, as Ryan pointed out, the approach for creating order on the frontend differs through api.
Using the OrderManager class we can follow one of these;
Approach 1: We use OrderManager class with a new method saveOrderForApi Approach 2: We extend OrderManager within the api extension and replace the logic within saveOrder
I prefer the second approach as it lets us maintain the api’s create order logic within the extension. We could also move some of the saveOrder logic into smaller functions if we find that we are repeating too much.
@sampoyigi What i did locally is adding a new argument $fromAPI = false // by default
for addOrderMenus()
and addOrderMenuOptions()
and it works.
But to be honest your second approach is much better
Great, lets go for approach #2 then. @LonnyX do you want to do an initial commit and we can all contribute from there?
Yep, I will try to push tonight :)
@ryanmitchell how can we extend OrderManager within this package when we cannot include the cart entension via composer here?
` use Igniter\Cart\Classes\OrderManager;
class APIOrderManager extends OrderManager { public function saveOrder() {
} } `
Then (assuming you put it in api/classes) within the file you want to use it
use Igniter\Api\Classes\APIOrderManager;
...
$orderManagers = APIOrderManager::instance();
I tried to create an order via the API but it looks like the order_menus isn't created.
Here is an example of data:
Firstly, sending
menu_items
in the request body is causing an error.now even without the
menu_items
, it looks like therestAfterSave
from Order.php isn't called but instead from the RestController.php itself. And this method is empty in the RestControllerIt looks like a bug