Needs review
Project:
Drupal Commerce Extra Price Formatters
Version:
7.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
11 Oct 2012 at 14:25 UTC
Updated:
20 Mar 2019 at 19:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
akalata commentedAnd here's a patch. It works, but I'm sure it's missing some bits and isn't completely following "best practices".
Comment #2
Heather51 commentedThis would be a great addition to the extra price formatters module for drupal commerce. I have product display views using taxonomy and price ranges make perfect sense where a product has several options each with a different price. I applied the patch to the latest dev. The formatter is available in the product price field but on viewing the page display I get this error:
Notice: Undefined property: stdClass::$field_product in commerce_extra_price_get_range() (line 58 of /home/clients/websites/w_wfstes/public_html/wfstes/sites/all/modules/commerce_extra_price_formatters/includes/extra_functions.inc).
Warning: Invalid argument supplied for foreach() in commerce_extra_price_get_range() (line 60 of /home/clients/websites/w_wfstes/public_html/wfstes/sites/all/modules/commerce_extra_price_formatters/includes/extra_functions.inc).
Notice: Undefined offset: 0 in commerce_extra_price_get_range() (line 106 of /home/clients/websites/w_wfstes/public_html/wfstes/sites/all/modules/commerce_extra_price_formatters/includes/extra_functions.inc).
Notice: Undefined offset: -1 in commerce_extra_price_get_range() (line 107 of /home/clients/websites/w_wfstes/public_html/wfstes/sites/all/modules/commerce_extra_price_formatters/includes/extra_functions.inc).
Any help on this would be much appreciated.
Comment #3
joachim commentedIsn't there an API function to get the calculated price of a product?
I'm interested in having the price say "From £xxx" is there is a range, so that's something I could either add to this patch as a formatter option, or add as another formatter that makes use of commmerce_extra_price_get_range().
Comment #4
jount commentedHi, akalata, and thanks for a great patch!
One thing to note. In file includes/extra_functions.inc :
I had the same problem with notices and warnings. There is a hardcoded "field_product" property in commerce_extra_price_get_range() function, which is causing that warning messages. Heather51, it seems you just have to change "field_product" in the code to your name variant of the product reference field to get price ranges displaying correctly.
Comment #5
Heather51 commentedHi jount - thanks for the tip. And thanks to akalata for creating this much needed patch.
I hadnt noticed that my product reference field was actually called field_product_options. Made the changes as per #4 - No more warnings.
However I am having an issue with the low price in the range. I have a 10% tax on products. The high price range of all products is correct but the low range is showing only the tax amount. ie for a product display where the lowest price in the range should be $4.50 inclusive of tax, the low price is showing as $0.41 which is actually the tax amount included in the full price.
Not sure why the high price would be ok but not the low. Any help here would be fantastic.
Comment #6
Heather51 commentedAdding to #5 there is definitely an issue here with the tax component. If I add some test products which have no tax component the price range works as expected. If I have tax included in the price of the products the the tax component gets chosen as the lowest price in the range on the product display node.
Anyone know how to resolve this?
Comment #7
ikos commentedThanks everyone for your efforts on this patch.
I am just looking at it now with a view to getting it into the latest dev.
I can also see the problem in my test site reported in #5 so I'll try to resolve that first.
Comment #8
ikos commentedOK I have attached an alternative patch.
This is a modified version of the original patch in #1 but it doesn't try to calculate the components as in theory you don't need to - you only need the calculated price to show the range in this way.
This approach also eliminates the tax issue mentioned in #5.
I have also delayed the formatted of the currency until the end to improve the sorting.
Please let me know if this works for you.
kind regards
Richard
Comment #9
Heather51 commentedHi ikos. Thanks for the great work you're doing here.
I've applied the patch in #8 to the latest dev version and am still having the same issue with the low price being the tax element of the lowest price in the range. I played with removing taxes from test products again. When all products in the group had no tax everything worked as expected. As soon as any product in the group had a tax element I ran into the same problem.
Im using display suite with a custom view mode which contains the price range formatter. Im also using taxonomy with taxonomy menu to group the products which are included in the price range.
Would really appreciate it if you could get a chance to have another look at this some time.
Comment #10
infines commentedComment #11
sam152 commentedThis patch isn't present in the dev version of the module? Was this never pushed out?
I think it might need some work before being applied.
Comment #12
sam152 commentedHere is my patch which solves a few of the above issues. It doesn't have any hard-coded languages or fields, but it doesn't do any logic on the components of the prices. It did work for my use-case however.
Comment #13
bloomt commentedWas anyone successful with this?
I am trying to make a view that displays product nodes that may or may not have multiple product variations or product references. If the product node only has one product reference then I want it to display the one price if the product node has multiple references I want it to show the low to high price range?
Any help would be great.
Comment #14
bmunslow commentedPatch #12 did the job nicely for me, although the patch didn't apply correctly for the file
extra_functions.inc, so I had to apply it manually.Other than that, very neat.
Comment #15
discipolo commentedin that case here is a reroll
Comment #16
VSZ commentedMany thanks for the patch #15. Works fine for me.
But I actually need price range with no decimals. How can I combine this two formatters?
Comment #17
VSZ commentedI would like to draw your attention to the fact that the price range option does not take into account status of a product.
Let's say we have two product variants referenced by one product display node. One of them is $5 and another one is $10. The price range will show $5-$10. If you disable one variant the price range will still show $5-$10 range.
I suggest to modify function commerce_extra_price_get_range($entity, $instance) in extra_functions.inc to check product status berore adding it's price to the list.
It will look like this:
Comment #18
brennino commentedThanks for the beautiful work, can some maintainer apply the patch and create a new release? The last release of this module is dated 2012 and it's a pity that a great work like the one in this page can't be released!
Comment #19
monstrfolk commentedDoes not seem to work with inline entity form. Thinking it is a problem with inline entity forms.
Get an error saying display_context['entity'] does not exist.
Checked and display_context['entity'] is not created for every product created with inline entity form. Only the first item created contains display_context['entity'].
Comment #20
mellowtothemax commentedNot working for me either
following errors
Notice: Undefined property: stdClass::$display_context in commerce_extra_price_get_range() (line 57 of /sites/all/modules/commerce_extra_price_formatters/includes/extra_functions.inc).
and
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7879 of includes/common.inc).
Comment #21
hockey2112 commentedI am also experiencing the "EntityMalformedException" error. Any fix/alternative solutions?