문제

Magento에서 주문의 모든 하위 집중 인보이스를 만들어야합니다. 나는이 코드를 사용했지만 나의 금액은오고있다.

$order = Mage::getModel('sales/order')->loadByIncrementId(100000067);
$items = $order->getItemsCollection();

$items = array(); //this will be used for processing the invoice


   foreach ($order->getAllItems() as $item) {
    $items[$item->getId()] = $item->getQtyOrdered();
    }


$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($items);

// The rest is only required when handling a partial invoice as in this example
$amount = $invoice->getGrandTotal();
echo $amount;
$invoice->register()->pay();
$invoice->getOrder()->setIsInProcess(true);

$history = $invoice->getOrder()->addStatusHistoryComment(
    'Partial amount of $' . $amount . ' captured automatically.', false
);

$history->setIsCustomerNotified(true);

$order->save();

Mage::getModel('core/resource_transaction')
    ->addObject($invoice)
    ->addObject($invoice->getOrder())
    ->save();
.

주문의 모든 하위 집중 인보이스를 만드는 방법 .... 내 주문 ID 110101과 5 SKU가있는 경우 (101,102,10,104,105) 이를 위해 Magento에서 주문의 하위 집중 인보이스를 만들고 싶습니다 ......

하지만 주어진 답변을 적용 할 때 나의 금액이 0이되어 다가 오는 것입니다. 여기에 이미지 설명 입력

도움이 되었습니까?

해결책

SKU 각각의 하위 송장을 만들려면이를 시도하십시오.

   foreach ($order->getAllItems() as $item) {
        // create invoice for sku MatchSKU 
       if($item->getSku()=='MatchSKU'):
       // example MatchSKU =101 if  
         $items[$item->getId()] = $item->getQtyOrdered();
         endif;
    }
.

대신 :

 foreach ($order->getAllItems() as $item) {
    $items[$item->getId()] = $item->getQtyOrdered();
    }
.

각 항목을 각 항목에 원하는 경우 다음을 시도하십시오.

foreach ($order->getAllItems() as $item) :
    $itemsQty = array();
    $itemsQty[$item->getId()] = $item->getQtyOrdered();

          if (!$order->canInvoice()) {
           echo  Mage::helper('sales')->__('Cannot do invoice for order.');
        }

        $invoice = $order->prepareInvoice($itemsQty);

        $invoice->register();

       // if want to add comment when invoice creating 
            $invoice->addComment($comment='Test comment', $email=true);

        // send  new  invoice email
            $invoice->setEmailSent(true);

        $invoice->getOrder()->setIsInProcess(true);

        try {
            $transactionSave = Mage::getModel('core/resource_transaction')
                ->addObject($invoice)
                ->addObject($invoice->getOrder())
                ->save();

            $invoice->sendEmail($email, ($includeComment ? $comment : ''));
        } catch (Mage_Core_Exception $e) {
           // there  have an error
        }

         $invoice->getIncrementId();


endforeach;
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top