Question

Comment pourrais-je aller sur la facturation d'un programme unique produit hors d'un ordre de vente de plus d'un produit?

i.e. ordre X a trois produits, SKU1, SKU2 & SKU3. Je veux seulement créer une facture pour SKU1.

Je l'ai regardé dans

\ app \ codes \ core \ Mage \ \ Adminhtml contrôleurs \ Sales \ Order \ InvoiceController.php

Bien que je suis un peu coincé quand je vois la méthode _getItemQtys().

pourrait vraiment utiliser quelques conseils.

Était-ce utile?

La solution 2

La solution est mise en place d'un tableau avec la clé étant item_id de l'ordre (note que ce n'est pas la même chose que product_id, il est un identifiant unique).

Disons que vous avez un ordre increment_id de $ (numéro de commande):

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

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

foreach($items as $item){
    $qty_to_invoice = x; //where x is the amount you wish to invoice
    <!-- please note that if you don't want to invoice this product, set this value to 0 -->
    $qtys[$item->getId()] = $qty_to_invoice;
    <!-- Note that the ->getId() method gets the item_id on the order, not the product_id -->
}

$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($qtys);
<!-- The rest is only required when handling a partial invoice as in this example-->
$amount = $invoice->getGrandTotal();
$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();
$invoice->save();
$invoice->sendEmail(true, ''); //set this to false to not send the invoice via email

Autres conseils

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

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

foreach($items as $item){
    if ($item->getSku() == 'SKU1') {
        $qty_to_invoice = $item->getQtyOrdered(); // now gets order quantity of item
    } else {
        $qty_to_invoice = 0;
    }

    $qtys[$item->getId()] = $qty_to_invoice;
    <!-- Note that the ->getId() method gets the item_id on the order, not the product_id -->
}

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

Amélioration de la réponse il est donc plus clair quand vous voulez seulement un spécifique SKU

Essayez celui-ci ...

<?php
$orderID = "145000010"; //order increment id
$orderDetails = Mage::getModel('sales/order')->loadByIncrementId($orderID);

if($orderDetails->canInvoice() and $orderDetails->getIncrementId())
{
    //$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
    $orderItems = $orderDetails->getAllItems();
    $invoiceItems = array();

    foreach ($orderItems as $_eachItem) {
    $opid = $_eachItem->getId();
    $opdtId = $_eachItem->getProductId();
    $itemss = Mage::getModel('catalog/product')->load($opdtId);
    $psku = $itemss->getSku(); // get product attribute which is used your condition
    if($psku=='Test product1'){
        $qty = $_eachItem->getQtyOrdered();
    } else {
        $qty = 0;
    }

    $itemsarray[$opid] = $qty;
    }

    if($orderDetails->canInvoice()) { 
    echo $invoiceId = Mage::getModel('sales/order_invoice_api')
    ->create($orderDetails->getIncrementId(), $itemsarray ,'Partially create Invoice programatically' ,0,0);
    }
}
?>

Pour plus d'info

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top