yea that’s a different issue than creating customers. I haven’t worked with guest profiles. It should be easier than figuring out how to create a customer. It sounds like you might have to over-ride some core functionality too.
I haven’t gone through automating shipments. Obviously it’s just a matter of looking in the right files. As far as specifying the date on the order/invoice/shipment, the most you would have to do is build a simple table of the product_id’s created in the import, along with the timestamp you’d like to set it to, then run a script once or every 5 minutes with cron. The least you would have to do is make sure it is an instance of Varien Object and do obj->setCreatedAt(’bla’)->setUpdatedAt(’bla’) .. the Varien Object uses magic functions for setters and getters so you can pretty much set and get anything you want, just by looking at the right db table and switching the naming from field_a in the db to fieldA in your setter/getter .. most of Magento doesn’t really look at what it’s saving, because of the flexibility that attributes offers.. for example, you can save a customer without attaching the state they live in .. its flexibility has both pros and cons.. the only other advice I can offer is (if you haven’t already) learn to use firebug and grep -r or some file searching equivalent..try and dig into the right controller from the form, etc..that’s probably obvious to most here..
here’s another set of code, adding items as quote_items rather than products
also the functions are split in 2, one to create the quote and the other converts it to an order
in my system, these are set up as soap functions, so it loads Mage separately in each function.
the top 3 lines in each function could be taken out and called just once at the top of the file
function PrepareOrder($params) { require_once '../app/Mage.php'; $app = Mage::app(); Mage::register('isSecureArea', true); //no output before here, will get a session header error foreach($params as $k=>$v) { $$k=$v; }
Thanks for the code Jesse_dev, saved me a good amount of time in replicating the order process, however there is a bug with the code above and the stock-level checking functions in the Mage_CatalogInventory_Model_Observer class.
The above code calls the function _getProductQtyForCheck 3 times over the one session. These calls are triggered from:
This then does a stock-check three times, and increments the _checkedProductsQty counter each time. The result of this is that orders which process for stock items which have 2 or less items in stock will process as being back-orders instead of orders which are in stock.
This happens because each of these calls are designed to be used once per page-load, and as all are done at the same time, the logic of this check fails. Im having a think about how to fix this, but it may require some fairly large core code extending unless anyone has any other ideas?
here’s another set of code, adding items as quote_items rather than products
also the functions are split in 2, one to create the quote and the other converts it to an order
in my system, these are set up as soap functions, so it loads Mage separately in each function.
the top 3 lines in each function could be taken out and called just once at the top of the file
function PrepareOrder($params) { require_once '../app/Mage.php'; $app = Mage::app(); Mage::register('isSecureArea', true); //no output before here, will get a session header error foreach($params as $k=>$v) { $$k=$v; }
Thanks for the code Jesse_dev, saved me a good amount of time in replicating the order process, however there is a bug with the code above and the stock-level checking functions in the Mage_CatalogInventory_Model_Observer class.
The above code calls the function _getProductQtyForCheck 3 times over the one session. These calls are triggered from:
This then does a stock-check three times, and increments the _checkedProductsQty counter each time. The result of this is that orders which process for stock items which have 2 or less items in stock will process as being back-orders instead of orders which are in stock.
This happens because each of these calls are designed to be used once per page-load, and as all are done at the same time, the logic of this check fails. Im having a think about how to fix this, but it may require some fairly large core code extending unless anyone has any other ideas?
Sorry for the double post, but I fixed this bug by extending Mage_CatalogInventory_Model_Observer->_getProductQtyForCheck() to remove this check in cases where its a custom order (a global variable set for the productId). Basic code which requires extending core files (not changing) through a custom module.
First thanks to jesse_dev, your code has helped me a lot to create a module for importing our legacy orders from VirtueMart.
One problem I found was with this code for creating invoices - they were appearing but not showing as paid and so the order wasn’t changed to completed. I found that I had to change the lines:
I found a small problem with jesse_dev’s ConfirmOrder() code.
When the quote is converted into an order it needs to be updated itself otherwise you leave active quotes in the database, this will mean that unless you’ve got something cleaning out old quotes the user will have the last created quote in their shopping basket the next time they log on (which could be a surprise to them or even over write the items they’d left in their basket)
The code needs to have the following lines added before the end:
$quoteObj->setIsActive(0); $quoteObj->save();
It might be a good idea to wrap the quote and order saves in a transaction (you would remove the two $....Obj->save() lines and place this code where $orderObj->save() is:
here’s another set of code, adding items as quote_items rather than products
also the functions are split in 2, one to create the quote and the other converts it to an order
in my system, these are set up as soap functions, so it loads Mage separately in each function.
the top 3 lines in each function could be taken out and called just once at the top of the file
function PrepareOrder($params) { require_once '../app/Mage.php'; $app = Mage::app(); Mage::register('isSecureArea', true); //no output before here, will get a session header error foreach($params as $k=>$v) { $$k=$v; }
Thanks for the info I have edited the code a bit for bundled products there is another thread in forum asking how to create bundled products programatically so here is what i did. Maybe it can be imporved
Use confirm order as it is
$app = Mage::app(); Mage::register('isSecureArea', true); //no output before here, will get a session header error foreach($params as $k=>$v) { $$k=$v; }
Can you please explain how the code was executed. I have also used the same code.(i Mean two functions ‘Make Quote’ & ‘Confirm Order’)
First function was working properly but the second function was not working properly. The following error was occuring:
<b>SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘subtotal’ cannot be null</b>
Please tell me how o overcome the above error?
Hi Rajesh,
Would provide us with array format that you are using to pass parameters to these functions and also functions that you are using ‘Make Quote’ and ‘Confirm Order’
When i am submitting the quote the data was entering as subtotal equals to zero. I think that is the reason to get that error. So how to insert the subtotal with the actual price can you plz post?