magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Creation of orders for downloadable products under the cron

Open mklishevych opened this issue 13 years ago • 9 comments

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.

mklishevych avatar Feb 08 '13 10:02 mklishevych

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.

mklishevych avatar Feb 11 '13 10:02 mklishevych

@mklishevich , could you please clarify the use case behind? We are trying to find out the case when orders are created by cron...

verklov avatar Feb 11 '14 11:02 verklov

@mklishevich, please respond. Otherwise we will be forced to close the issue. We need additional information to continue working on the issue.

verklov avatar Apr 01 '14 09:04 verklov

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.

davidalger avatar Apr 01 '14 14:04 davidalger

Thank you for the use case! I will have a ticket created in the backlog for the team to look at it.

verklov avatar Apr 15 '14 19:04 verklov

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.

verklov avatar Oct 23 '14 11:10 verklov

Thank you for this request! Internal ticket: MAGETWO-19106

verklov avatar Jan 08 '15 17:01 verklov

As of 0.74-beta8 in production. You can now create downloadable products via APIs in two different ways.

First way

  1. Create product ( POST /V1/products )
  2. Create downloadable Link ( POST /V1/products/:sku/downloadable-links ) for the product you created

Second way

  1. 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.

choukalos avatar May 11 '15 16:05 choukalos

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.

mklishevych avatar May 13 '15 18:05 mklishevych