Magento自动确认订单而不是管理员

时间:2015-07-19 13:08:50

标签: magento

我在管理员面板中看到了我的订单,并且所有订单都处于状态"等待"。

订单是否可以在没有管理员必须这样做的情况下自动确认?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

是有一种方法可以实现这个使用下面的代码并在你的时间基础上从cron调用,代码将在下订单1小时后将状态从挂起更改为处理。

<?php
require_once('app/Mage.php');
Mage::app('admin');
$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status','pending')
    ->addFieldToFilter('created_at', array('lt' =>  new Zend_Db_Expr("DATE_ADD('".now()."', INTERVAL -'60:00' HOUR_MINUTE)")))
    ->addAttributeToSelect('customer_email')   
    ->addAttributeToSelect('increment_id');
Mage::log("cod diret run from script cron start");
foreach ($orders as $order) {   
    $incrementId = $order->getIncrementId();        
    $individualOrder = Mage::getModel("sales/order")->loadByIncrementId($incrementId);
    try {
if(!$individualOrder->canInvoice())
{   
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $individualOrder)->prepareInvoice();
Mage::log("next");
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder()); 
$transactionSave->save();
}
catch (Mage_Core_Exception $e) { 
}
$OrderStatus = Mage::getModel("sales/order")->loadByIncrementId($incrementId);
$OrderStatus->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
    $orderid= $individualOrder->getEntityId();
    $email = $order->getCustomerEmail();     
}