Auto generate the product title

Hi, is that possible to hide the product title field in the "Add a product" page? or maybe it could automatically generated from the other fields?

Posted: Dec 21, 2011


nrackleff on January 31, 2012

I would love to see this too. We are creating a site where the client wants the title to be the SKU concatenated with a required taxonomy term. Even if we could just make the title not required it would help.

rfay Randy Fay on January 31, 2012

Actually, it's not hard at all to do a simple rule that builds a title based on other fields. The [attached rule](http://www.drupalcommerce.org/sites/default/files/auto_title_products.ru...) builds a title based on the SKU. It listens to the "before saving a product" event, and just sets the title. Of course, this will override anything you may have in the title field. It also does not deal with the fact that the title field is required. A little form alter could fix that.

nrackleff on February 1, 2012

I have two types of products in the store and I only want to apply this rule to one of them. I thought I could add a condition, but when I tried the condition 'Entity is of Type', I can select Commerce Product, but there is no option to select a particular type of commerce product. I looked at the Commerce Extra Conditions module, but it doesn't seem to contain such a condition either. Any idea how I can accomplish this? Thanks again for your help.

rfay Randy Fay on February 1, 2012

Unfortunately there's quite a lot of confusion about what "type" means. Entity type is "commerce_product" or "commerce_order". *Bundle* type is what you want. To do that you do a data comparison on commerce-order:type and see if it's of the type you want.

nrackleff on February 1, 2012

That works great. I was able to create a new rule through the interface and it worked when I tested it. I just put dummy data in the title field so I could submit since it was a required field. Once the product was saved, my dummy data had been overwritten with the SKU. I will deal with the hook_form_alter and the concatenation of the SKU and the other field tomorrow. The other filed is a taxonomy term. This is all so new to me, but I am beginning to recognize how powerful it is. Thank you so much for your help.

frankye on February 2, 2013

This is rule "SKU to title" with php code:

{ "rules_before_saving_product_change_title" : {
    "LABEL" : "Before saving product change title",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "php", "rules", "entity" ],
    "ON" : [ "commerce_product_presave" ],
    "DO" : [
      { "php_eval" : { "code" : "if(isset( $commerce_product-\u003Esku)) {\r\n$commerce_product-\u003Etitle = $commerce_product-\u003Esku;\r\n}" } }