|
i will try to explain how everthing works, whole logic is mainly in these two files (take a look if u understand)
/app/code/core/Mage/Sales/Model/Order.php
/app/code/core/Mage/Sales/Model/Order/Config.php
and then setup is in /app/code/core/Mage/Sales/etc/config.xml
first u have to realize that STATE is not the same as STATUS u see displayed in front and backend
there are these ORDER STATES
const STATE_NEW = ‘new’;
const STATE_PENDING_PAYMENT = ‘pending_payment’;
const STATE_PROCESSING = ‘processing’;
const STATE_COMPLETE = ‘complete’;
const STATE_CLOSED = ‘closed’;
const STATE_CANCELED = ‘canceled’;
const STATE_HOLDED = ‘holded’;
each STATE can have multiple STATUSES (although default .xml file have only one for each)… and STATUS is only text expression of STATE for customers/backend operators
order is in STATE “new” : when order is created/edited
order changes to STATE “pending_payment” : this state works only with paypal as far as i know (maybe with some other payment processing options)
order changes to STATE “processing”: when invoice OR shipment is created
order changes to STATE “complete” : when both invoice AND shipment are created
order changes to STATE “closed” : when invoice is created AND then memo is created (u refund to customer)
order changes to STATE “canceled” : when order is canceled ( before invoice is created)
order changes to STATE “holded” : when order is holded
as u can see each one of buttons INVOICE HOLD REORDER CANCEL EDIT changes STATE of an order
simplest possible custom modification is to edit /app/code/core/Mage/Sales/etc/config.xml and edit/add custom STATUSES for each STATE. If u have multiple STATUSES for each STATE it is possible to choose default one via config.xml e.g. with “default” parameter
<states>
<complete translate="label">
<label>Complete</label>
<statuses>
<complete default="1"/>
<partial complete>
<complete pickup>
<etc.............>
</statuses>
<visible_on_front/>
</complete>
if you want to go further and change STATUS automaticaly in each STATE according to some variable e.g. shipping or payment method there is this function in /app/code/core/Mage/Sales/Model/Order/Config.php line 59
public function getStateDefaultStatus($state)
{
$status = false;
if ($stateNode = $this->_getState($state)) {
if ($stateNode->statuses) {
foreach ($stateNode->statuses->children() as $statusNode) {
if (!$status) {
$status = $statusNode->getName();
}
$attributes = $statusNode->attributes();
if (isset($attributes[’default’])) {
$status = $statusNode->getName();
}
}
}
}
return $status;
}
this function always sets default STATUS for each STATE when order enters that STATE
just add couple more “if” and u can make it set whatever STATUS u want, of course with cooperation with parameters from config.xml
i know its pretty limiting to have just 5 STATEs to work with (actually only 2-3usable) but with correct setup its possible to alter it according to your workflow and automate almost every process. Extendind magento to have more order STATEs is pretty complicated.
just to remind: dont edit core files and make your own config.xml and in case u need it rewrite of public function getStateDefaultStatus($state)
it would be really nice and simple local code base extension with just two files in it and can completely change way u process orders.
all that is written above are just my observations and i might be mistaken. please correct me.
i wish somebody finaly wrote a proper wiki about order management in magento as it is most misunderstood part of it :(
|