Programmatically stop the decrease in the number of shares when placing an order in magento

I need to stop reducing inventory when placing an order, I need to complete this operation only after a successful payment.

+5
source share
4 answers

Yes, we can pragmatically disable this reduction q

How?

Extend Mage_Checkout_Model_Type_Onepage and Rewrite the saveOrder method

Changes

before the next lines in the above method there will be about # 740 to # 742

    $service = Mage::getModel('sales/service_quote', $this->getQuote());
    $service->submitAll();

Add

    $quote = $this->getQuote();
    # Ref: Mage_CatalogInventory_Model_Observer::subtractQuoteInventory
    $quote->setInventoryProcessed(true);

This tells Magento that it does not process the inventory for the quote, so it will not reduce the quantity, even if it is configured for this.

+6
source

a > > > >

a >

+5

, , Magento EE/CE

sales_model_service_quote_submit_before
+1

, , ?

Qty : Magento, : http://www.nicksays.co.uk/magento_events_cheat_sheet/

 <events>
   <sales_order_payment_pay>
      <observers>
        <my_observer>
            <type>singleton</type>
            <class>my/observer</class>
            <method>addQty</method>
        </my_observer>
      </observers>
   </sales_order_payment_pay>     
</events>

Qty ..

<?php
class Company_My_Model_Observer
{
    public function addQty($event)
    {
        $order = $event->getInvoice()->getOrder(); // Mage_Sales_Model_Order
        $items = $order->getAllVisibleItems();

        foreach($items  as $item) {
             $qty = $item->getQtyOrdered(); // Amount to add back on
             $product = Mage::getModel('catalog/product')->load($item->getProductId());
             /**
              * Here you would load the product and add this amount back on
              */
        }

        return $this;
    }
}

, , , , . magento , .

0

All Articles