The plugin already allows you to assign a price on most of the elements of the designer, however you may have more needs for setting your prices. For this, you have the option of defining more complex pricing rules.

To better understand the definition of price rules, you can follow the following example which summarizes all the possibilities of properties that you can use for the rules :

var options = {
    pricingRules: [
		{
			handler: 'usedColorsAmount',
			match: 'all',
			scope: 'first',
			target:{
				views:[
					'Front'
				]
			},
			conditions:[
				{
					operator: '>',
					value: 4,
					price: 15
				}
			]
		},
		{
			handler: 'layersAmount',
			match: 'first',
			scope: 'first',
			conditions:[
				{
					operator: '<',
					value: 3,
					price: 20
				},
				{
					operator: '<',
					value: 5,
					price: 15
				}
			]
		},
		{
			handler: 'canvasSize',
			target: {
				views: ['Left']
			},
			conditions:[
				{
					operator: '>',
					values: {
						height: 100,
						width: 200
					},
					price: 3
				}
			]
		},
		{
			handler: 'layerSize',
			match: 'all',
			target: {
				types: ['Text', 'QrCode', 'Design']
			},
			conditions:[
				{
					operator: '>',
					height: 100,
					price: 3
				}
			]
		},
		{
			handler: 'textLength',
			conditions:[
				{
					operator: '>',
					value: 4,
					price: 0
				}
			]
		},
		{
			handler: 'textLines',
			conditions:[
				{
					operator: '>',
					value: 4,
					price: 0
				}
			]
		},
		{
			handler: 'scale',
			match: 'any',
			target: {
				views: ['Left'],
				types: ['Text', 'QrCode', 'Design']
			},
			conditions:[
				{
					operator: '>',
					values: {
						scaleX: 2,
						scaleY: 2
					},
					price: 2
				}
			]
		},
	],
}

var instance = new AsukaDesigner('#myId', options); // Create an instance of the main plugin class

Let’s take a closer look at the properties of the first object in the array :

  • handler : the property to use for your pricing rule
  • match : If “all”, executes all conditions, otherwise only the first valid rule is executed.
  • scope : If “all”, run the rule on all the elements encountered, otherwise run the rule on the first element.
  • target : You can set two properties on the target object. A “views” property which will contain an array of valid views, as well as a “types” property which will contain an array which will allow you to filter the objects according to their types (Text, QrCode, Design, Upload).
  • conditions : A table that contains the different conditions. Each of these conditions has an operator (=, <=,> =, <,>) property, a value property that contains the values that will be tested as well as the price that will be applied.
Was this article helpful to you? Yes No

How can we help?