Hello,

i am using 1.0-alpha3 and i want to display the title after an imagefield. But in the content type's display options i am able to see all the other fields, except for the title field. So the title appears only above/under the product reference object.
Is it possible, somehow to change that order?

Thank you,
apanag

Comments

rszrama’s picture

Title: Is there a title field available on display options for a content type? » Render product title / SKU in the node display context instead of just field data
Version: 7.x-1.0-alpha3 » 7.x-1.x-dev
Component: Product » Product reference
Category: support » feature

Right now, this module is only pulling field data from referenced products into the node for display. Because product titles aren't fields but are part of the product entity, this data is not being brought in. I suppose I'll go ahead and make this a feature request and change it to include the SKU as well, but it isn't high priority at this point - it's just a bit of grunt work to duplicate the code that works for field data to work on the entity properties as well.

apanag’s picture

Ryan,

do we have an ETA on this?

Thanks for your hard work.

apanag

rszrama’s picture

Not really. It's not something I'm actively pursuing at the moment, so it's on the "sooner or later" track. : P

rszrama’s picture

Issue tags: +low-hanging fruit

Tagging.

pcambra’s picture

Issue tags: +dcparisprintmarch

Tagging

apanag’s picture

Any updates on this?

Thank you.

rszrama’s picture

Tagging.

rfay’s picture

Title: Render product title / SKU in the node display context instead of just field data » Render property data in the product reference formatter instead of just field data
Status: Active » Needs review
StatusFileSize
new49.18 KB
new27.54 KB
new3.9 KB

OK, well... Somebody who knows the entity ropes better than I do will be able to give me some direction here. Unfortunately, there's no default formatting that I understand for properties.

This patch makes all properties available; It displays them. Setting to needs review but it actually "needs help" :-)

  • It doesn't do a very sophisticated job of displaying them. Surely somebody can suggest an appropriate technique
  • It still says "Settings are on the product type display page", which isn't true

Display:
rfay_dell_Selection_087.png

Configuration:
rfay_dell_Selection_086.png

MickL’s picture

need a $commerce_title, $commerce_sku and $commerce_type for the productdisplaynode.tpl.php that changes dynamically like <?php print render($content['product:commerce_price']);?>

rfay’s picture

@benchi: If I understand you you're asking for a hook_preprocess() that adds these new items as variables for you to use in your own tpl.php?

rszrama’s picture

StatusFileSize
new19.32 KB

Thanks for getting the ball rolling, Randy. It turned out to be more complicated than I expected, or rather it kept getting more and more complicated the more I tried to use the core Field API. : P

It turns out we can use field_info_extra_fields() to find out which extra fields have been made available on Products when adding them to the display fields of referencing entities. However, we can't use the same method within hook_field_extra_fields() itself, so I have to resort to calling the Product module's extra fields function directly in commerce_product_field_extra_fields(). Figuring that out wasted a couple hours. :-/

The attached patch changes from using the Entity API's understanding of properties to using extra fields, as those are the only properties that will be visible on a Product's "Manage display" tab anyways. We already have theme functions available for the extra fields that are currently present for display, so what I've done is added the theme function into the Product module's commerce_product_field_extra_fields() and look for that when rendering to determine if an extra field should be injected into a referencing entity or not.

Also, I had to add in Cart integration for multiple value product reference fields so the product SKU / title is properly updated with the Add to Cart form. This mimics the field integration in commerce_cart_add_to_cart_form_attributes_refresh().

By far the hardest part was figuring out how to preserve the existing behavior of product extra fields - they should default to hidden on new sites and remain hidden on updated sites. This is no small task, as there actually is no core way to specify the default visibility of an extra field. You have to alter it at the point of display and separately alter the "Manage display" form so it matches the same default setting... but once you get data saved, it should function as expected with the new data. If I'd known this was going to suck hours of my time today, I would've demoted this from a 1.1 blocker... but once I fixated on the issue, I couldn't stop working on it. C'est la vie. : P

I'd love to get a review on this patch before I commit. : ) (My biggest worry is that everyone updates to 1.1 and suddenly has the product extra fields injected into all their product displays unintentionally... I did an update test, and it appeared to work fine, but ya never know.)

MickL’s picture

rszrama’s picture

This should accommodate that. Were you able to test it?

