Using Feeds, I am trying to import products from a source CSV. One of the CSV columns contains the quantity of items in stock. The goal is to map it to a product 'Stock Status' field. If the quantity field is greater than zero, 'Stock Status' is 'In Stock'; if zero, 'Stock Status' is 'Out of Stock'.

I didn't see a Feeds Tamper plugin or combination of plugins that would work and my attempts to use Rules so far have failed.

Thank you in advance for any help.


The easiest is to just put a formula into a spreadsheet and alter your source csv.

Else you could write your own feeds tamper plugin.

Create an empty file called 'stock.inc' and place it into the feeds_tamper/plugins directory. Add this to it:

$plugin = array(
  'form' => 'feeds_tamper_stock_form',
  'callback' => 'feeds_tamper_stock_callback',
  'name' => 'Calculate stock',
  'multi' => 'direct',
  'category' => 'Other',

function feeds_tamper_stock_form($importer, $element_key, $settings) {
  return array(
    'help' => array(
      '#markup' => t('Sets the stock status'),

function feeds_tamper_stock_callback($result, $item_key, $element_key, &$field, $settings, $source) {
  $field = $result->items[$item_key] > 0 ? 'In Stock' : 'Out of Stock' ;

Clear your cache.

I have not tested this but I believe it will get you close.

  • I can't control the format of the spreadsheet so I went with your Feeds Tamper approach. I downloaded the 'Feeds Tamper PHP' module and added 3 lines of code. It seems like a simpler and more maintainable solution. Thank you for your guidance. I didn't know whether to use Rules or Feed Tamper. You saved me hours and a lot of uncertainty over whether I used the right approach or not. – user320691 Sep 11 '14 at 17:46

Using J. Reynolds' answer as a guide, I downloaded Feeds Tamper PHP and added the following code to a feeds tamper PHP plugin.

if ($item['quantity'] > 0) {
  return 1;
} else {
  return 2;

The destination field is of 'List (text)' type with 1 representing 'in stock' and 2 representing 'out of stock'.

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.