Creation of orders for downloadable products under the cron
Currently, it's only possible to create orders for downloadable products only from frontend or admin area. I've investigated the problem and I can say the problem is caused by wrong event subscription configuration.
In file app/code/core/Mage/Downloadable/etc/config.xml, subscription for event called sales_order_item_save_commit_after presented for both frontend and adminhtml areas.
Observer for this event is not triggered under the cron (because the only available area under the cron is crontab area), so the order will have no downloadable links in it.
I believe there is no reason to ignore the crontab area and it should be changed for sure.
The same problem exists in part of creating gift messages under the crontab area. Event called sales_convert_quote_item_to_order_item is generated by magento, but the subscription for this event is only supported for adminhtml and frontend areas.
@mklishevich , could you please clarify the use case behind? We are trying to find out the case when orders are created by cron...
@mklishevich, please respond. Otherwise we will be forced to close the issue. We need additional information to continue working on the issue.
I can't speak for this user, but the obvious use case which I would think of is ERP integrations. We build integrations which run in the cron, importing orders, synchronizing products, inventory, pricing, and the list goes on. There are modules which do this same stuff to import orders from Amazon and eBay for those using Magento as their OMS. It's not an isolated use case, that much I can say. And there needs to be a way for this stuff to be done from cron, whether it's firing front or admin events from cron, subscribing these event handlers to the crontab area as well as frontend and admin, or allowing the cron to import the event handlers which fire while a given observer is running.
Thank you for the use case! I will have a ticket created in the backlog for the team to look at it.
The team is currently working on the new Magento 2 API. Once this is complete, we will verify this issue again. Most likely this will be gone. Meanwhile we are leaving the ticket open.
Thank you for this request! Internal ticket: MAGETWO-19106
As of 0.74-beta8 in production. You can now create downloadable products via APIs in two different ways.
First way
- Create product ( POST /V1/products )
- Create downloadable Link ( POST /V1/products/:sku/downloadable-links ) for the product you created
Second way
- Create product and as part of request object include both the product object and the downloadable link object (plus any other's that you want - perhaps media, etc); via POST /V1/products
We don't have much API documentation right now but if you'd like to get the latest/greatest for REST url's and payload/responses try running the api-functional tests. Make sure you update the phpunit.xml.dist file and set your base url, admin user, admin password, and change GENERATE_REST_DOCUMENTATION variable to true. That'll create an output file with the documentation for all REST calls, requests and responses in the system.
Initial issue was not related to API at all. It was related to the situation, when some module (e.g. M2ePro) re-implements checkout functionality to create orders in magento, which came from 3rd party source (eBay in this case). And the problem was that subscription for event called "sales_order_item_save_commit_after" was explicitly configured for adminhtml and frontend event areas. Under the cron only global and crontab areas are available, and that was the issue.