6 replies [Last post]
holeyhippiegeek's picture
Offline
Joined: 05/20/2008
Juice: 34
Was this information Helpful?

I have the cart set up so that each product purchased requires the input of info from the user via several attributes and their options. How can I get these options to be listed in the EDI export pattern (using the EDI module)? I don't know if, how, or where to find the keywords for the attributes.

Please speak very slowly. . . Smiling
--Reagan

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: EDI to print attributes??

There are no ready made keys for something like this, unfortunately. You'll have to add the keys to the UC EDI module, though it's not a bad feature request. You can try something like this in the function uc_edi_order_product_values():

<?php
  $values
['!attributes'] = '';
 
$options = $product['data']['attributes'];
  if (
module_exists('uc_attribute') && is_array($options)) {
    foreach (
$options as $attribute => $option) {
     
$values['!attributes'] .= t('@attribute: @option', array('@attribute' => $attribute, '@option' => $option)) .'; ';
    }
  }
?>

You'd have to do some other coding to get the display to be more specific, like per attribute tokens or something.

melanie_me's picture
Offline
Joined: 03/29/2009
Juice: 108
Re: Re: EDI to print attributes??

I have this module working and printing the attributes. I figured I'd share what I did with the community...

I added the above code here:

// Returns a list of replacement values for product export patterns.
function uc_edi_order_product_values($product) {
  $product = (array) $product;

  foreach (array_keys($product) as $key) {
    if (!is_array($product[$key]) && !is_object($product[$key])) {
      $values['!'. $key] = $product[$key];
    }
  }

  $values['!batch_id'] = variable_get('uc_edi_order_next_batch_id', 1000);
  $values['!#'] = variable_get('uc_edi_order_product_line_number', 1);
  variable_set('uc_edi_order_product_line_number', $values['!#'] + 1);
  $values['!attributes'] = '';
  $options = $product['data']['attributes'];
  if (module_exists('uc_attribute') && is_array($options)) {
    foreach ($options as $attribute => $option) {
      $values['!attributes'] .= t('@attribute: @option', array('@attribute' => $attribute, '@option' => $option)) .'; ';
    }
  }

  $values['!spacer'] = ' ';

  return $values;

Then I added !attributes to the order product export pattern in the Order Export Settings in admin>store>settings>edi

melanie_me's picture
Offline
Joined: 03/29/2009
Juice: 108
Update!!

Actually, this is not working as planned! All attributes for registrations made after the most recent Ubercart update (ubercart 6.x-2.0-rc6) are not exporting!!

I have all the attributes up to that point, then nothing! I really need help with this before the end of the day!

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: EDI to print attributes??

Each attribute can be stored with more than one option now, so $option is now an array in your code. This is the way the order invoices display attributes:

<?php
  $values
['!attributes'] .= t('@attribute: @options', array('@attribute' => $attribute, '@options' => implode(', ', (array)$option))) .';';
?>
melanie_me's picture
Offline
Joined: 03/29/2009
Juice: 108
Re: Re: Re: Re: EDI to print attributes??

So, now my code looks like this:

// Returns a list of replacement values for product export patterns.
function uc_edi_order_product_values($product) {
  $product = (array) $product;

  foreach (array_keys($product) as $key) {
    if (!is_array($product[$key]) && !is_object($product[$key])) {
      $values['!'. $key] = $product[$key];
    }
  }

  $values['!batch_id'] = variable_get('uc_edi_order_next_batch_id', 1000);
  $values['!#'] = variable_get('uc_edi_order_product_line_number', 1);
  variable_set('uc_edi_order_product_line_number', $values['!#'] + 1);
  $values['!attributes'] .= t('@attribute: @options', array('@attribute' => $attribute, '@options' => implode(', ', (array)$option))) .';';

  $values['!spacer'] = ' ';

  return $values;

But it is not returning any attribute data. Any ideas?

melanie_me's picture
Offline
Joined: 03/29/2009
Juice: 108
Okay, nevermind!! My code

Okay, nevermind!!

My code now looks like this:

// Returns a list of replacement values for product export patterns.
function uc_edi_order_product_values($product) {
  $product = (array) $product;

  foreach (array_keys($product) as $key) {
    if (!is_array($product[$key]) && !is_object($product[$key])) {
      $values['!'. $key] = $product[$key];
    }
  }

  $values['!batch_id'] = variable_get('uc_edi_order_next_batch_id', 1000);
  $values['!#'] = variable_get('uc_edi_order_product_line_number', 1);
  variable_set('uc_edi_order_product_line_number', $values['!#'] + 1);
$values['!attributes'] = '';
  $options = $product['data']['attributes'];
  if (module_exists('uc_attribute') && is_array($options)) {
    foreach ($options as $attribute => $option) {
      $values['!attributes'] .= t('@attribute: @options', array('@attribute' => $attribute, '@options' => implode(', ', (array)$option))) .';';
    }
  }

  $values['!spacer'] = ' ';

  return $values;

And it's working just the way I need it to! Thanks for your help!