Allround Webdevelopment

Header Menu

Blog

Search for:

Magmi: delete or disable products missing in CSV / source

04/19/2015

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.

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!

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.

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?

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.

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???

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.

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.

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.

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.

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

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 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 –

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.

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

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

Recent posts

Testimonial

The support is great and the installation was easy. We are using both extensions for our customers. Both extensions are powerfull and rich featured. Way to go! Cheers, Gerard – Silvasoftboekhoudprogramma

Silvasoft

About

Emvee Solutions is a webdevelopment company from the Netherlands. We are a group of enthousiastic developers, always looking for new and innovative products (plugins & extensions). We are specialized in Magento & Wordpress development.

Our products

We provide:

Money back guarantee (15-days)

Good and quick support

Onetime payment, lifetime usage

Proven, safe and well tested code

Helpdesk

Please contact us if you have any problem or question about one of our products. Find out how to contact us on our support page.