CoreCommerce - outputting customer choices attribute in receipt email.

Permalink
Im trying to output a custom attribute value into a receipt and order email.
the problem im having, is the attribute is repeated and added for each product in the cart. So when the email is sent, this is what I get:
<product1> - <product1 attribute>
<product2> - <product1 attribute>, <product2 attribute>
Product 2 is getting product 1's attribute AND its own... the same keeps happening the more products that are added (ie the next product gets all previous attributes and its own).

Im sure it has something to do with the way I'm looping through it.. Any help would really appreciated!

Here is the code from my receipt email.
for ($i = 0; $i < count($products); $i++) {
  $body .= $products[$i]['quantity'] . " x " . $products[$i]['name'] . " " . $products[$i]['description'];
  if (count($products[$i]['attributes'])) {
       foreach($products[$i]['attributes'] as $key => $attr) {
          // here we set a conditional on the attribute to only display if active
          if (isset($attr)) {
            // here we remove the key (label name) and add a space in front of the attribute value
            $keyValues[$i] = " " . $attr;
          }
           // another conditional to display only if set. 
           if ($keyValues[$i]) {
              $body .= implode(",", $keyValues[$i]);
              // $body .= $keyValues[$i];
          }
       }

jpcharrier
 
jpcharrier replied on at Permalink Best Answer Reply
jpcharrier
It appears as though I have overcomplicated things here. Basically tacking the $attr onto the body was all that was needed... See updated code below.
for ($i = 0; $i < count($products); $i++) {
  // SSB Edit
  // Here we tack the description to the end of this string ( $products[$i]['description'])
  $body .= $products[$i]['quantity'] . " x " . $products[$i]['name'] . " " . $products[$i]['description'];
  if (count($products[$i]['attributes'])) {
       foreach($products[$i]['attributes'] as $key => $attr) {
          $body .= " " . $attr;
       } 
    }
  $body .= " @ " . $products[$i]['price'] . "\r\n\r\n";    
}