Question

Once product is created in magento , the same product details should be passed to an external source using API.

How to achieve this ?

Was it helpful?

Solution

You can hook and observer to the catalog_product_save_after event (just for admin scope) in the observer check if the object is new then send the data wherever you need.

Config:

{Vendor}/{Module}/etc/config.xml (part)

...
</adminhtml>
    <events>
        <catalog_product_save_after>
            <observers>
                <gps_checkout_controller_action_predispatch_checkout_onepage_saveOrder>
                    <class>{vendor}_{module}/observer</class>
                    <method>productSaveAfter</method>
                </gps_checkout_controller_action_predispatch_checkout_onepage_saveOrder>
            </observers>
        </catalog_product_save_after>
    </events>
</adminhtml>
...

Observer

{Vendor}/{Module}/Model/Observer.php

<?php
class {Vendor}/{Module}/Model/Observer 
{
    public function productSaveAfter(Varien_Event_Observer $observer)
    {
        $product = $observer->getEvent()->getData('product');
        if($product->isObjectNew()) {
            // Performe API Request ... 
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top