MickL’s picture

how do i call the product-title or product-sku in my productnode.tpl.php? i am currently using print render($content['product:commerce_price']['#object']->sku);

rszrama’s picture

With the patch, $content['product:title'] and $content['product:sku'] should work fine.

rfay’s picture

I read through the patch and have no objections to anything.

I did get this before doing a drush cc all the first time I hit the site after patching, but am not sure whether it had to do with something else. drush cc all fixed it. (That's in commerce_embed_view(); I don't see how it could be related...)
PHP Fatal error: Call to a member function set_display() on a non-object in /home/rfay/workspace/commerce/sites/all/modules/commerce/commerce.module on line 312

I was hoping for *all* product properties to be available, not just SKU and Title. I changed the title that way in #8 , but didn't mention it I guess. I do think it's sad to go to all this effort without making everything available. #8, while not as good a patch, did handle all the properties.

Nicely done. Thanks!

rszrama’s picture

Ok, thanks for the review Randy. If I'm not mistaken, all we'd need as a follow-up would be to define extra fields for other properties. The biggest problem lies in the inability to configure settings for their display like you can with fields. Maybe we can at least make sure we put the full product object inside the node object so the data is available at the theme level.

rfay’s picture

Status: Needs review » Reviewed & tested by the community

Also... since this patch does all that was asked for (and all that's actually relevant in so many cases) it's probably good to go as is.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Alrighty, committed. : )

rszrama’s picture

Issue tags: -low-hanging fruit

(Meant to remove the tag... turned out to be more than I imagined. ; )

MickL’s picture

i will test that in a few days. thank you very much ryan, you're awesome !! :)

(will this be a part of 1.1?)

rszrama’s picture

Yep, anything that gets committed before the 1.1 release will be part of the 1.1. : )

MickL’s picture

"can't find file to patch at input line 5"
"..."
":--- a/modules/cart/commerce_cart.module"
":--- b/modules/cart/commerce_cart.module"

what is this a/b for??
finally i typed in the paths manually without the a/b (e.g. modules/cart/commerce_cart.module). All files where be patched but $content['product:title'] and $content['product:sku'] shows nothing. :(

am i to stupid ?

rfay’s picture

You'd probably be better to just use the current dev release, which already contains this.

MickL’s picture

ok i tried the current dev release now. unfortunately $content['product:title'] and $content['product:sku'] still shows nothing while $content['product:commerce_price'] works fine.

MickL’s picture

finally i got it.

whether im using a custom node.tpl.php i needed to drag the sku in the visible area at "admin/structure/types/manage/my-productdisplay-name/display"

now its working. thanks ryan.

rszrama’s picture

Awesome, glad to hear it's working for you.

MickL’s picture

there is one last thing:

i need to remove the div wrapper:
<div class="commerce-product-extra-field commerce-product-extra-field-sku node-456-product-sku"> 0700</div>

but it is in no .tpl.php file :(

i have the same problem with my custom product field "color":
<div class="commerce-product-field commerce-product-field-field-color field-field-color node-456-product-field-color">orange</div>

rszrama’s picture

The wrapper is a necessary part of injecting the fields and allowing them to be updated by the Add to Cart form unfortunately. Can you work around it?

MickL’s picture

i worked around ;) i understand. but it is not clean and a <div> always breaks the line. maybe there is another way to select and update the fields?

rszrama’s picture

In your CSS, just make that div display inline. That's why we use generic classes in addition to the node ID specific class.

NicholasR’s picture

Thanks for this fix, it's just what I was looking for.

That said, it appears as if it is impossible to set the Label of title to 'hidden'.

/admin/commerce/products/types/product/display
does not have a drop down to control the label's view state for title, and
print render($content['product:title']);
will output Title: product_title.

Is there a way to not output this string?

rszrama’s picture

Unfortunately, not through the basic Field UI. There may be a way for us to alter the form and save label settings in there, but in the meantime you'll just need to override the template for the property in your theme. Sucky, I know.

rfay’s picture

Title: Render property data in the product reference formatter instead of just field data » Render title/sku data in the product reference formatter instead of just field data

Changing title as only Title and SKU actually went in.

Status: Fixed » Closed (fixed)
Issue tags: -1.1 blocker

Automatically closed -- issue fixed for 2 weeks with no activity.