Comments

rtdean93’s picture

Thanks for this module... exactly what I needed.

One more question... I have a field that I have added to each product (field_product_category).

// Special treatment for a product, since we want to get the title from
// from the product entity instead of the line item.

How do I pull in a product field value for each ilne item?

andyg5000’s picture

Hey rtdean,
If you look at the commerce_email_extras.module file line 18-22, these are the table headers. Lines 37-41 are the row fields that create the line items table. You can edit those to include your extra category header and fields. You'll have to dissect the wrapper object to pull out the category value. I'd recommend creating your own module from the sandbox one that I have created because I have no plans of making this any more than a sandbox module for proof of concept. Let me know if you need any help.
Thanks,
Andy

kevster’s picture

Many thanks - just what I needed - appreciated!

rtdean93’s picture

Andy - I could use some direction.. Not sure how to dissect the wrapper object. Does the wrapper object include the product entity? The field I need is called 'field_main_title' which is an extra field for the product in addition to the regular title.

andyg5000’s picture

Hey rtdean93,
The $line_item_wrapper does include the product entity in $line_item_wrapper->commerce_product. You'll need to reference that specific field in the wrapper. For example, the following gets the product title:
$line_item_wrapper->commerce_product->title->value()

I imagine you can get your value by declaring the following:
$line_item_wrapper->commerce_product->field_main_title->value()

You can also use the get PropertyInfo() method and use print_r or dpm (with Devel module) to browse the wrappers elements. For example:
print_r($line_item_wrapper->commerce_product->getPropertyInfo());

Hopefully this helps!

andyg5000’s picture

I have updated the sandbox module to include all product types and not just the standard 'product' bundle.

RMani’s picture

I downloaded the sandbox version , having difficulties in enabling this module could you please help
regards,
Rekha

minneapolisdan’s picture

This looks promising, but has the sandbox disappeared? I couldn't access it. Never mind, I got it, thanks.

brephraim’s picture

This is nice, but unfortunately as written it doesn't support custom line item types.

jbekker’s picture

Mmh, for some reason I get the SKU on the product TD and the product title is gone. I checked your code but I can't figure it out.

brephraim’s picture

If a line item isn't of the "product" type, this is what happens, as a result of the "default" code.

andyg5000’s picture

Hey All,
I haven't looked at this module/post since June. I'll try to take a look at the issues this week and follow up. I originally posted this issue and sandbox as a concept of how you could achieve a more detailed line items table. It's probably best to get with the maintainers of this module and come up with a solution that can be committed to it instead of trying to create a new add on module.
-A

brephraim’s picture

Well, I really appreciate this code, I was able to modify it to work for the custom line item types on my site, but unfortunately I'm not code savvy enough to be able to come up with a generic patch.

mrpeanut’s picture

Would love to see the sandbox module committed. It works great!

mrpeanut’s picture

@andyg5000 — I realize this wasn't ever meant as a module or something that you are making customizations for, but is it possible to move the shipping line item under Subtotal? So, for example...

Line Items
Subtotal
Shipping Service
Total
Balance

mrpeanut’s picture

@brephraim — Could you share how you modified the module to work with custom line items? I have a custom line item sampler and am having the same issue you were.

brephraim’s picture

