Commerce Product Bundle implements PurchaseableEnityInterface, which offers getPrice() method to return a price for a given bundle. Current implementation doesn't use PriceResolver, but instead, it returns a (opinionated) price from the best practice or the most common use case if a static price is not set.

Commerce's PriceResolver offers a way for system to decide on a way to get a price, which allows other contributed modules to override the default / most common calculated price. Below are 2 use cases that would benefit:

1. If a bundle is added to commerce_pricelist, but the bundle_price is now (suggesting dynamic pricing), then commerce_pricelist can override the PriceResolver and detect the complex situation and therefore disable the price form for editing
2. Some site might want to return the highest price from a bundle instead of the first price, when there is no static price set.

Todo:

Move the current getPrice() code and logic into a PriceResolver class.

Comments

skyredwang created an issue. See original summary.

skyredwang’s picture

Issue summary: View changes
olafkarsten’s picture

Assigned: Unassigned » olafkarsten
Category: Feature request » Task

  • olafkarsten committed 06edaa6 on 8.x-1.x
    Issue #2934102 by skyredwang, olafkarsten: Implement a PriceResolver...
  • olafkarsten committed ec3aa89 on 8.x-1.x
    Issue #2934102: Fix comment style issue.
    
olafkarsten’s picture

Status: Active » Fixed
Related issues: +#2831613: Meta: Product bundle price resolution
  • Adds BundlePriceResolver class.
  • Extends the BundleInterface with setPrice() method.
  • Refactored the ProductBundle getPrice() method. It now returns NULL if no price is set on the object. The logic for calculating the bundle price from the bundle items/referenced variations has moved to the price resolver.
  • Adds tests for all that stuff.

That probably isn't BC.

Status: Fixed » Closed (fixed)

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