I have a variation creation form with a size taxonomy. And instead of having a fixed selection list for terms, I allow the administrator to add new terms as the comes in. For this I am using the Autocomplete term widget and the user just write a new term name. This has a small bug. That the line items is not displayed correctly if added to cart. But if variation is deleted and recreated with same term it works.

Steps for reproduce:

  • Install Commerce Kickstart 1.6
  • Install Inline Entity Form 7.x-1.x-dev (2012-Apr-25)
  • Add vocabulary Size.
  • Add termreference to Size for Product. (Product type)
    • Use widget Autocomplete term widget
    • Use Size vocabulary
    • Enable this field to function as an attribute field on Add to Cart forms
    • Attribute selection widget: Select list
  • Change widget type for Product-field for the Product Display
    • To "Inline entity form"
  • Edit "Product One"
  • Add variation
    • Set Size to "Large"
    • Set SKU to "LargeTshirt"
    • Set Price to "10" USD
    • Skip image
  • Save "Product One"
  • Add Large variation to cart

In Shopping cart block the title is now "Product One ()". Should be "Product One(Large)".

  • Now edit "Product One"
  • Delete the Large variation.
  • Recreate Variation
    • Set Size to the already existing size "Large"
    • Set SKU to "LargeTshirt2"
    • Set Pric to "10" USD"
    • Skip image
  • Save "Product One"
  • Add Large variation to cart

Now the shopping cart block has the correct line item displayed with "Product One (Large)".

So there is a bug when creating new taxonomy term for product. But reusing existing terms works.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wesleydv’s picture

Status: Active » Needs review
FileSize
1.02 KB

I have found myself in the same situation and can confirm that this is indeed a bug.
I attached a patch solving this issue but I'm not sure if it is most efficient/secure way to do it.
It also adds support for empty attributes (eg. not required attributes).

rupertj’s picture

wesleydv's patch fixes the Issues I've been having with non-required fields, and products showing up with titles like Product (Small, , ).

Here's a re-roll against current -dev.

kristofferwiklund’s picture

Status: Needs review » Reviewed & tested by the community

It works nice.

Thanks

bojanz’s picture

Status: Reviewed & tested by the community » Needs work

Needs to be rerolled against latest -dev, no longer applies.

christosku’s picture

Status: Needs work » Needs review
FileSize
1.1 KB

A reroll against current -dev.

star-szr’s picture

Status: Needs review » Needs work

Thanks for the reroll, @christosku!

+++ b/includes/commerce_product.inline_entity_form.incundefined
@@ -358,7 +358,18 @@ class CommerceProductInlineEntityFormController extends EntityInlineEntityFormCo
+            foreach ($entity as $field) {
+              if (is_array($field) && isset($field['und'][0]['tid'])) {
+                $attribute_values[] = $field['und'][0]['name'];
+             }
+            }

I don't think this patch will get committed with 'und', and probably not with LANGUAGE_NONE, either. Is it possible to refactor this to use the Entity API metadata wrapper instead, ala $wrapper->{$field_name}->value()?

Minor: the closing bracket for the if statement needs to be indented by one space.

star-szr’s picture

Status: Needs work » Needs review
FileSize
1.32 KB
1.23 KB

The filtering for empty attributes can cause errors if all attributes are empty:

Notice: Undefined variable: attribute_values in save()
Warning: implode() [function.implode]: Invalid arguments passed in implode()

If we check (!empty($attribute_values)) that should do the trick, and then we don't end up with Product ().

Here's a new patch which fixes the indentation, replaces 'und' with LANGUAGE_NONE, and doesn't run a foreach() for each taxonomy field. I'm not sure if we need to check for tid anymore, especially if we know the field belongs to the taxonomy module.

I did try to get the taxonomy term information via the Entity API, but came up empty, perhaps because the term hasn't been saved yet.

One remaining issue is that if multiple taxonomy terms are added to one taxonomy field, only the first term will be displayed.

UrmasZ’s picture

For me last patch(#7) is working. Thanks. :)

akalata’s picture

With #7, I still get the '()' even when there should be one out of two attributes listed. I'm going to play with it today, but in case I get distracted I'm also getting this error message after saving the product:
Notice: Undefined index: name in CommerceProductInlineEntityFormController->save() (line 383 of ... inline_entity_form/includes/commerce_product.inline_entity_form.inc).

akalata’s picture

My taxonomy field was only saving the tid, so I had to use taxonomy_term_load to get the name.

akalata’s picture

I also created a separate issue for updating existing products whose titles have already been saved: #1811390: Batch update existing product titles autogenerated by Inline_Entity_Form.

GuyPaddock’s picture

After applying #10, I'm still not getting taxonomy-driven attributes in the titles.

I have 1 required taxonomy attribute, and 3 optional. Perhaps this is the issue?

kristofferwiklund’s picture

Status: Needs review » Needs work

Patch is not applying. And manual apply changes is not working either.

vasike’s picture

Status: Needs work » Needs review
FileSize
1.19 KB

so the issue here was about the new product attribute terms using autocomplete widget for taxonomy term fields.

it seems the previous patches provided or a solution only for this case (new term) or for the existing term (already working).

here is patch that should help to add the new and old terms attributes to product title.
i'm not sure about the language key (LANGUAGE_NONE) used for this.

it seems this autocomplete widget for taxonomy term reference fields brings some issues in IEF.
there's another one : #1723864: Term multiplication for new Term values added for Term fields with autocomplete widget on multiple references fields.

kingfisher64’s picture

I'm getting these output when I try to add a product. What can be done to get rid of these notices? Many thanks

Notice: Undefined index: sku in CommerceProductInlineEntityFormController->entityForm() (line 175 of /var/www/virtual/domain.co.uk/htdocs/sites/all/modules/inline_entity_form/includes/commerce_product.inline_entity_form.inc).

Notice: Undefined index: status in CommerceProductInlineEntityFormController->entityForm() (line 194 of /var/www/virtual/domain.co.uk/htdocs/sites/all/modules/inline_entity_form/includes/commerce_product.inline_entity_form.inc).
kingfisher64’s picture

Update - setting sku to non auto generated appears to output these messages. However changing the setting back to auto sku doesn't fix it. Only a db restore did in this case?

yingtho’s picture

Here is a patch for the undefined index sku/status.

Status: Needs review » Needs work

The last submitted patch, 17: inline_entity_form-1559968-17.patch, failed testing.

oncreative’s picture

Any progress on this? I'm having this issue and have done a DB restore but has not fixed this.