15 days money back guarantee   Onetime payment, lifetime usage

Blog

Magmi: delete or disable products missing in CSV / source

A little while back I had to automate product importing from external CSV source for a client of ours. We used Magmi to do so. Magmi is awesome and you can do so much with it. However, there was one thing I needed to write my own plugin for.

In our case the clients catalog must only contain the products from the CSV source, which means that products imported at a certain date could possible be removed from the CSV in a later stage. But, using Magmi this products, that are no more existing in the CSV source, will still exist in my Magento store.

So, I made this real simple and tiny plugin (actually 2 plugins) with which you can delete or disable product from your Magento store when they do not exist anymore in the CSV source.

So, how to use these plugin`s:

  1. Download the plugin files here.
  2. Extract the ZIP
  3. There are two folders inside the zip, each of them is a plugin
  4. Upload the two folders to your server in the Magmi dir: /magmi/plugins/base/itemprocessors/
  5. Now go to your Magmi web interface (probably: websiteurl/magmi/web/magmi.php)
  6. In the list of plugins you will find 2 new plugins: ‘Missing products disabler’ & ‘Missing products deleter’
  7. Enable whichever you like, read the notes when enabling.
  8. That`s it, your all set. Importing should now delete missing products.

PS 1: I have put e-mail reporting in the plugins, read the instructions when enabling the plugin to add your own mailadres to the recipents. You will then be notified whenever products are deleted or disabled.

