1

Is there a way where we can create an order with a cron job? I need this because, the product which I sell is a prepaid subscription(a simple magento product).

Which after payment, I convert it into 6 products(again simple magento product) in case it is a six month subscription and put the first month's order into the cart and remaining 5 products SKUs into a separate table, along with customer_id, some foreign_id for identification and the respective shipping dates.

I could do the above by hooking on to the event

sales_model_service_quote_submit_before

Then I program the cron to run each day and match today's date with the shipping dates in the above created table, fetch those SKUs, customer_id and process the order.

How to go about in making a CRON job to order on behalf of the customer.

NOTE:

The reason I am using the above method is because,

1) The payment is prepaid. NO RECURRING PAYMENTS. I could not use magento's in-built recurring profiles or Aheadworks' subscription and recurring payments plugin. As all are based on billing agreement and are recurring based on paypal/ authorize.net 's call. Thus this is not the solution for the problem

2) If I use a bundle product and put all the 12 sub products (incase of 12 month subscription) into it and sell, the orders will be translated as a single order. It will be pending for 12 months as the shipping will take place 1 sub-product per month.

3) I need to manage inventory on the sub products

If there is some other way to go about in this, please let me know.

If there is a plugin to do all these stuff and you could point that out to me, I owe you a beer!

Help me out. I am literally 5 days old in Magento

3
  • It sounds like you need a subscription module like this Oct 30, 2014 at 13:09
  • @chaoticgeek : are you sure, as far as aheadworks backend demo, I see there are no option for prepaid subscription, all i see is a recurring payment every month. Oct 30, 2014 at 13:13
  • I'm not suggesting that is the one to go with, just an example. Since I don't know of a way to do it right off the top of my head I figured at least pointing you to a subscription service may help. Oct 30, 2014 at 15:17

2 Answers 2

1

Since you already are settled for an approach and it sounds like you were able to modify the first order after payment, what kind of help do you expect now?

  1. creating a cron: can be done with the <crontab> section in your modules config.xml
  2. create an order programmatically: this is not so straightforward, because the order data is spread across multiple tables. You should emulate the Magento workflow, i.e. create a quote, add the product to it, set payment method, shipping method, shipping and billing address, then convert the quote to an order.

This is out of scope for an answer here, but I can give you some pointers:

  • to add products to the quote, you have two options:
    1. reuse the original quote items. Make sure that you keep them in the database without any modifications, then load them directly and use $quote->addItem($item) to add them to the new quote. This option is your choice if you need to be unaffected from modifications in the product over time (like price changes)
    2. use the internal product option buyRequest*, which is generated for all quote/order items. It's a serialized array that contains all information to "replay" the add to cart. For example it's used by Magento for the wishlist and for reorders. Make sure that you save this in your custom table, then pass it like this to the quote model: $quote->addProduct($product, new Varien_Object(unserialize($buyRequest))). This option is the most "natural" way to create a new quote, so if it's ok for you that things like changed prices will be taken into account, choose this one.
  • look at Mage_Sales_Model_Convert_Quote to convert quotes to orders. It's a stateless class, much like a helper. You can instantiate it with Mage::getSingleton('sales/convert_quote') and use its methods.

*) I wrote a detailed reference about the buyRequest object here: http://www.schmengler-se.de/en/2014/09/magento-info_buyrequest-objekt-referenz/

0

Creating orders programmatically is not too hard, and there is a lot of information out there.

For your need, custom table should have the number of shipment, SKU(s) that needs to ship for the shipment, ship date, shipping address, etc. I assume you have everything you need and that you know how to create proper extensions. I'll just give you a basic flow of process on the special case you seem to have.

  1. At every cron job, prepare a new quote.

  2. Add the appropriate product(s) to this quote.

  3. Add shipping and billing addresses.

  4. You have to add a payment to the quote. Since this is prepaid, you can either use the available check/money order method, change its label (so customers aren't thrown off), and take care of the order status at the end. Or, you can create a custom payment method for this.

  5. You also have to add a shipping method. You haven't described what you do with shipping, so I don't know. You can probably use the free shipping method.

  6. Convert quote to order. If you used the check/money order payment, make sure your order is set to processing instead of pending.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.