evitaDB icon indicating copy to clipboard operation
evitaDB copied to clipboard

Calculation of appropriate reference price

Open novoj opened this issue 1 year ago • 1 comments

Consider following example:

{
  queryProduct(
    filterBy: {
      entityPrimaryKeyInSet: [
        103885
      ],
      priceInCurrency: EUR,
      priceInPriceLists: [
        "employee-basic-price",
        "basic"
      ]
    }
  ) {
    recordPage {
      data {
        primaryKey
        attributes {
          code
        }
        priceForSale {
          priceWithoutTax
          priceWithTax
          taxRate
        }
        referencePrice: price(priceList: "basic") {
          priceWithoutTax
          priceWithTax
          taxRate
        }
      }
    }
  }
}

We can only specify a single price in the referencePrice: price(priceList: "basic") part. The real use cases often work with multiple fallback price lists and need to consider the inner record handling logic of the price. So we want to extend support for the following declaration:

referencePrice: price(priceLists: ["reference", "basic_milagro_cz", basic"]) {
          priceWithoutTax
          priceWithTax
          taxRate
        }

which would take the first available price according to the passed sequence of price lists and use it as the result price for the field. The logic will also take into account the price inner record handling logic:

  • for LOWEST_PRICE it returns the first available price that has the same innerRecordId as the price for sale
  • for SUM, it returns the sum of the first available prices selected for each different innerRecordId that also has the sale price available.

This needs to be added to the EntityContract interface and opened both in GraphQL and consider propagating to the REST API as well (since this logic is hard to compute on the client side).

novoj avatar Apr 30 '24 12:04 novoj

@lho the logic is prepared in method io.evitadb.api.requestResponse.data.PricesContract#getPriceForSaleWithAccompanyingPrices including basic tests. Please:

  • [ ] add the logic to GraphQL API
  • [ ] consider relevant support also in REST API
  • [ ] add tests
  • [ ] document usage in reference documentation (or transfer issue back to me after implementation on your side)

novoj avatar May 13 '24 10:05 novoj

This issue changes behaviour of allPricesForSale and breaks backward compatibility for someone who relied on flawed implementation logic. Now the method mimics the calculation and behavior of priceForSale, which is more consistent.

novoj avatar May 30 '24 20:05 novoj

@novoj the GQL support, tests and user documentation are done.

lukashornych avatar Jun 03 '24 07:06 lukashornych