- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Magento2.4.2 error when create order pragmatically
I followed this tutorial to create order https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/. This solution is working fine till Magento2.3.5. I'm facing following issue with Magento2.3.6 and 2.4 versions.
I've tried
cache:flush
di:compile
Type Error occurred when creating object: Magento\InventoryIndexer\Model\Queue\ReservationData, Argument 2 passed to Magento\InventoryIndexer\Model\Queue\ReservationData::__construct()
must be of the type int, null given, called in /var/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
Try This:
rm -rf var/generation/*
bin/magento setup:di:compile
bin/magento cache:clean
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
I've tried a viral solution and followed this https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/
The quote is created successfully but error occurred when place order through cronjob only.
$orderId = $this->cartManagementInterface->placeOrder($quote->getId());
And the following error occurred
Type Error occurred when creating object: Magento\InventoryIndexer\Model\Queue\ReservationData, Argument 2 passed to Magento\InventoryIndexer\Model\Queue\ReservationData::__construct() must be of the type int, null given, called in /var/www/html/magen
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
Fix: 1 ->
Generally, the reason for this error is when you are passing arguments from the calling method but not receive that arguments in the called function.
For Example, I’ve passed two parameters in calling function and receive only one argument in a called function that means one argument is missing. This results in the error : Type Error Occurred When Creating Object in Magento 2.
Sometimes, The Object is Created, but because of the compilation issue, the object is not created in the generator. Generally, Many programmers Solve this by deleting the whole generated folder to resolve this issue.
However, it’s risky to remove that folder every time which may lead to data loss. Therefore, The solution of this error instead of removing that folder, Is try to run these commands in the sequence mentioned :
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
Fix: 2 ->
Try to replace this line :
$orderId = $this->cartManagementInterface->placeOrder($quote->getId());
with this :
$order = $this->cartManagementInterface->submit($quote);
$quote --> Quote Object
$order --> returns Order Object
For Getting Order Id you can use :
$order->getIncrementId();
If my answer is useful, please Accept as Solution & give Kudos
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
Hello @saeed393,
It may be an MSI issue, in my case we face this issue because of MSI, once we disabled it everything worked fine.
Thanks & Regards
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
You may get this error because of using wrong store for order. Please make sure that you are creating order for actual store view not for admin store view ( All Store View whose store id is 0 ) & also confirm that product must be available in that store view for which you are placing order.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
i had save issue but solved by using
$quote->setStoreId(1);
otherwise the stock id will be null in
Magento\InventoryIndexer\Model\Queue\ReservationData
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
You might get this mistake in view of involving incorrectly store for request. Kindly ensure that you are making request for genuine store view not for administrator store view ( All Store View whose store id is 0 ) and likewise affirm that item should be accessible in that store view for which you are setting request.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento2.4.2 error when create order pragmatically
$quote->setStoreId(1);
Thanks, this solved error on Magento ver. 2.4.7-p3