You are here

function product_node_import_prepare in Node import 5

Implementation of hook_node_import_prepare().

File

supported/ecommerce/product.inc, line 39
Support file for product.module of the e-commerce module bundle.

Code

function product_node_import_prepare(&$node, $preview = FALSE) {
  $errors = array();
  if ($node->type == 'product') {
    if (isset($node->price)) {
      $price = normalize_price($node->price);
      if ($price === FALSE) {
        $errors[] = t('Price (%value) is not valid. It must only contain integers, decimal point and a currency symbol.', array(
          '%value' => $node->price,
        ));
      }
      else {
        $node->price = $price;
      }
    }
    else {
      $node->price = 0;
    }
    if (isset($node->hide_cart_link) && strlen($node->hide_cart_link) > 0) {
      switch (strtolower($node->hide_cart_link)) {
        case 'visible':
          $node->hide_cart_link = 0;
          break;
        case 'hidden':
          $node->hide_cart_link = 1;
          break;
        default:
          $node->hide_cart_link = $node->hide_cart_link ? 1 : 0;
          break;
      }
    }
    else {
      $node->hide_cart_link = 0;
    }
    if (variable_get('payment_recurring', 0)) {
      if (isset($node->price_interval) && strlen($node->price_interval) > 0) {
        if (!is_numeric($node->price_interval) || $node->price_interval < 0 || $node->price_interval > 31) {
          $errors[] = t('Price interval (%value) is not valid. It must be an integer between 0 and 31.', array(
            '%value' => $node->price_interval,
          ));
        }
      }
      if (isset($node->price_unit) && strlen($node->price_unit) > 0) {
        $options = array(
          t('days') => 'D',
          t('day(s)') => 'D',
          t('day') => 'D',
          'd' => 'D',
          t('weeks') => 'W',
          t('week(s)') => 'W',
          t('week') => 'W',
          'w' => 'W',
          t('months') => 'M',
          t('month(s)') => 'M',
          t('month') => 'M',
          'm' => 'M',
          t('years') => 'Y',
          t('year(s)') => 'Y',
          t('year') => 'Y',
          'y' => 'Y',
        );
        if (!isset($options[strtolower($node->price_unit)])) {
          $errors[] = t('Price interval unit (%value) is not valid. It must either be "d" (days), "w" (weeks), "m" (months) or "y" (years).', array(
            '%value' => $node->price_unit,
          ));
        }
        else {
          $node->price_unit = $options[strtolower($node->price_unit)];
        }
      }
      if (isset($node->price_cycle) && strlen($node->price_cycle) > 0) {
        if (!is_numeric($node->price_cycle) || $node->price_cycle < 0 || $node->price_cycle > 31) {
          $errors[] = t('Number of payment cycles (%value) is not valid. It must be an integer between 0 and 31.', array(
            '%value' => $node->price_cycle,
          ));
        }
      }
    }
  }
  return $errors;
}