PS 2: I have put this code up for free, and you are free to use and share. However, it would be very much appreciated if you`d share the code via our site (this post). Thanks!

PS 3: If you encounter any problems with these plugins, please do contact us and we will fix it asap. Thanks!

 

31 Responses to “Magmi: delete or disable products missing in CSV / source”

  1. Hi

    Any solution for Multi Feeds yet?

    Thanks For your Amazing Extension

    Alex

    • Emvee Solutions 03/14/2016 at 10:07 am

      Hi Alex,

      Sorry, not yet.. We will post an update on this blog when this feature will be available.

  2. I was just wondering whether this would enable the product again if the product returns to the feed?

    • Emvee Solutions 09/18/2015 at 4:34 am

      Hi Mike, the plugin itself does not re-enable products but you could very easily arrange that with Magmi. For example, using the default values setter plugin which comes with Magmi by default, you could add a default value for attribute ‘status’. So, on import you enable all products, and since our script runs at the end of the import it will disable products missing in CSV.

      • Works perfectly. thank you 🙂

        • Emvee Solutions 09/21/2015 at 5:28 pm

          Cool! You`re welcome 🙂

          • I am sorry to be a pain but I have a huge problem which I will be so grateful if you had a solution.

            We import from over 10 feeds and we want to dissable products no longer in any of them but as we work with more than one feed, the disabler will delete all products from the other feeds as there not in the same one if that makes sense , is that correct?

            Is there a way around this?

            Is there a way for the disabler to search all sheets and then disable?

            Kind regards

            Mike

            • Emvee Solutions 09/22/2015 at 3:41 pm

              Hi Mike,

              No worries! I get your problem, unfortunately this is not supported yet..

              Apart from merging your feeds to one (CSV) file (if possible), I don`t have a solution at the moment. I`ll check this with our dev team, since I`ve heard this request more. Maybe in the near future we can add something to support this situation.

              • I appreciate your assistance and my colleague has already began merging the feeds using vlookup so I think we should be OK 🙂 Thanks again. Amazing extension.

              • Emvee Solutions 09/24/2015 at 11:36 am

                Cool, you`re welcome!

  3. Hello, I need to delete the products that are no longer present in the CSV file and I think that your plugins are an excellent solution.
    The main problem I have though is that I have more csv file in my shop, one for each supplier.

    When I import products with magmi, my csv files contain a field “supplier” that I insert into a custom magento product attribute, I created specially.

    Now how can I do to eliminate only the products present in csv of a particular vendor? what…
    Can you add some parameter that map the product delete with a custom parameter???

    • Emvee Solutions 07/06/2015 at 7:29 am

      Hi, currently this is not possible. You can contact us via the contact link above if you are interested in a quote for customization on the plugin to fit your needs.

  4. Hi,

    I wonder if this plugin works on store view scope?
    Because when i run import the plugin disable only product on default view, not on store view. Iam using Default Values setter v0.0.5 to add store and wesite to the csv file.

    thnx

    • Emvee Solutions 07/03/2015 at 1:14 pm

      Hi bakir,

      Actually ‘status’ is not a storeview scope field in Magento. The scope is website, so it should be disabled in all storeviews as long as you are running on one website. Also, by default the website scopes inherit the ‘default’ value for status, so if you did not change anything manually it should be disabled fine for the storeview scope.

      Probably, the problem is in the way you add the products. If you explicitly set the values for the ‘status’ field for each storeview, then it will not inherit the default value anymore. So I would be looking at the way you import / add your products. The best way would be to only set status = enabled for the default storeview and not import this field (status) at all for the site / storeview specifics import. That way the storeviews will inherit the default and our plugin will work fine. If you leave status empty for the specific storeviews or remove it from the imported columns it should inherit default.

      • Hi again,

        I have defined storeview when i import new products, because i have different name and price for each storeview. But i have not define any column for status in my csv file, but the status field is imported by Magmi. And i cant change that because Magmi always import required field if its not defined in csv. And as i have defined storeview the status will be imported to that storeview.

        Is there any solution for that?

        thnx

        • Emvee Solutions 07/30/2015 at 7:08 am

          Hi, you should check your settings for modules like default values setter, of missing columns, etc. To my knowledge Magmi does not automatically set missing columns, so my best guess is you overrride it in some module. Also, I recommend to do set the status for the default storeview product, but leave empty for the other translations.

  5. Hi again,

    Thnx for fast reply.

    I have modiffy the error massage in my last reply. I have deleted som paths.

    after i put your code i got this error when i start Magmi:

    Warning: require_once(../integration/inc/magmi_datapump.php): failed to open stream: No such file or directory in /home/mywebsite/www/public_html/magmi2/plugins/base/itemprocessors/zmissingproductdisabler/zmissingproductdisabler.php on line 3

    Fatal error: require_once(): Failed opening required ‘../integration/inc/magmi_datapump.php’ (include_path=’.:/usr/share/php:/usr/share/pear:../inc:/home/mywebsite/www/public_html/magmi/plugins/inc:/home/mywebsite/www/public_html/magmi/inc’) in /home/mywebsite/www/public_html/magmi/plugins/base/itemprocessors/zmissingproductdisabler/zmissingproductdisabler.php on line 3

    • Emvee Solutions 05/30/2015 at 11:05 am

      Hi, what about the cron? Does it run now after the change? If this does not work, please try the absolute path solutions, that should definitely work!

      • Hi again,

        The issue is now when i start Magmi not in PHP. When i put the code you give on first line i got error when i start Magmi. same issue when i run as command line.

      • Maybe stupid question, must i change directory on line 2 to my absolute path?

        • Emvee Solutions 06/01/2015 at 1:45 pm

          Hi, yeah, take a look at my answer on 05/30/2015 at 9:30 am below. You must change the second line to your absolute path

  6. Hi,

    It works with your last version. Thank you for your help and for a very good plugin.

  7. Hi,

    Thnx for you sharing the plugin.
    I have tried this plugin but it did not work for me. Have any one tried it and worked?

    • Emvee Solutions 05/19/2015 at 7:28 am

      Hi! We recently made an update to the plugin. Did you download the latest version and overwrite older files? It should work, at least it is working on our testserver and we have several users who confirmed this working.

      Do you see any error in the output box when running the import? If you use deleter function, did you enable the Magmi Productdeleter plugin as well? This is a default plugin and should be in your list. Or are you using disabler? If you are using deleter, can you try disabler and see if that`s working?

      • I have update now, it works fine, thnx for a nice plugin.

      • Hi Again,

        I have made some mistake, it was another plugin i have tested which worked. Your plugin doesnt work for me. Iam using disabler plugin. In your plugin i can send mail and i can make some changes for qty. Therefore i like to use your plugin if that works.
        I got this error massage:
        SKU BET0494 – 1 SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row –

        • Emvee Solutions 05/20/2015 at 3:02 am

          Hi Bakir,

          Thanks for your reply. I honestly doubt that this error is coming from our plugin since it would make no sense.. Can you share a screenshot of all enabled modules in Magmi so I can see if maybe a plugin is conflicting?

          The subquery error suggests that the subquery returns more then one result. We have ons subquery in our plugin, which is a query on the status attribute. If this error is generated by our plugin than it means you have 2 attributes with the attribute code ‘status’ in you Magento database. That would be very strange, but you could verify this by going to Catalog > Attributes > Manage attributes in Magento and search in the field attribute code for ‘status’. If it gives 2 results then there the error makes sense. But it should nog be possible to have 2 attributes with the same code name..

          However, to make sure it is not our plugin which throws this error I made a new version of our plugin. If you upload the latest version and still get this error, then I`m 100% sure it is not our plugin. So please test with this latest version. Make sure that in Magmi it shows version 0.0.4 for the disabled plugin.

          • Hi,

            I have update now, it works fine, thnx for a nice plugin.

            • Emvee Solutions 05/20/2015 at 9:13 am

              Awesome! Thanks for letting know.

              • Hi,

                I have tried to setup cron for import, but it doesn’t work. When i tried to run php command i got this error:
                PHP Fatal error: require_once(): Failed opening required ‘../integration/inc/magmi_datapump.php’ (include_path=’.:/usr/share/php:/usr/share/pear:/mywebsite/magmi/inc:/mywebgsite/magmi/integration/inc:/mywebsite/magmi/engines:/mywebsite/magmi/plugins/inc:/mywebsite/magmi/inc’) in /mywebsite/magmi/plugins/base/itemprocessors/zmissingproductdisabler/zmissingproductdisabler.php on line 2

                Any idea how i can fix this issue?

              • Emvee Solutions 05/30/2015 at 9:30 am

                Hi Bakir,
                You probably want to add this:
                chdir(dirname(__FILE__));

                To the top of this file:
                /mywebsite/magmi/plugins/base/itemprocessors/zmissingproductdisabler/zmissingproductdisabler.php

                Make sure you place it after the opening <?php tag (so not above this tag). After adding this, try again and let me know. The reason for this is cron needs absolute server paths and the script uses a relative path. So another option would be changing the include inside the zmissingdisabler.php file:
                /integration/inc/magmi_datapump.php

                to include via absolute path of your server, which would look something like: /home/yoursite/public_html/magmi/integration/inc/magmi_datapump.php

                Note that the real absolute path differs per server setup, I just mentioned the most common one. To find out your servers absolute path you can take a look here: http://stackoverflow.com/questions/6079479/how-to-get-the-absolute-path-to-the-public-html-folder

Leave a Reply