This is aimed at improving Commerce Product URLs module by removing commerce_product_urls_entity_view() function - a huge chunk of code executed twice for each entity view (first time in commerce_product_reference_entity_view(), and then in commerce_product_urls_entity_view()).
This code currently needs replicating, as commerce_product_urls_entity_view() does not allow to specify default product which should be selected, so commerce_product_urls_entity_view() had to be introduced to accommodate for this.
Once attached patch makes its way into commerce_product_reference module, commerce_product_reference_entity_view() can be removed, which should be a significant performance gain. (Also, a first step of implementing unique URLs for particular products on product displays in Commerce core.)
Patch to follow.
Comments
Comment #1
maciej.zgadzaj commentedComment #2
maciej.zgadzaj commentedAs discussed over IRC, new patch with new approach.
Comment #3
maciej.zgadzaj commentedSmall changes to docs - added a couple of "the"s and new lines...
Comment #4
maciej.zgadzaj commentedAnd slightly better version, passing array of product entities instead of wrappers as a second param to
hook_commerce_product_reference_default_product_alter().Comment #5
maciej.zgadzaj commentedNew version provides the same option to change default product for
commerce_cart_field_formatter_view()too.Comment #6
fearlsgroove commentedThis is working well for me for a similar need. I applied the patch and looked over the code (briefly) and didn't find anything to object to. Doesn't seem like much performance impact here, and the default behavior is unaffected.
Is there anything else holding this up?
Comment #7
summit commentedHi, would love to see this committed also!
Greetings, Martijn
Comment #8
maciej.zgadzaj commentedSince it's still not committed, here is version not generating strict warnings (Only variables should be passed by reference) in commerce_product_reference_default_product() (in line with core reset() / key() approach).
Changing to needs review for bot to re-test, just in case.
Comment #9
rszrama commentedCommitted this with a small change to make it explicit that the alter function is actually altering the delta and not the product itself.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/b63b0d1