Meta issue for price resolution:

Price resolution is a key feature of product bundles. Bundles may provide a fixed price, or bundle items may override the price of each product/variation, or the prices of each product/variation may be totaled. Handle this.

The first problem is in finding a way to calculate the price of the bundle if bundle items have variable/user-selectable variations -- see https://github.com/olafkarsten/commerce_product_bundle/commit/0603099437.... Since the bundle item doesn't contain the state of the selected variations (but the default product bundle order item type does), and by default price resolution does not pass anything to PurchasableEntityInterface::getPrice, we are currently relying on the default product variation for each product bundle item.

Price logic is:

1) If bundle has own price, use this.
2) If bundle hasn't an own price, calculate the price out of the bundle items.

ToDo
#2934102: Implement a PriceResolver
#2934708: Add a bundle specific formatter for the commerce price field
#2934716: Write tests for price resolution.

Comments

steveoliver created an issue. See original summary.

steveoliver’s picture

Issue summary: View changes

  • steveoliver committed 0603099 on 8.x-1.x
    Issue #2831613 - Get price from bundle items if not from bundle (WIP).
    
steveoliver’s picture

Status: Active » Needs review
StatusFileSize
new1008 bytes

@olafkarsten, I thought I had commit access to this repo, but anyways... here's a small typo fix.

lawxen’s picture

Status: Needs review » Needs work
StatusFileSize
new132.49 KB

@steveoliver After applying the 2928976-5-current-store.patch and 2831613-4.patch

I create a product bundle like this:
create a bundle with ptice empty

got error

lawxen’s picture

lawxen’s picture

Status: Needs work » Needs review
StatusFileSize
new746 bytes
new624 bytes
olafkarsten’s picture

Why a check against a zero price? We do this twice in getUnitPrice(). Imho a price of 0.00$ is valid, or did I miss something?

lawxen’s picture

StatusFileSize
new649 bytes
new628 bytes
new771 bytes

@olafkarsten
Oh, yes, you are right.
we should do like commerce_variant http://cgit.drupalcode.org/commerce/tree/modules/product/src/Entity/Prod...

change getUnitPrice to get('price')

olafkarsten’s picture

:D Nice trick, but hey - we are not commerce_product_variation, so we cannot access it's properties directly. We coding against the interface, in this case the PurchasableEntityInterface::getPrice(), which is implemented by commerce_product_variation. The return value is either a valid price object or null. Thats fine for us too, I guess. No further checks needed. But we have to fix our own interface documentation. I will do that.

lawxen’s picture

StatusFileSize
new683 bytes
new565 bytes

@olafkarsten thanks for the analysis
I just change the code, documentation need your help.

olafkarsten’s picture

Thanks, I'll do the interface docs and some test coverage.

olafkarsten’s picture

  • olafkarsten committed 79a7667 on 8.x-1.x
    Issue #2831613 by caseylau, steveoliver: Product bundle price resolution...
olafkarsten’s picture

Status: Needs review » Active
olafkarsten’s picture

steveoliver’s picture

Assigned: steveoliver » Unassigned

(I'm not actually doing anything on this at the moment). :)

olafkarsten’s picture

Let's make this a meta issue for price resolution.

orbistertius’s picture

@olafkarsten, I was reading the issues of this module thinking about using it in a proyect. But this issue is a key. My idea to make this work would be a module creating a variation type holding a reference field to variations of other products. You are limiting the creation to only one variation per product, the use of a reference field inside the variation would make it possible to change the variations of the products included by creating more variations but if the bundles are offering a lot of variations UX would suffer because you need to recreate the bundle as many times as there are mixes of product variations.
Perhaps it is possible to decouple the creation of the bundle variations from the normal entity form and use your bundle form, with multiple variations per product added to the bundle, but variation entities created are all possible mixes of product variations selected.
Hope this gets the conversation going...

olafkarsten’s picture

Lets clearify some wording first:

We have product bundles and product bundle items - a product bundle can have (reference) as many product bundle items as you want. A product bundle item can have (reference) as many product variations as you want, but the variations must belong the same product.

But part of this isn't materialized in actual code yet. We need to figure out how to track the current state of the bundle - means, which of referenced variants is the selected / active one.

I think this is, want you asked for, but I'm not sure.

olafkarsten’s picture

Title: Product bundle price resolution » Meta: Product bundle price resolution