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:
product_price
?product.price
attribute?product.price
?product.purchase_price
? Also a simple json object?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.
You pretty much already got it right with the example in your question.
See the api reference here.
purchasePrices
is also an instance of PriceField
so it's identical in its nature to price
.