2012-01-29 2 views
7

나는 어떻게 든 주문이 발송되지 않습니다 sales_order/indexMagento 프로그래밍 방식으로 주문을 발송하려면 어떻게해야합니까?

에서 젠토 및 선박 완전한 여러 개의 주문에 MassAction를 추가하는 몇 가지 코드를 찾고 있어요.

마치 정상적인 순서 인 것처럼 보이며 canship() 테스트를 통과하지 못했습니다. 패스해야합니까 $order$orderid?

여기에 내 코드

당신은, 당신이 실제로 주문 incrementId을받을 경우 IncrementOrderId에 의해 주문 ID, 또는 부하를 얻는 경우에, ID에 의해로드 할 필요
//Get orderids 
$orderIds = $this->getRequest()->getPost('order_ids'); 

//verify if the array is not empty 
if (!empty($orderIds)) { 
//loop through orders 
foreach ($orderIds as $orderId) { 

// Dont know what this does 
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId); 

// Is the order shipable? 
if($order->canShip()) 
{ 
$itemQty = $order->getItemsCollection()->count(); 
// This first definition and 2nd look overlapping, our one is obsolete? 
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty); 
$shipment = new Mage_Sales_Model_Order_Shipment_Api(); 

// But still, no shipment, why? 
$shipmentId = $shipment->create($orderId, array(), 'Shipment created through ShipMailInvoice', true, true); 

답변

6

입니다.

사용이 :

$order = Mage::getModel('sales/order')->load($orderId);

가이 일을 알려 주시기.

: 그리고

$shipmentId = $shipment->create($order->getIncrementId(), $itemQty, 'Shipment created through ShipMailInvoice', true, true); 

은보십시오.

+0

많은 감사합니다 @ShaunOReilly. 그것은합니다 ... canship()를 통과 을 수행하지만 다음 오류가 발생합니다 order_not_exists 'code' 추적 : 주문/선적/Api.php (142) : Mage_Api_Model_Resource_Abstract -> _ 오류 ('order_not_exist ...') Sales/OrderController.php (45) : Mage_Sales_Model_Order_Shipment_Api-> create ('121', Array, 'Shipment create ...', true, true) 'code' –

+0

이제 $ shipment-> create에서 충돌합니다. 나는 $ order와 orderId를 모두 시도했다. 둘 다 작동하지 않습니다. $ order 결과가 액세스 위반이됩니다 $ shipmentId = $ shipment-> create ($ order, array(), –

+0

내 대답의 마지막 편집을보세요. – ShaunOReilly

1
$order = Mage::getModel('sales/order')->load($orderId); 

//create shipment 
$itemQty = $order->getItemsCollection()->count(); 
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty); 
$shipment = new Mage_Sales_Model_Order_Shipment_Api(); 
$shipmentId = $shipment->create($order->getIncrementId(), array(), 'Shipment created through ShipMailInvoice', true, true); 

//add tracking info 
$shipment_collection = Mage::getResourceModel('sales/order_shipment_collection'); 
$shipment_collection->addAttributeToFilter('order_id', $orderId); 
foreach($shipment_collection as $sc) 
{ 
$shipment = Mage::getModel('sales/order_shipment'); 
$shipment->load($sc->getId()); 
           if($shipment->getId() != '') 
           { 
           try 
           { 
            Mage::getModel('sales/order_shipment_track') 
            ->setShipment($shipment) 
            ->setData('title', 'carrier') 
            ->setData('number', $trackInfo) 
            ->setData('carrier_code', 'custom') 
            ->setData('order_id', $shipment->getData('order_id')) 
            ->save(); 

           }catch (Exception $e) 
           { 
            Mage::getSingleton('core/session')->addError('order id '.$orderId.' no found'); 
           } 
           } 
         } 
// change order status to complete 
         $order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE); 
         $order->setData('state', Mage_Sales_Model_Order::STATE_COMPLETE); 
         $order->save(); 

1. 선원을 만들고, 2. 선적 추적 정보를 추가하고, 3. 선적 상태를 완료로 변경하십시오.

ShaunOReilly에게 감사드립니다.

관련 문제