Search code examples
pluginsshopware6

Shopware 6 create product price in custom plugin: product.price vs productPrice


How do i create price for a product in custom plugin?

The database contains a table product_price but the product has also a attribute price.*price*, that confused me. The default configuration within the product detail form price card set only the attribute product.price, entity product_price keeps empty.

Seems product.price to be a simple object, so is it done by following code? I mean, no repository needed?

// ../my_price_form.js
...
Component.register('product-pricing-configurator-form', {
    ...
    methods: {
        setPrice() {
            this.product.price["c" + this.currencyId] = {
                net: ...,
                gross: ...,
                linked: true,
                listPrice: null,
                currencyId: this.currencyId
                regulationPrice: null
            }
        }
}

Questions:

  1. What is the purpose of the entity product_price?
  2. How do i create the product.price attribute?
  3. Is there a documentation available about create product.price?
  4. What about the configuration for attribute product.purchase_price? Also a simple json object?

Solution

    1. product_price is the table for advanced pricing. These prices require a ruleId which is the id of a rule build with the rule builder. Depending on whether the rule is fulfilled and the priority these prices take precedence over the regular price (product.price) or other advanced prices.

    2. You pretty much already got it right with the example in your question.

    3. See the api reference here.

    4. purchasePrices is also an instance of PriceField so it's identical in its nature to price.