- We can set order status as complete through script after order placed.
- We need to add following code in config.xml
<sales_order_place_after>
<observers>
<b4u_order_observer>
<type>singleton</type>
<class>Mshop_B4u_Model_Observer</class>
<method>after_order_placed</method>
</b4u_order_observer>
</observers>
</sales_order_place_after>
- Need to write the following code in observer( mshop -> b4u -> model -> Observer.php )
public static function after_order_placed($observer) {
$event = $observer->getEvent();
$order = $event->getOrder();
$order_no = (string) $order->getRealOrderId();
$order->loadByIncrementId($order_no);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save();
return true;
}
- And we can create invoice also through this script. for that we need to add extra code and the above function should look like below,
public static function after_order_placed($observer) {
$event = $observer->getEvent();
$order = $event->getOrder();
$order_no = (string) $order->getRealOrderId();
// **** This is for creating invoice *****
$order = Mage::getModel('sales/order')->loadByIncrementId($order_no);
try {
if(!$order->canInvoice())
{
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
//Or you can use
//$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
catch (Mage_Core_Exception $e) {
}
// **** This is for set as order complete *****
$order->loadByIncrementId($order_no);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save();
return true;
}
- After that we placed order we got error message in the popup box like " you cannot manually set the order status to complete ".
- For that we need to update code in core file. i know we should not edit that. but in this case we need to edit core file.
- We need to add following code in config.xml
<sales_order_place_after>
<observers>
<b4u_order_observer>
<type>singleton</type>
<class>Mshop_B4u_Model_Observer</class>
<method>after_order_placed</method>
</b4u_order_observer>
</observers>
</sales_order_place_after>
- Need to write the following code in observer( mshop -> b4u -> model -> Observer.php )
public static function after_order_placed($observer) {
$event = $observer->getEvent();
$order = $event->getOrder();
$order_no = (string) $order->getRealOrderId();
$order->loadByIncrementId($order_no);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save();
return true;
}
- And we can create invoice also through this script. for that we need to add extra code and the above function should look like below,
public static function after_order_placed($observer) {
$event = $observer->getEvent();
$order = $event->getOrder();
$order_no = (string) $order->getRealOrderId();
// **** This is for creating invoice *****
$order = Mage::getModel('sales/order')->loadByIncrementId($order_no);
try {
if(!$order->canInvoice())
{
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
//Or you can use
//$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
catch (Mage_Core_Exception $e) {
}
// **** This is for set as order complete *****
$order->loadByIncrementId($order_no);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save();
return true;
}
- After that we placed order we got error message in the popup box like " you cannot manually set the order status to complete ".
- For that we need to update code in core file. i know we should not edit that. but in this case we need to edit core file.
app/code/core/Mage/Sales/Model/Order.php:
/**
* Whether specified state can be set from outside
* @param $state
* @return bool
*/
public function isStateProtected($state)
{
if (empty($state)) {
return false;
}
return self::STATE_COMPLETE == $state || self::STATE_CLOSED == $state;
}
Adding to the top a false return value, like so:
public function isStateProtected($state)
{
return false;
if (empty($state)) {
return false;
}
return self::STATE_COMPLETE == $state || self::STATE_CLOSED == $state;
}
Then run it again and your order should complete.
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
İKQH
Hollanda yurtdışı kargo
ReplyDeleteİrlanda yurtdışı kargo
İspanya yurtdışı kargo
İtalya yurtdışı kargo
Letonya yurtdışı kargo
2M2H3
Litvanya yurtdışı kargo
ReplyDeleteLüksemburg yurtdışı kargo
Macaristan yurtdışı kargo
Malta yurtdışı kargo
Polonya yurtdışı kargo
8OYL8T
Yunanistan yurtdışı kargo
ReplyDeleteAfganistan yurtdışı kargo
Amerika Birleşik Devletleri yurtdışı kargo
Amerika Samoası yurtdışı kargo
Angola yurtdışı kargo
AQWJ
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
A6İXU