I'm working on a quote system where I want the admin to be able to activate it, which will then forward them to the create new order page in Adminhtml, sales_order_create
.
I want this page to already have a customer assigned & products selected.
Edit:
I'd like to be able to pre-populate the quote for the Adminhtml page for creating an order.
Here's an example of creating a cart quote on the front-end:
$cart = Mage::getModel('checkout/cart');
$product = Mage::getModel('catalog/product')->load($productId);
if ($product){
if ($product->isSaleable()){
$cart->addProduct($product, array('qty' => $qty));
}
}
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$cart->save();
I want to do this, but in the backend (sales_order_place
)
I'm looking at the code in app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
and it looks like adminhtml/session_quote
would be the model I'd be aiming to use.
So the workflow would be:
- Set up quote object
- Call
$this->redirect('*/sales_order_create');
- The admin will then be redirected to the create new order page with a customer already selected and the basket already populated with products
Would really appreciate some input.
Best Answer
This is very possible. Here is a very scaled back version of how to accomplish this task.
Explanation:
The
adminhtml/session_quote
object provides access to aMage_Sales_Model_Quote
object. This object is associated with the session, so the changes made to it are persisted. Do what you would like to the quote object. The items are loaded via$this->getQuote()->getAllVisibleItems();
(inMage_Adminhtml_Block_Sales_Order_Create_Items
).Depending on how you are going to use this, you may need to clear the session:
Code: