1

I tried to change the attribute value once we click on Place Order button present in checkout page :

config.xml :

<sales_convert_quote_to_order>
    <observers>
        <example_place_order>
            <class>Amasty_Example_Model_Observer</class>
            <method>PlaceOrder</method>
        </example_place_order>
    </observers>
</sales_convert_quote_to_order>

app/code/local/Amasty/Example/Model - Observer.php

public function PlaceOrder($observer)
{ 
    $product = $observer->getEvent()->getProduct();
    Mage::getSingleton('catalog/product_action')->updateAttributes(
        array($product->getId()),
        array('cart_status' => 0),
        $storeId = 0
    );
}

Result

Call to a member function getProduct() on a non-object in line: $product = $observer->getEvent()->getProduct();

2 Answers 2

0

Please try this ... it should set cart_status to 0 for all ordered products:

public function PlaceOrder(Varien_Event_Observer $observer)
{
    $quote = $observer->getQuote();
    $productIds = array();

    foreach ($quote->getItemsCollection() as $item) {
        $productIds[] = $item->getProductId();
    }

    Mage::getSingleton('catalog/product_action')->updateAttributes(
        $productIds,
        array('cart_status' => 0),
        $storeId = 0
    );
}
3
  • now when i click on place order, i dont see any error and order placed successfully, but its not changing value of the attribute......
    – user52996
    Jun 13, 2017 at 13:53
  • Updated answer.
    – sv3n
    Jun 13, 2017 at 14:21
  • Thanks a ton for your continous help and valuable time......
    – user52996
    Jun 13, 2017 at 14:29
-1

Try this:

public function PlaceOrder($observer) { 

     $product = $observer->getEvent()->getQuoteItem()->getProduct();
      Mage::getSingleton('catalog/product_action')->updateAttributes(
         array($product->getId()),
         array('cart_status' => 0),
         $storeId = 0
      );
}
1
  • now it show error : Call to a member function getProduct() on a non-object in in line $product = $observer->getEvent()->getQuoteItem()->getProduct();
    – user52996
    Jun 13, 2017 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.