@infigo-official/types-for-pricing-script 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,912 @@
1
+ /**
2
+ * This module provides access to the main item object in pricing scripts.
3
+ * The Item interface represents the product variant being priced and contains all
4
+ * the essential information needed for pricing calculations including:
5
+ * - Product pricing information (base price, special prices, costs)
6
+ * - Product details (SKU, name, categories, dimensions)
7
+ * - Quantity and packaging information
8
+ * - Attribute management and pricing adjustments
9
+ * - File handling capabilities
10
+ * - Tier-based pricing support
11
+ *
12
+ * @module OrderItem
13
+ */
14
+
15
+ /**
16
+ * The main item object available in pricing scripts.
17
+ * Represents the product variant being priced and provides access to all
18
+ * product information, attributes, pricing data, and methods for file handling
19
+ * and attribute management.
20
+ *
21
+ * This object is the primary interface for accessing product data and performing
22
+ * pricing calculations in pricing scripts.
23
+ */
24
+ declare interface Item {
25
+ /**
26
+ * The standard product variant price in the base currency.
27
+ * This is the base price before any attribute adjustments, tier pricing,
28
+ * or special pricing is applied.
29
+ *
30
+ * @example
31
+ * var basePrice = Item.Price;
32
+ * var adjustedPrice = basePrice * 1.2; // 20% markup
33
+ */
34
+ Price: number;
35
+
36
+ /**
37
+ * The old price from the product variant, typically used for displaying
38
+ * price comparisons or discounts. This value represents the previous
39
+ * price before any recent price changes.
40
+ *
41
+ * @example
42
+ * if (Item.OldPrice > Item.Price) {
43
+ * var discount = Item.OldPrice - Item.Price;
44
+ * return "Save $" + discount.toFixed(2);
45
+ * }
46
+ */
47
+ OldPrice: number;
48
+
49
+ /**
50
+ * The calculated unit price for this item. If the pricing script is attached to a product,
51
+ * this will be the product variant price. If the pricing script is attached to a checkout attribute,
52
+ * this will be the price per individual unit including discounts and all the adjustments.
53
+ *
54
+ * @example
55
+ * var unitPrice = Item.UnitPrice;
56
+ * var totalForQuantity = unitPrice * Item.Quantity;
57
+ */
58
+ UnitPrice: number;
59
+
60
+ /**
61
+ * The final calculated price for this item, including all discounts and adjustments.
62
+ * If the pricing script is attached to a product,
63
+ * this will be the product variant price multiplied by the quantity.
64
+ * If the pricing script is attached to a checkout attribute,
65
+ * it represents the total price for the entire quantity of this item
66
+ * after all pricing rules have been applied.
67
+ *
68
+ * @example
69
+ * var finalTotal = Item.FinalPrice;
70
+ * console("Final price for " + Item.Quantity + " units: $" + finalTotal);
71
+ */
72
+ FinalPrice: number;
73
+
74
+ /**
75
+ * The product cost, representing the actual cost to produce or acquire
76
+ * the product. This value is used for margin calculations and profit analysis.
77
+ *
78
+ * @example
79
+ * var margin = Item.Price - Item.ProductCost;
80
+ * var marginPercentage = (margin / Item.Price) * 100;
81
+ */
82
+ ProductCost: number;
83
+
84
+ /**
85
+ * The special price for the product variant, if applicable.
86
+ * This value is null if no special pricing is currently active.
87
+ * Special pricing typically overrides the standard price for promotional periods.
88
+ *
89
+ * @example
90
+ * var finalPrice = Item.SpecialPrice || Item.Price;
91
+ */
92
+ SpecialPrice: number | null;
93
+
94
+ /**
95
+ * The start date for special pricing, if applicable.
96
+ * This value is null if no special pricing is currently active.
97
+ * Used to determine if special pricing should be applied based on current date.
98
+ *
99
+ * @example
100
+ * var now = new Date();
101
+ * if (Item.SpecialPriceStartDate && now >= Item.SpecialPriceStartDate) {
102
+ * return Item.SpecialPrice;
103
+ * }
104
+ */
105
+ SpecialPriceStartDate: Date | null;
106
+
107
+ /**
108
+ * The end date for special pricing, if applicable.
109
+ * This value is null if no special pricing is currently active.
110
+ * Used to determine if special pricing should be applied based on current date.
111
+ *
112
+ * @example
113
+ * var now = new Date();
114
+ * if (Item.SpecialPriceEndDate && now <= Item.SpecialPriceEndDate) {
115
+ * return Item.SpecialPrice;
116
+ * }
117
+ */
118
+ SpecialPriceEndDate: Date | null;
119
+
120
+ /**
121
+ * Additional shipping charge for this specific product variant.
122
+ * This value is added to the base shipping cost and represents
123
+ * any extra shipping fees specific to this item.
124
+ *
125
+ * @example
126
+ * var totalShipping = baseShippingCost + Item.AdditionalShippingCharge;
127
+ */
128
+ AdditionalShippingCharge: number;
129
+
130
+ /**
131
+ * The weight of the item in the configured weight unit (typically grams or ounces).
132
+ * This value is used for shipping calculations and weight-based pricing.
133
+ *
134
+ * @example
135
+ * var shippingCost = calculateShippingByWeight(Item.Weight);
136
+ */
137
+ Weight: number;
138
+
139
+ /**
140
+ * Indicates whether the weight can be set or modified for this item.
141
+ * Some products may have fixed weights that cannot be changed,
142
+ * while others allow weight adjustments based on attributes or custom settings.
143
+ *
144
+ * @example
145
+ * if (Item.CanSetWeight) {
146
+ * // Allow weight adjustments in the UI
147
+ * }
148
+ */
149
+ CanSetWeight: boolean;
150
+
151
+ /**
152
+ * The Stock Keeping Unit (SKU) of the product variant.
153
+ * This is the unique identifier for the product variant and is used
154
+ * for inventory management and order processing.
155
+ *
156
+ * @example
157
+ * var productIdentifier = Item.Sku;
158
+ */
159
+ Sku: string;
160
+
161
+ /**
162
+ * The actual SKU based on the current attribute combination.
163
+ * If no attributes are selected, this will be the same as the product SKU.
164
+ * This value reflects the specific configuration of the product being priced.
165
+ *
166
+ * @example
167
+ * var configuredSku = Item.ActualSku;
168
+ */
169
+ ActualSku: string;
170
+
171
+ /**
172
+ * The width of the item in the configured dimension unit (typically inches or centimeters).
173
+ * This value is used for packaging calculations and dimensional pricing.
174
+ *
175
+ * @example
176
+ * var packagingCost = calculatePackagingCost(Item.Width, Item.Height, Item.Length);
177
+ */
178
+ Width: number;
179
+
180
+ /**
181
+ * The height of the item in the configured dimension unit (typically inches or centimeters).
182
+ * This value is used for packaging calculations and dimensional pricing.
183
+ *
184
+ * @example
185
+ * var packagingCost = calculatePackagingCost(Item.Width, Item.Height, Item.Length);
186
+ */
187
+ Height: number;
188
+
189
+ /**
190
+ * The length of the item in the configured dimension unit (typically inches or centimeters).
191
+ * This value is used for packaging calculations and dimensional pricing.
192
+ *
193
+ * @example
194
+ * var packagingCost = calculatePackagingCost(Item.Width, Item.Height, Item.Length);
195
+ */
196
+ Length: number;
197
+
198
+ /**
199
+ * The name of the product as displayed to customers.
200
+ * This is the human-readable product name used in the user interface
201
+ * and order confirmations.
202
+ *
203
+ * @example
204
+ * var displayName = Item.ProductName;
205
+ */
206
+ ProductName: string;
207
+
208
+ /**
209
+ * Array of category names that this product belongs to.
210
+ * Categories are used for product organization, filtering, and
211
+ * category-specific pricing rules.
212
+ *
213
+ * @example
214
+ * if (Item.Categories.includes("Premium")) {
215
+ * return Item.Price * 1.1; // 10% premium markup
216
+ * }
217
+ */
218
+ Categories: string[];
219
+
220
+ /**
221
+ * Array of tag names associated with this product.
222
+ * Tags are used for product classification, search optimization,
223
+ * and tag-based pricing rules.
224
+ *
225
+ * @example
226
+ * if (Item.Tags.includes("Featured")) {
227
+ * return Item.Price * 1.05; // 5% featured product markup
228
+ * }
229
+ */
230
+ Tags: string[];
231
+
232
+ /**
233
+ * The order quantity for this item.
234
+ * This represents how many units of this product variant are being ordered.
235
+ * Used for quantity-based pricing and tier calculations.
236
+ *
237
+ * @example
238
+ * var tier = HelperMethods.FindTier(Item.Quantity, Item.PricingTiers);
239
+ */
240
+ Quantity: number;
241
+
242
+ /**
243
+ * The pack quantity, calculated as the order quantity divided by the product variant's
244
+ * OrderPackQuantity. This represents how many packs are being ordered.
245
+ *
246
+ * @example
247
+ * var packPrice = Item.Price * Item.PackQuantity;
248
+ */
249
+ PackQuantity: number;
250
+
251
+ /**
252
+ * The quantity selector mode for this product.
253
+ * This determines how quantity selection is handled in the user interface
254
+ * and affects pricing calculations.
255
+ *
256
+ * @example
257
+ * switch (Item.QuantitySelectorMode) {
258
+ * case 1: // Individual units
259
+ * return Item.Price * Item.Quantity;
260
+ * case 2: // Packs
261
+ * return Item.Price * Item.PackQuantity;
262
+ * }
263
+ */
264
+ QuantitySelectorMode: number;
265
+
266
+ /**
267
+ * Whether this is a batch job
268
+ */
269
+ IsBatch: boolean;
270
+
271
+ /**
272
+ * Number of pages (-1 if not valid)
273
+ */
274
+ NumberOfPages: number;
275
+
276
+ /**
277
+ * Number of records (-1 if not valid)
278
+ */
279
+ NumberOfRecords: number;
280
+
281
+ /**
282
+ * Array of pricing tiers with Price, Quantity, and CustomerRole
283
+ */
284
+ PricingTiers: Tier[];
285
+
286
+ /**
287
+ * Array of batch tiers (same as PricingTiers but for batch tier table)
288
+ */
289
+ BatchTiers: Tier[];
290
+
291
+ /**
292
+ * Price per record (-1 if not valid)
293
+ */
294
+ PricePerRecord: number;
295
+
296
+ /**
297
+ * Array of attributes with Key, Value, IsRequired, Prompt, PriceAdjustment, etc.
298
+ */
299
+ Attributes: Attribute[];
300
+
301
+ /**
302
+ * User email
303
+ */
304
+ Email: string;
305
+
306
+ /**
307
+ * Array of customer role system names
308
+ */
309
+ CustomerRoles: string[];
310
+
311
+ /**
312
+ * Department name of user
313
+ */
314
+ Department: string;
315
+
316
+ /**
317
+ * Array of other order items using the same custom pricing script
318
+ */
319
+ OtherOrderItems: Item[];
320
+
321
+ /**
322
+ * Alias of OtherOrderItems
323
+ */
324
+ CartItems: Item[];
325
+
326
+ /**
327
+ * Index of this item in the other order item array (0 if not in array)
328
+ */
329
+ OrderItemIndex: number;
330
+
331
+ /**
332
+ * Index of this item in the other order item array (-1 if not in array)
333
+ */
334
+ CartItemIndex: number;
335
+
336
+ /**
337
+ * Whether this item is in the other order item array
338
+ */
339
+ IsInOtherOrderItems: boolean;
340
+
341
+ /**
342
+ * Value of the currently used discount code
343
+ */
344
+ DiscountCode: string;
345
+
346
+ /**
347
+ * Array of versions with JobId, CustomName, and Quantity
348
+ */
349
+ Versions: ItemVersion[];
350
+
351
+ /**
352
+ * Number of versions
353
+ */
354
+ NumberOfVersions: number;
355
+
356
+ /**
357
+ * Whether this is a version of a job
358
+ */
359
+ IsVersion: boolean;
360
+
361
+ /**
362
+ * Sum of all quantities of all versions
363
+ */
364
+ VersionsSumQuantity: number;
365
+
366
+ /**
367
+ * Get file information for attached files
368
+ * @param attributeId - ID of the attribute
369
+ * @param readContent - Whether to read file content
370
+ * @returns FileInfo object
371
+ */
372
+ getFileInfo(attributeId: string, readContent: boolean): FileInfo;
373
+
374
+ /**
375
+ * Shortcut method to retrieve an attribute value by name
376
+ * @param attribute - Name of the attribute
377
+ * @returns Attribute value
378
+ */
379
+ getAttributeValue(attribute: string): string;
380
+
381
+ /**
382
+ * Set the attribute value permanently to the given value
383
+ * @param attribute - Name of the attribute
384
+ * @param value - Value to set
385
+ */
386
+ setAttributeValue(attribute: string, value: string): void;
387
+
388
+ /**
389
+ * Get file information for a specific configurable file from Global Data
390
+ * @param filename - Name of the file
391
+ * @returns FileInfo object
392
+ *
393
+ * @example
394
+ * // Method 1: Using getGlobalFileContent (current approach)
395
+ * var fileInfo = Item.getGlobalFileContent("test.csv");
396
+ * if (fileInfo && fileInfo.CsvContent) {
397
+ * console("CSV file loaded successfully with " + fileInfo.CsvContent.length + " rows");
398
+ * var headers = fileInfo.CsvContent[0]; // First row contains headers
399
+ *
400
+ * // Process CSV data from FileInfo object
401
+ * for (var i = 1; i < fileInfo.CsvContent.length; i++) {
402
+ * var row = fileInfo.CsvContent[i];
403
+ * // Access data by column index
404
+ * var firstColumn = row[0];
405
+ * var secondColumn = row[1];
406
+ * }
407
+ * }
408
+ *
409
+ * @example
410
+ * // For non-CSV files, access raw content
411
+ * var textFile = Item.getGlobalFileContent("config.txt");
412
+ * if (textFile && textFile.Content) {
413
+ * console("File content: " + textFile.Content);
414
+ * }
415
+ */
416
+ getGlobalFileContent(filename: string): FileInfo;
417
+
418
+ /**
419
+ * Get CSV file content as a 2D array from Global Data
420
+ * @param filename - Name of the CSV file
421
+ * @returns 2D array representing CSV content, or null if file doesn't exist
422
+ *
423
+ * @example
424
+ * // Basic CSV loading and processing
425
+ * var csvData = Item.getGlobalFileCsvContent("test.csv");
426
+ * if (csvData) {
427
+ * console("CSV data loaded directly as array with " + csvData.length + " rows");
428
+ *
429
+ * // Extract column names from first row
430
+ * function getColumnNames(csvTable) {
431
+ * if (csvTable && csvTable.length > 0) {
432
+ * return csvTable[0]; // Returns array of column names
433
+ * }
434
+ * return [];
435
+ * }
436
+ *
437
+ * var columnNames = getColumnNames(csvData);
438
+ * console("Available columns: " + columnNames.join(", "));
439
+ *
440
+ * // Process data rows (skip header row)
441
+ * for (var i = 1; i < csvData.length; i++) {
442
+ * var row = csvData[i];
443
+ * // Access data by column index
444
+ * var firstColumn = row[0];
445
+ * var secondColumn = row[1];
446
+ * }
447
+ * } else {
448
+ * console("CSV file not found or empty");
449
+ * }
450
+ *
451
+ * @example
452
+ * // Method 2: Using getGlobalFileCsvContent (preferred for CSV files)
453
+ * var csvData = Item.getGlobalFileCsvContent("test.csv");
454
+ * if (csvData) {
455
+ * console("Direct CSV access with " + csvData.length + " rows");
456
+ * // csvData is already a 2D array, no need to access .CsvContent property
457
+ * }
458
+ */
459
+ getGlobalFileCsvContent(filename: string): string[][] | null;
460
+ }
461
+
462
+ /**
463
+ * Global Item object available in pricing scripts
464
+ * This constant provides access to all item-related data and functionality,
465
+ * allowing scripts to retrieve product information, pricing data, attributes,
466
+ * and perform various operations on the current item being priced.
467
+ *
468
+ * The Item object contains comprehensive information about the product variant
469
+ * including pricing details, attributes, customer information, file attachments,
470
+ * and methods for data manipulation and file handling.
471
+ *
472
+ * @example
473
+ * // Access basic product information
474
+ * var productName = Item.ProductName;
475
+ * var basePrice = Item.Price;
476
+ * var quantity = Item.Quantity;
477
+ *
478
+ * // Work with attributes
479
+ * for (var i = 0; i < Item.Attributes.length; i++) {
480
+ * var attr = Item.Attributes[i];
481
+ * console("Attribute: " + attr.Key + " = " + attr.Value);
482
+ * }
483
+ *
484
+ * // Get file information
485
+ * var fileInfo = Item.getFileInfo("fileAttributeId", true);
486
+ * if (fileInfo.NumberOfPages > 0) {
487
+ * console("File has " + fileInfo.NumberOfPages + " pages");
488
+ * }
489
+ *
490
+ * // Access customer information
491
+ * if (Item.CustomerRoles.indexOf("Registered") >= 0) {
492
+ * // Apply Registered pricing logic
493
+ * }
494
+ *
495
+ * // Work with pricing tiers
496
+ * var tier = HelperMethods.FindTier(Item.Quantity, Item.PricingTiers, Item.CustomerRoles);
497
+ * if (tier) {
498
+ * console("Using tier: " + tier.Quantity + " @ $" + tier.Price);
499
+ * }
500
+ *
501
+ * // Calculate final price
502
+ * var finalPrice = Item.Price;
503
+ * finalPrice += HelperMethods.GetAttributePriceAdjustment(Item.Quantity, Item.CustomerRoles);
504
+ *
505
+ * // Advanced pricing calculations with special conditions
506
+ * try {
507
+ * var finalPrice = Item.Price;
508
+ *
509
+ * // Apply quantity-based discounts
510
+ * if (Item.Quantity >= 100) {
511
+ * finalPrice *= 0.9; // 10% bulk discount
512
+ * console("Applied bulk discount: 10%");
513
+ * }
514
+ *
515
+ * // Check for special customer pricing
516
+ * if (Item.CustomerRoles.indexOf("Wholesale") >= 0) {
517
+ * finalPrice *= 0.85; // 15% wholesale discount
518
+ * console("Applied wholesale pricing");
519
+ * }
520
+ *
521
+ * // Apply attribute-based adjustments
522
+ * var colorAttr = Item.getAttributeValue("Color");
523
+ * if (colorAttr === "Premium Gold") {
524
+ * finalPrice += 25.00; // Premium color surcharge
525
+ * console("Added premium color surcharge: $25.00");
526
+ * }
527
+ *
528
+ * // File processing fees based on page count
529
+ * if (Item.NumberOfPages > 0) {
530
+ * var processingFee = Item.NumberOfPages * 0.50;
531
+ * finalPrice += processingFee;
532
+ * console("Added processing fee: $" + processingFee + " for " + Item.NumberOfPages + " pages");
533
+ * }
534
+ *
535
+ * // Setup cost for batch jobs
536
+ * if (Item.IsBatch && Item.Quantity > 1) {
537
+ * finalPrice += 15.00; // One-time setup fee
538
+ * console("Added batch setup fee: $15.00");
539
+ * }
540
+ *
541
+ * } catch (error) {
542
+ * alert("Error in pricing calculation: " + error.message);
543
+ * finalPrice = Item.Price; // Fallback to base price
544
+ * }
545
+ *
546
+ * @example
547
+ * // Working with product versions and configurations
548
+ * if (Item.Versions && Item.Versions.length > 0) {
549
+ * for (var v = 0; v < Item.Versions.length; v++) {
550
+ * var version = Item.Versions[v];
551
+ * console("Version " + (v + 1) + ": " + version.Data.length + " data entries");
552
+ *
553
+ * // Process version-specific data
554
+ * for (var d = 0; d < version.Data.length; d++) {
555
+ * var data = version.Data[d];
556
+ * console(" Data entry: " + data.Key + " = " + data.Value);
557
+ * }
558
+ * }
559
+ * }
560
+ *
561
+ *
562
+ * @example
563
+ * // CSV-based pricing with attribute matching
564
+ * function getCsvBasedPrice() {
565
+ * var csvData = Item.getGlobalFileCsvContent("pricing.csv");
566
+ * if (!csvData || csvData.length < 2) {
567
+ * console("CSV file not found or empty");
568
+ * return Item.Price;
569
+ * }
570
+ *
571
+ * var headers = csvData[0];
572
+ * var priceColumnIndex = -1;
573
+ *
574
+ * // Find price column
575
+ * for (var h = 0; h < headers.length; h++) {
576
+ * if (headers[h] === "Price") {
577
+ * priceColumnIndex = h;
578
+ * break;
579
+ * }
580
+ * }
581
+ *
582
+ * if (priceColumnIndex === -1) {
583
+ * console("Price column not found in CSV");
584
+ * return Item.Price;
585
+ * }
586
+ *
587
+ * // Find matching row
588
+ * for (var row = 1; row < csvData.length; row++) {
589
+ * var isMatch = true;
590
+ *
591
+ * for (var col = 0; col < headers.length; col++) {
592
+ * var columnName = headers[col];
593
+ * if (columnName !== "Price" && columnName !== "Setup") {
594
+ * var csvValue = csvData[row][col];
595
+ * var attrValue = Item.getAttributeValue(columnName);
596
+ *
597
+ * if (csvValue && csvValue !== attrValue) {
598
+ * isMatch = false;
599
+ * break;
600
+ * }
601
+ * }
602
+ * }
603
+ *
604
+ * if (isMatch) {
605
+ * var price = parseFloat(csvData[row][priceColumnIndex]) || Item.Price;
606
+ * console("Found matching price: $" + price);
607
+ * return price;
608
+ * }
609
+ * }
610
+ *
611
+ * console("No matching row found, using default price");
612
+ * return Item.Price;
613
+ * }
614
+ *
615
+ * @example
616
+ * // Setup cost calculation
617
+ * function calculateWithSetupCost() {
618
+ * var basePrice = Item.Price;
619
+ * var setupCost = 50.00; // Example setup cost
620
+ * var quantity = Item.Quantity;
621
+ *
622
+ * // Distribute setup cost across quantity
623
+ * var setupCostPerUnit = setupCost / quantity;
624
+ * var finalPrice = basePrice + setupCostPerUnit;
625
+ *
626
+ * console("Base price: $" + basePrice);
627
+ * console("Setup cost: $" + setupCost + " ($" + setupCostPerUnit + " per unit)");
628
+ * console("Final price: $" + finalPrice);
629
+ *
630
+ * return finalPrice;
631
+ * }
632
+ *
633
+ * return finalPrice;
634
+ *
635
+ * @example
636
+ * // Comprehensive pricing script example showcasing most Item functionality
637
+ * // This example demonstrates CSV-based pricing with attribute matching,
638
+ * // tier pricing, file processing, configuration, and output functions
639
+ * function comprehensivePricingScript() {
640
+ * try {
641
+ * // 1. Configuration and Setup
642
+ * var config = Configuration.ScriptConfig();
643
+ * var defaultConfig = {
644
+ * filePath: "pricing.csv",
645
+ * priceColumnName: "Price",
646
+ * setupCostColumnName: "Setup",
647
+ * skuColumnName: "SKU",
648
+ * debugMode: false,
649
+ * baseFileName: "standup",
650
+ * separator: "-",
651
+ * splitMapping: ["Size", "Material"]
652
+ * };
653
+ *
654
+ * // Merge configuration using HelperMethods
655
+ * HelperMethods.MergeObject(defaultConfig, config);
656
+ *
657
+ * console("Starting comprehensive pricing calculation for: " + Item.ProductName);
658
+ * console("Item SKU: " + Item.Sku + ", Actual SKU: " + Item.ActualSku);
659
+ * console("Base Price: $" + Item.Price + ", Quantity: " + Item.Quantity);
660
+ *
661
+ * // 2. Customer and Role Information
662
+ * console("Customer: " + Item.Email);
663
+ * console("Department: " + Item.Department);
664
+ * console("Customer Roles: " + Item.CustomerRoles.join(", "));
665
+ *
666
+ * // Check for guest users
667
+ * if (Item.CustomerRoles.length === 1 && Item.CustomerRoles[0] === "Guests") {
668
+ * console("Guest user detected - returning zero price");
669
+ * return 0;
670
+ * }
671
+ *
672
+ * // 3. Product Information and Categories
673
+ * console("Product Categories: " + Item.Categories.join(", "));
674
+ * console("Product Tags: " + Item.Tags.join(", "));
675
+ * console("Dimensions: " + Item.Width + "x" + Item.Height + "x" + Item.Length);
676
+ * console("Weight: " + Item.Weight + " (Can set weight: " + Item.CanSetWeight + ")");
677
+ *
678
+ * // 4. Batch and Version Information
679
+ * if (Item.IsBatch) {
680
+ * console("Batch job with " + Item.NumberOfRecords + " records");
681
+ * }
682
+ *
683
+ * if (Item.Versions && Item.Versions.length > 0) {
684
+ * console("Product has " + Item.NumberOfVersions + " versions");
685
+ * console("Total versions quantity: " + Item.VersionsSumQuantity);
686
+ *
687
+ * for (var v = 0; v < Item.Versions.length; v++) {
688
+ * var version = Item.Versions[v];
689
+ * console("Version " + (v + 1) + ": JobId=" + version.JobId +
690
+ * ", Name=" + version.CustomName + ", Qty=" + version.Quantity);
691
+ * }
692
+ * }
693
+ *
694
+ * // 5. File Processing
695
+ * var finalPrice = Item.UnitPrice; // Start with calculated unit price
696
+ *
697
+ * // Check for file uploads and calculate processing fees
698
+ * if (Item.NumberOfPages > 0) {
699
+ * var processingFee = Item.NumberOfPages * 0.25;
700
+ * finalPrice += processingFee;
701
+ * console("Added file processing fee: $" + processingFee + " for " + Item.NumberOfPages + " pages");
702
+ * }
703
+ *
704
+ * // 6. CSV File Loading and Processing
705
+ * var csvFileName = defaultConfig.filePath;
706
+ *
707
+ * // Dynamic filename generation if no static path provided
708
+ * if (!csvFileName) {
709
+ * csvFileName = defaultConfig.baseFileName;
710
+ * for (var i = 0; i < defaultConfig.splitMapping.length; i++) {
711
+ * var attrValue = Item.getAttributeValue(defaultConfig.splitMapping[i]);
712
+ * if (attrValue) {
713
+ * csvFileName += defaultConfig.separator + attrValue;
714
+ * }
715
+ * }
716
+ * csvFileName += ".csv";
717
+ * }
718
+ *
719
+ * console("Loading CSV file: " + csvFileName);
720
+ * var csvData = Item.getGlobalFileCsvContent(csvFileName);
721
+ *
722
+ * if (csvData && csvData.length > 1) {
723
+ * console("CSV loaded successfully with " + csvData.length + " rows");
724
+ *
725
+ * // Find matching row based on attributes
726
+ * var headers = csvData[0];
727
+ * var priceColumnIndex = -1;
728
+ * var setupColumnIndex = -1;
729
+ *
730
+ * // Find column indices
731
+ * for (var h = 0; h < headers.length; h++) {
732
+ * if (headers[h] === defaultConfig.priceColumnName) {
733
+ * priceColumnIndex = h;
734
+ * } else if (headers[h] === defaultConfig.setupCostColumnName) {
735
+ * setupColumnIndex = h;
736
+ * }
737
+ * }
738
+ *
739
+ * // Find matching row
740
+ * for (var row = 1; row < csvData.length; row++) {
741
+ * var isMatch = true;
742
+ *
743
+ * // Check SKU match if SKU column exists
744
+ * if (defaultConfig.skuColumnName) {
745
+ * var skuColumnIndex = headers.indexOf(defaultConfig.skuColumnName);
746
+ * if (skuColumnIndex >= 0) {
747
+ * var csvSku = csvData[row][skuColumnIndex];
748
+ * if (csvSku && csvSku !== Item.ActualSku) {
749
+ * isMatch = false;
750
+ * continue;
751
+ * }
752
+ * }
753
+ * }
754
+ *
755
+ * // Check attribute matches
756
+ * for (var col = 0; col < headers.length; col++) {
757
+ * var columnName = headers[col];
758
+ * if (columnName !== defaultConfig.priceColumnName &&
759
+ * columnName !== defaultConfig.setupCostColumnName &&
760
+ * columnName !== defaultConfig.skuColumnName) {
761
+ *
762
+ * var csvValue = csvData[row][col];
763
+ * var attrValue = Item.getAttributeValue(columnName);
764
+ *
765
+ * if (csvValue && csvValue !== attrValue) {
766
+ * isMatch = false;
767
+ * break;
768
+ * }
769
+ * }
770
+ * }
771
+ *
772
+ * if (isMatch && priceColumnIndex >= 0) {
773
+ * var csvPrice = parseFloat(csvData[row][priceColumnIndex]);
774
+ * if (!isNaN(csvPrice)) {
775
+ * finalPrice = csvPrice;
776
+ * console("Found matching CSV price: $" + csvPrice);
777
+ *
778
+ * // Add setup cost if applicable
779
+ * if (setupColumnIndex >= 0) {
780
+ * var setupCost = parseFloat(csvData[row][setupColumnIndex]);
781
+ * if (!isNaN(setupCost) && setupCost > 0) {
782
+ * var setupCostPerUnit = setupCost / Item.Quantity;
783
+ * finalPrice += setupCostPerUnit;
784
+ * console("Added setup cost: $" + setupCost + " ($" + setupCostPerUnit + " per unit)");
785
+ * }
786
+ * }
787
+ * }
788
+ * break;
789
+ * }
790
+ * }
791
+ * } else {
792
+ * console("CSV file not found or empty: " + csvFileName);
793
+ * }
794
+ *
795
+ * // 7. Attribute Processing and Price Adjustments
796
+ * console("Processing " + Item.Attributes.length + " attributes");
797
+ * var totalAttributeAdjustment = 0;
798
+ *
799
+ * for (var i = 0; i < Item.Attributes.length; i++) {
800
+ * var attr = Item.Attributes[i];
801
+ * console("Attribute: " + attr.Key + " = " + attr.Value +
802
+ * " (Required: " + attr.IsRequired + ", Adjustment: $" + attr.PriceAdjustment + ")");
803
+ *
804
+ * // Apply attribute price adjustments
805
+ * if (attr.PriceAdjustment && attr.PriceAdjustment !== 0) {
806
+ * totalAttributeAdjustment += attr.PriceAdjustment;
807
+ * }
808
+ *
809
+ * // Special handling for premium attributes
810
+ * if (attr.Key === "Material" && attr.Value === "Premium") {
811
+ * var premiumSurcharge = 15.00;
812
+ * totalAttributeAdjustment += premiumSurcharge;
813
+ * console("Applied premium material surcharge: $" + premiumSurcharge);
814
+ * }
815
+ * }
816
+ *
817
+ * finalPrice += totalAttributeAdjustment;
818
+ * console("Total attribute adjustments: $" + totalAttributeAdjustment);
819
+ *
820
+ * // 8. Tier Pricing with Cart Consolidation
821
+ * var totalQuantity = Item.Quantity;
822
+ *
823
+ * // Check other cart items for quantity consolidation
824
+ * if (Item.CartItems && Item.CartItems.length > 0) {
825
+ * console("Checking " + Item.CartItems.length + " cart items for consolidation");
826
+ *
827
+ * for (var c = 0; c < Item.CartItems.length; c++) {
828
+ * var cartItem = Item.CartItems[c];
829
+ * if (cartItem.ProductName === Item.ProductName && c !== Item.CartItemIndex) {
830
+ * totalQuantity += cartItem.Quantity;
831
+ * console("Added quantity from matching cart item: " + cartItem.Quantity);
832
+ * }
833
+ * }
834
+ * }
835
+ *
836
+ * console("Total consolidated quantity: " + totalQuantity);
837
+ *
838
+ * // Apply tier pricing
839
+ * var tier = HelperMethods.FindTier(totalQuantity, Item.PricingTiers, Item.CustomerRoles);
840
+ * if (tier) {
841
+ * finalPrice = tier.Price + totalAttributeAdjustment;
842
+ * console("Applied tier pricing: " + tier.Quantity + " units @ $" + tier.Price);
843
+ * }
844
+ *
845
+ * // 9. Special Pricing and Discounts
846
+ * if (Item.SpecialPrice && Item.SpecialPriceStartDate && Item.SpecialPriceEndDate) {
847
+ * var now = new Date();
848
+ * if (now >= Item.SpecialPriceStartDate && now <= Item.SpecialPriceEndDate) {
849
+ * finalPrice = Item.SpecialPrice + totalAttributeAdjustment;
850
+ * console("Applied special pricing: $" + Item.SpecialPrice);
851
+ * }
852
+ * }
853
+ *
854
+ * // 10. Role-based Discounts
855
+ * if (Item.CustomerRoles.indexOf("Wholesale") >= 0) {
856
+ * finalPrice *= 0.85; // 15% wholesale discount
857
+ * console("Applied wholesale discount: 15%");
858
+ * } else if (Item.CustomerRoles.indexOf("Premium") >= 0) {
859
+ * finalPrice *= 0.90; // 10% premium customer discount
860
+ * console("Applied premium customer discount: 10%");
861
+ * }
862
+ *
863
+ * // 11. Category and Tag-based Adjustments
864
+ * if (Item.Categories.indexOf("Urgent") >= 0) {
865
+ * finalPrice *= 1.25; // 25% rush charge
866
+ * console("Applied rush charge for Urgent category: 25%");
867
+ * }
868
+ *
869
+ * if (Item.Tags.indexOf("Featured") >= 0) {
870
+ * finalPrice *= 1.05; // 5% featured product markup
871
+ * console("Applied featured product markup: 5%");
872
+ * }
873
+ *
874
+ * // 12. Minimum Price Validation
875
+ * var minimumPrice = Item.ProductCost * 1.1; // 10% margin minimum
876
+ * if (finalPrice < minimumPrice) {
877
+ * console("Price below minimum margin, adjusting to: $" + minimumPrice);
878
+ * finalPrice = minimumPrice;
879
+ * }
880
+ *
881
+ * // 13. Final Price Validation and Output
882
+ * if (finalPrice <= 0) {
883
+ * console("Invalid final price calculated: $" + finalPrice);
884
+ * return Item.Price; // Fallback to base price
885
+ * }
886
+ *
887
+ * // Round to 2 decimal places
888
+ * finalPrice = Math.round(finalPrice * 100) / 100;
889
+ *
890
+ * console("Final calculated price: $" + finalPrice);
891
+ * console("Price breakdown:");
892
+ * console("- Unit Price: $" + Item.UnitPrice);
893
+ * console("- Final Price: $" + Item.FinalPrice);
894
+ * console("- Calculated Price: $" + finalPrice);
895
+ *
896
+ * // Set any dynamic attribute values based on calculation
897
+ * Item.setAttributeValue("CalculatedPrice", finalPrice.toString());
898
+ * Item.setAttributeValue("PriceCalculationDate", new Date().toISOString());
899
+ *
900
+ * return finalPrice;
901
+ *
902
+ * } catch (error) {
903
+ * console("Error in comprehensive pricing script: " + error.message);
904
+ * console("Stack trace: " + error.stack);
905
+ * return Item.Price; // Fallback to base price
906
+ * }
907
+ * }
908
+ *
909
+ * // Execute the comprehensive pricing script
910
+ * return comprehensivePricingScript();
911
+ */
912
+ declare const Item: Item;