Find the lines

  foreach ($wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    switch ($line_item_wrapper->type->value()) {

And then insert this underneath:

	  case 'sampler-pack':
        $title = htmlentities($line_item_wrapper->commerce_product->title->value(), ENT_QUOTES, 'UTF-8');
        $title .= commerce_email_order_item_attributes($line_item_wrapper->commerce_product->product_id->value());

        $rows[] = array(
          'data' => array(
            array('data' => $line_item_wrapper->quantity->value(), 'style' => array('text-align: left;' . 'border-bottom: 1px solid black;' . $td_style)),  
            array('data' => $title, 'style' => array('text-align: left;' . 'border-bottom: 1px solid black;' . $td_style)),
			array('data' => "<span style='width:0px;'></span>", 'style' => array('text-align: left;' . 'border-bottom: 1px solid black;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), $currency_code), 'style' => array('text-align: right;' . 'border-bottom: 1px solid black;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_total->amount->value(), $currency_code), 'style' => array('text-align: right;' . 'border-bottom: 1px solid black;' . $td_style)),
          )
        );
        break;

Actually, now that I think of it, I'm pretty sure I altered the $rows array. The above code gives you the basic idea though, what you may be able to do to get it to work with the default config is to just delete the $rows declaration from the above code, and instead copy in the corresponding declaration from the case (in_array($line_item_wrapper->type->value(), $product_types)): code block in the original module.

Let me know if I can help in any other way.

mrpeanut’s picture

I wasn't able to get the custom line item to show up. Here's exactly what I entered underneath switch ($line_item_wrapper->type->value()) {. I tried changing commerce_product to commerce_sampler, tried your original code, etc.

	  case 'commerce_sampler':
		$sku = $line_item_wrapper->commerce_sampler->sku->value();
        $title = htmlentities($line_item_wrapper->commerce_sampler->title->value(), ENT_QUOTES, 'UTF-8');
        $title .= commerce_email_order_item_attributes($line_item_wrapper->commerce_sampler->product_id->value());

        $rows[] = array(
          'data' => array(
            array('data' => $sku, 'style' => array('text-align: left;' . $td_style)),
            array('data' => $title, 'style' => array('text-align: left;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), $currency_code), 'style' => array('text-align: right;' . $td_style)),
            array('data' => $line_item_wrapper->quantity->value(), 'style' => array('text-align: right;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_total->amount->value(), $currency_code), 'style' => array('text-align: right;' . $td_style)),
          )
        );
        break;

I'm not very proficient with PHP yet, unfortunately.

brephraim’s picture

OK, well I guess let me back up: does this line item still refer to a product? I had assumed that was the case, otherwise the code will for sure not work.

mrpeanut’s picture

Oh, yes, it does. But the product type machine name is sampler, although it is still a product. And then my custom line item (via Commerce Customizable Products) is sampler-pack.

brephraim’s picture

I modified the code in my original reply to your question. As I was saying, your columns might be off, but at least it should show up, and you can copy the $rows array code from the code already in your module as I described.

mrpeanut’s picture

Still no luck. This is my code (from #17, removed your rows array code and replaced it with the rows array code from the existing module).

	  case 'sampler-pack':
        $title = htmlentities($line_item_wrapper->commerce_product->title->value(), ENT_QUOTES, 'UTF-8');
        $title .= commerce_email_order_item_attributes($line_item_wrapper->commerce_product->product_id->value());

        $rows[] = array(
          'data' => array(
            array('data' => $line_item_wrapper->quantity->value(), 'style' => array('text-align: left;' . 'border-bottom: 1px solid black;' . $td_style)), 
            array('data' => $title, 'style' => array('text-align: left;' . 'border-bottom: 1px solid black;' . $td_style)),
			array('data' => "<span style='width:0px;'></span>", 'style' => array('text-align: left;' . 'border-bottom: 1px solid black;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), $currency_code), 'style' => array('text-align: right;' . 'border-bottom: 1px solid black;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_total->amount->value(), $currency_code), 'style' => array('text-align: right;' . 'border-bottom: 1px solid black;' . $td_style)),
          )
        );
        break;
mrpeanut’s picture

Ahh, yes, I'm partially an idiot. The machine name is actually sampler_pack not sampler-pack. You're right, the columns are messed up, but the data is there. Now if I could just find a way to show the product display title in addition. :) Thank you!

brephraim’s picture

It should be fairly simple to rearrange the code so the columns display as needed.

As for the product display title, that's probably going to be be a tougher nut to crack.

andyg5000’s picture

As a heads up, I've renamed this "module" to Commerce Extra Tokens and split the different invoice parts into their own tokens. This allows for it to be used with more than just Commerce Email. Since Commerce Kickstart uses the message notify module, this will hopefully help more people who are trying to send detailed line items in their order emails. There are examples of how to use it with commerce_email and message_notify on this page http://drupal.org/sandbox/andyg5000/1532508 .

mengi’s picture

Thank you for all your work, I would love to see this as a module or integrated with Commerce Email.

camizzz’s picture

Great work!
i've a question.
Is it possible to print a field included into a line item types?
ex: line item type -> product -> field_customization

I would like to include in the order email the details of the customer customization.
the customizations are inserted with the Commerce Customizable Products module.

I hope you can help me!
greetings from italy :)

mrpeanut’s picture

@camizzz -- Did you find a way to insert the field data from a Commerce Customizable Products field? Trying to do the same thing.

mrpeanut’s picture

@camizzz — Not sure if you saw this, but a similar question exists at #1895022: Can you show a code example of how to access custom line item values in code?. I've tried changing the code from #22 to below, with no luck:

  foreach ($wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    switch ($line_item_wrapper->type->value()) {
	  case 'sampler_pack':
        $sku = $line_item_wrapper->commerce_product->sku->value();
        $title = htmlentities($line_item_wrapper->commerce_product->title->value(), ENT_QUOTES, 'UTF-8');
        $title .= commerce_email_order_item_attributes($line_item_wrapper->commerce_product->product_id->value());
		$flavor_1 = $line_item_wrapper->field_flavor_1->value();

        $rows[] = array(
          'data' => array(
            array('data' => $sku, 'style' => array('text-align: left;' . $td_style)),
            array('data' => $title, 'style' => array('text-align: left;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), $currency_code), 'style' => array('text-align: right;' . $td_style)),
            array('data' => $line_item_wrapper->quantity->value(), 'style' => array('text-align: right;' . $td_style)),
            array('data' => commerce_currency_format($line_item_wrapper->commerce_total->amount->value(), $currency_code), 'style' => array('text-align: right;' . $td_style)),
          )
        );
        break;
camizzz’s picture

@MrPeanut - thanks for your help! I've found a way to output the field into the email, but it works only for input textfield. if i try to put in a field type "Term reference" which widget is Select list/Check boxes/radio buttons, I've got this error:

RECOVERABLE FATAL ERROR: OBJECT OF CLASS STDCLASS COULD NOT BE CONVERTED TO STRING IN _THEME_TABLE_CELL()

i would like to output the "names" of the taxonomy terms.

This works perfectly for input field

$line_item_wrapper->MY_LINE_ITEM_FIELD->value();

Thanks
Cami

mrpeanut’s picture

I just accomplished the same exact thing (with taxonomy term names). My field name is field_flavor.

$flavor = $line_item_wrapper->field_flavor->value(); then $flavor->name (if I remember correctly, I can check my code if that doesn't work).

camizzz’s picture

@MrPeanut - Thank you! It works perfectly!

$line_item_wrapper->MY_FIELD->value()->name;
camizzz’s picture

$line_item_wrapper->MY_FIELD->value()->name; works correctly only for select and radio buttons but not for Check Boxes. this is not strange? there is another way?
is there a reference page where can i find all kind of values?
ex: value()->name , value()->VALUE HERE

Thanks,
Cami

andyg5000’s picture

Cami,

Inspect the wrapper object with $line_item_wrapper->getPropertyInfo(); You can run that through dpm (devel module) or var_dump/print_r and it will show you the properties within the $line_item_wrapper object. Then you'll know which property is available for use. I always suggest checking the existance of the field before attempting to access the value(). For example:

if (!empty($line_item_wrapper->my_field)) {
  $value = $line_item_wrapper->my_field->value();
  print $value->name; 
}

Hopefully this helps!

-A

camizzz’s picture

maybe this is the moment to learn how to use devel module. I've no idea how to use your explanation. Currently to check that the value is outputted, i create the order and i check the sent email. I know, maybe this isn't the right way to work.
Can you explain me how and where insert $line_item_wrapper->getPropertyInfo(); ?
Thank you!

shaneonabike’s picture

Amazing!

zpolgar’s picture

I tried to use payment methods token in e-mail, but there is only the token name what I see in the mail.

zpolgar’s picture

The payment method token not work separately, with the other tokens its ok.

zpolgar’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

My problem is that the line items not show the discounted price. In the cart and during the checkout process I use discounted price for a line item but in the email I send the original price. Its a little bit confused. What can i do?

kevster’s picture

@MrPeanut - did you ever get the shipping included in the summary totals belwo sub total? I managed to do this by changing commerce_extra_tokens.module around line 125 add another elseif:

// add in shipping here ex VAT...
      elseif (strpos($data['components'][$key]['name'], 'flat_rate_') === 0) {
        $rows[] = array(
          'data' => array(
            array('data' => t('Shipping:'), 'style' => array('font-weight: bold; text-align: right;' . $styles['td_style'])),
            array('data' => commerce_currency_format($data['components'][$key]['price']['amount'], $currency_code), 'style' => array('font-weight: bold; text-align: right;' . $styles['td_style'])),
          )
        );
      }
      // end shipping

This works for me and I just hide the previous shipping code that puts the shipping in inc VAT above the totals. Only thing I cant do now is change the weighting as the shipping appears below the VAT. Any ideas @andyg5000 on how to change the weighting to move shipping above the VAT?

janamills’s picture

perfect thanks! :-)

johnpitcairn’s picture

Note that now the patch from #1332698: Allow theming of [commerce-order:commerce-email-order-items] has been committed, the [commerce-email:commerce-email-order-items] table can be completely overridden in a new theme function, theme_commerce_email_order_items(). The full $order entity is supplied as a variable, and you can generate line-items/product/shipping/etc from that.

So it is now also possible to achieve just about anything you want using the standard token and a theme override.

waltercat’s picture

For those of us who don't know how to theme and create modules, how can we edit the line item table? I have been able to use htmlmail to override the template, but other than that, I have no clue how to begin changing the template. I tried reviewing this issue as well as these two issues, but they all link and refer to one another but I can't figure out what exactly to do to override the line item table.

https://drupal.org/node/1332698
https://drupal.org/node/1605586

Motlem’s picture

Issue summary: View changes

This module is working great for me, but I have one issue that I have not been able to overcome. I have a custom field in the line item that stores an integer value. I am able to get it to display just fine in the table, but I would like to sort the array by this value. I'm sure I'm probably missing something simple, but if someone knows how to resort this, I would appreciate the help.

I have:

$rows[] = array(
  'data' => array(
    array('data' => $sku, 'style' => array('text-align: left;' . $styles['td_style'])),
    array('data' => $title, 'style' => array('text-align: left;' . $styles['td_style'])),
    array('data' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), $currency_code), 'style' => array('text-align: right;' . $styles['td_style'])),
    array('data' => $line_item_wrapper->quantity->value(), 'style' => array('text-align: right;' . $styles['td_style'])),
    array('data' => commerce_currency_format($line_item_wrapper->commerce_total->amount->value(), $currency_code), 'style' => array('text-align: right;' . $styles['td_style'])),
    array('data' => $shelf, 'style' => array('text-align: left;' . $styles['td_style'])),
  )
);

and would like to be able to sort this by the $shelf value. My gratitude to anyone that can provide some assistance.

Zoltan Komar’s picture

Hi!

I'm trying to create a new site wich uses this modul but there's one small problem wich i can't seem to figure out. I can't render the pizza toppings in a notification e-mail. The Toppings part is a field item but i can't render the field item in notification.As it seems its missing something i just can't figure it out. I tried all different methods from this and all other forums none of it works. I hope someone can help me.
Thanks in advance!

rszrama’s picture

Status: Active » Closed (outdated)