Extension to storeitem model

To change the source code for errors find out the file in source and if it is a model file then in extension suitescript file has to use. Sample code is given below. StoreItem.Model file is changed

// JJ.storeItems.storeItems.js
// Load all your starter dependencies in backend for your extension here
// ----------------

define('JJ.storeItems.storeItems'
,	[
		'JJ.storeItems.storeItems.ServiceController'
		,'StoreItem.Model'
		,'SC.Model'
		,'Utils'
		,'underscore'
		,'SC.Models.Init'
		,'Configuration'
	]
,	function (
		storeItemsServiceController
		,StoreItemModel
		,SCModel
		,Utils
		,_
		,ModelsInit
		,Configuration
	)
{
	'use strict';
	_.extend(StoreItemModel, {
		preloadItems: _.wrap(StoreItemModel.preloadItems, function update(items, fieldset_name) {
			console.log("preloadItemss");
			var self = this
			,	items_by_id = {}
			,	parents_by_id = {}
			,	fieldKeys = Configuration.get('fieldKeys')
			,	itemsFieldsStandardKeys = fieldKeys && fieldKeys.itemsFieldsStandardKeys || [];

			if(!itemsFieldsStandardKeys.length)
			{
				return {};
			}

			items = items || [];

			this.preloadedItems = this.preloadedItems || {};

			items.forEach(function (item)
			{
				if (!item.id || !item.type || item.type === 'Discount' || item.type === 'OthCharge' || item.type === 'Markup'|| item.type === "Subtotal")
				{
					return;
				}

				if (!self.getPreloadedItem(item.id, fieldset_name))
				{
					items_by_id[item.id] = {
						internalid: new String(item.id).toString()
					,	itemtype: item.type
					,	itemfields: itemsFieldsStandardKeys
					};
				}
			});
			if (!_.size(items_by_id))
			{
				return this.preloadedItems;
			}

			var items_details = this.getItemFieldValues(items_by_id, fieldset_name);

			// Generates a map by id for easy access. Notice that for disabled items the array element can be null
			_.each(items_details, function (item)
			{
				if (item && typeof item.itemid !== 'undefined')
				{
					if (item.itemoptions_detail && item.itemoptions_detail.matrixtype === 'child')
					{
						parents_by_id[item.itemoptions_detail.parentid] = {
							internalid: new String(item.itemoptions_detail.parentid).toString()
						,	itemtype: item.itemtype
						,	itemfields:itemsFieldsStandardKeys
						};
					}

					self.setPreloadedItem(item.internalid, item, fieldset_name);
				}
			});

			if (_.size(parents_by_id))
			{
				var parents_details = this.getItemFieldValues(parents_by_id, fieldset_name);

				_.each(parents_details, function (item)
				{
					if (item && typeof item.itemid !== 'undefined')
					{
						self.setPreloadedItem(item.internalid, item, fieldset_name);
					}
				});
			}

			// Adds the parent information to the child
			_.each(this.preloadedItems, function (item)
			{
				if (item.itemoptions_detail && item.itemoptions_detail.matrixtype === 'child')
				{
					item.matrix_parent = self.getPreloadedItem(item.itemoptions_detail.parentid, fieldset_name);
				}
			});

			return this.preloadedItems;

		})

	});
});

Leave a comment

Your email address will not be published. Required fields are marked *