3

I want get Product Ids after import product using csv file.

When I go following menu System > Import/export > Import and import*.csv file of products and when finish import data one event called catalog_product_import_finish_before this event is in app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php.

This event work but not getting `ids(entity_id)` of product after imported.

Any one help me where I am going wrong ?

my app/code/local/Test1/Module1/etc/config.xml

<config>
    <modules>
        <Test1_Module1>
            <version>0.1.1</version>
        </Test1_Module1>
    </modules>
         <adminhtml>
              <events>
                <catalog_product_import_finish_before>
                    <observers>
                        <test_module1_catalog_product_import_after>
                            <type>singleton</type>
                            <class>module1/observer</class>
                            <method>afterImportProductData</method>
                        </test_module1_catalog_product_import_after>
                    </observers>
                </catalog_product_import_finish_before>
             </events>
          </adminhtml>
</config>

this is defined code in app/code/local/Test1/Module1/Model/Observer.php

public function afterImportProductData(Varien_Event_Observer $observer)
    {
        echo "<pre>";
        Mage::log($observer->getEvent()->getAdapter()->getData());
        die('die');
    }

Please help me.

  • Please post the full config.xml file. Youre using 'marketplace/observer' as the observer class name but are your models configured to be using 'marketplace' in the config.xml? – Raphael at Digital Pianism Feb 28 '16 at 12:17
  • sry its other code pasted.I revert back and corrected code ..see again and help me – Niraj Patel Feb 28 '16 at 12:23
4

Try adding the following code inside the config tag of your config.xml:

<models>
    <module1>   
        <class>Test1_Module1_Model</class>
    </module1>
</models>

Then to get the product Ids you can use the following piece of code in your observer:

$adapter = $observer->getEvent()->getAdapter();
$affectedEntityIds = $adapter->getAffectedEntityIds();
|improve this answer|||||
  • But I want to fetch new product ids which after imported it creates. – Niraj Patel Feb 28 '16 at 17:39
  • Observer working properly but any method to get in observer method product ids after imported data ? – Niraj Patel Feb 28 '16 at 17:40
  • @test see my edited answer – Raphael at Digital Pianism Feb 28 '16 at 17:45
  • What a solution.Your solution is flexible.2 min ago I found solution to override app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php file and get entitiy_ids from _saveProductEntity function line number 1271 to get entity_ids from foreach loop. $newId is new entitiy_id of new product.Thanks again thank you thank u thank u. – Niraj Patel Feb 28 '16 at 17:56
  • Your solution is flexible than me. thank you for saving my time – Niraj Patel Feb 28 '16 at 17:57

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.