Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:28:22+00:00 2026-06-06T11:28:22+00:00

Im starting to understand how Magento Event Observers work and hoping someone could help

  • 0

Im starting to understand how Magento Event Observers work and hoping someone could help me figure out what Event I would need to seek out to get my potential module to work. I have certain products that have an attribute called “child skus” which is an array of SKU numbers of other products in my inventory.

Example:

Name: Totally Awesome Product

SKU: TP-1212

Child SKUS: GP-3232,FD-4332,VC-5332

Every time someone purchases TP-1212 I also need Magento to deduct that quantity from those child skus behind the scenes. Does anyone know if there is an event dispatcher for after a purchase has been completed that would handle something like that??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:28:23+00:00Added an answer on June 6, 2026 at 11:28 am

    This is a little tricky and there are most likely some edge cases not covered in the below code – Also the answer assumes the following:

    1. You wish to reduce the stock level of all associated products of the parent just purchased
    2. You wish to reduce by only 1
    3. There are no further complications or other conditions that must be met/dealt with

    Code:

    So, you obviously need to create a module first. The config.xml needs to declare the observer which will listen to checkout_type_onepage_save_order_after. (Note: there are other events you can listen to in order to achieve your goal).

    The config.xml will contain the following code at a minimum:

    <?xml version="1.0"?>
    <config>
        <modules>
            <YourCmpany_YourModule>
                <version>1.0.0</version>
            </YourCmpany_YourModule>
        </modules>
        <frontend>
            <events>
                <checkout_type_onepage_save_order_after>
                    <observers>
                        <yourmodule_save_order_observer>
                            <class>YourCompany_YourModule_Model_Observer</class>
                            <method>checkout_type_onepage_save_order_after</method>
                        </yourmodule_save_order_observer>
                    </observers>
                </checkout_type_onepage_save_order_after>
            </events>
        </frontend>
        <global>
            <models>
                <yourmodule>
                    <class>YourCompany_YourModule_Model</class>
                </yourmodule>
            </models>
        </global>
    </config>
    

    Then in your observer:

    <?php
    
    class YourCompany_YourModule_Model_Observer
    {
        public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer)
        {
            $order = $observer->getEvent()->getOrder();
    
            /**
             * Grab all product ids from the order
             */
                $productIds = array();
            foreach ($order->getItemsCollection() as $item) {
                $productIds[] = $item->getProductId();
            }
    
            foreach ($productIds as $productId) {
    
                $product = Mage::getModel('catalog/product')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->load($productId);
    
                if (! $product->isConfigurable()) {
                    continue;
                }
    
                /**
                 * Grab all of the associated simple products
                 */
                $childProducts = Mage::getModel('catalog/product_type_configurable')
                            ->getUsedProducts(null, $product);
    
                foreach($childProducts as $childProduct) {
    
                    /**
                     * in_array check below, makes sure to exclude the simple product actually 
                     * being sold as we dont want its stock level decreased twice :)
                     */
                    if (! in_array($childProduct->getId(), $productIds)) {
    
                        /**
                         * Finally, load up the stock item and decrease its qty by 1
                         */
                        $stockItem = Mage::getModel('cataloginventory/stock_item')
                                        ->loadByProduct($childProduct)
                                        ->subtractQty(1)
                                        ->save()
                                    ;
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting out using IronPython with WPF and I don't quiet understand
I'm starting out with MVVM, and I'm starting to understand things. I'm currently experimenting
I've just starting working with Prolog and I don't understand how to work with
I'm just starting out with CloudFoundry and I understand that the only way to
I am just starting out with WPF and am trying to understand data binding.
I'm just starting out playing around with handlebars and I'm struggling to understand how
Still completely stuck with regex's and square brackets. Hopefully someone can help me out.
Starting to learn and understand phing. I would like to export sql database using
I thought that I was really starting to understand how pointers work, and then
I'm just starting out learning ASP.NET. From what I understand, ASP.NET differs from old

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.