1

I created an event observer to report the creation of new magento products, but the observer doesn't work when the products are created by importing Magmi.

My magento version is 1.9.3.9

This is the config.xml

    <global>
        <models>
            <wally_logproductupdate>
                <class>Wally_LogProductUpdate_Model</class>
            </wally_logproductupdate>
        </models>
        <events>
            <catalog_product_save_before>
                <observers>
                    <wally_logproductupdate>
                        <class>wally_logproductupdate/observer</class>
                        <method>beforeSave</method>
                        <type>singleton</type>
                    </wally_logproductupdate>
                </observers>
            </catalog_product_save_before>
        </events>
    </global>

This is the Observer:

class Wally_LogProductUpdate_Model_Observer
{
    protected $isNew = false;

    public function beforeSave($observer)
    {
        $product = $observer->getEvent()->getProduct();
        if ($product->isObjectNew()) {
            $this->isNew = true;
            $this->afterSave($observer);
        }
    }

    public function afterSave($observer)
    {
        $product = $observer->getEvent()->getProduct();
        if ($this->isNew) {
            $name = $product->getName();
            $sku = $product->getSku();
            $price = $product->getPrice();

            Mage::log("[{$name} ({$sku}) {$price}] aggiornato", null, 'product-updates.log');           
        }
    }
}

Is it the right way or do I have to work in other ways to import products using magmi?

1

As per official wiki of magmi:

Magmi is a Magento Mass Importer developed as a magento DATABASE client, (ie not a magento extension) , that operates directly in SQL.

So magmi runs raw query and any event will not dispatched during import by magmi!

  • Yes, these days I have read that magmi does not pass by the orm model of magento, so what is the best solution to get the id of new products imported from magmi? – Mastafis Apr 8 at 18:35
  • 1
    You can add additional attribute while import from magmi say is_magmi_new and set value to 1 while import. after import you can create a script on root and check for all product is_magmi_new with value 1. once you done you goal, you can set value to 0 – Pawan Apr 10 at 3:05
  • Good idea, I try to do it :D – Mastafis Apr 10 at 14:02
  • did it worked ? – Pawan Apr 12 at 2:34
  • No @Pawan I was not able to do it this way, in the end I opted to create a custom event and pass everything to an observer who retrieves product ids based on the date of creation – Mastafis Apr 15 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.