Overview
The JSMA product provides functionality for accessing and editing products.
What can JSMA product do for me?
You could use JSMA product to build a simplified product management interface for editors.
Index
Usage
writing data
Here is an example on how to write data to a JSMA product:
... product.addPreviewImage(file) // adds an image at the end of the list of preview images ...
reading data
Here is an example on how to read data from a JSMA product:
... var prodName = product.name(); ...
Methods
The JSMA product provides the following methods:
void product.addPreviewImage(file, [position])
Adds a preview image to the product.
Example
... product.addPreviewImage(file) // adds an image at the end of the list of preview images product.addPreviewImage(file, 0) // adds an image at the beginning of the list of preview images ...
Parameter file:fileParameter (required)
This can either be
- an upload (received via request.parameter('upload_parameter_name'))
- another JSMA file
- or a String
as the file content.
Parameter position:Int (optional)
An optional index to set the position within the list of preview images.
bool product.addToPortal(id)
Adds the product to a portal by ID.
Returns true or false, depending if the operation was successful.
Example
... product.addToPortal(1) // => true ...
Parameter id (required)
string product.category
Returns the category field of the product.
Example
... product.category // => 'A Category' ...
product product.clone(name)
Clones the product and returns the copy as a JSMA product.
Slice aware
This entity is slice aware, which means that to use this facility:
- there must be a logged in user in the context of the execution
- this user must be currently within a slice
- this user must have the necessary privileges to edit the entity (IFE → System → Benutzer → Roles → Content-Management)
Example
... product.clone() // => product ...
Parameter name: (optional)
product.customPath
Returns the customPath field of the product.
Example
... product.customPath // => '/a-custom-path/to-a-product' ...
bool product.delete()
Marks a product as deleted.
Slice aware
This entity is slice aware, which means that to use this facility:
- there must be a logged in user in the context of the execution
- this user must be currently within a slice
- this user must have the necessary privileges to edit the entity (IFE → System → Benutzer → Roles → Content-Management)
Example
... product.delete() // => true ...
void product.deletePermanent()
Permanently deletes a product.
This function is deprecated!
Example
... product.deletePermanent() ...
string product.deliveryInformation
Returns the deliveryInformation field of the product.
Example
... product.deliveryInformation // => 'some delivery information' ...
string product.description
Returns the rendered description field of the product.
Example
... product.description // => 'some product description' ...
string product.descriptionUnprocessed
Returns the unprocessed content of the description field of the product.
Example
... product.descriptionUnprocessed // => 'description with renderable content' ...
product.flexAttributes()
Returns an array of the flex attributes of the product
Example
... function getCategoryConfiguratorFilter(product, parameters) { var result = {}; var flexAttributes = product.flexAttributes; for(var i=0;i<flexAttributes.length;i++) { var flexAttribute = flexAttributes[i]; if (/^category\./.test(flexAttribute)) { result[flexAttribute.substring(9)] = product.get(flexAttribute); } } return JSON.stringify(result); } ...
string product.format1
Returns the format1 field of the product.
Example
... product.format1 // => 'format1 content' ...
product.format2
Returns the format2 field of the product.
Example
... product.format2 // => 'format2 content' ...
string product.get(key)
Returns the value of key as string or null if no value is set under the key.
Example
... product.get(key) ...
Parameter key:string (required)
The key to be looked up in the flexAttributes of the product.
boolean product.has(key)
Returns a boolean value depending on whether key is present for a given product
Example
... product.has(key) ...
Parameter key:string (required)
The key to be checked in the flexAttributes of the product.
bool product.hasTemplate
Returns whether the product has a template associated
Example
... product.hasTemplate // => true ...
int product.id
Returns the id field of the product.
Example
... product.id ...
product.increment(key)
Increments the vale of a given key by one.
Example
... product.increment(key) ...
Parameter key:string (required)
The key to be incremented in the flexAttributes of the product.
bool product.isDeleted
Returns whether product is marked as deleted.
Example
... product.isDeleted // => false ...
bool product.isDirectDelivery
Returns whether product is a direct delivery product.
Example
... product.isDirectDelivery // => true ...
product.isInPortal
Returns whether the product is associated to the current portal.
Example
... product.isInPortal // => true ...
bool product.isOfflineEditable
Returns whether product is marked as offline editable.
This function is deprecated!
Example
... product.isOfflineEditable // => false ...
bool product.isOnlineEditable
Returns whether product is marked as online editable.
This function is deprecated!
Example
... product.isOnlineEditable // => true ...
bool product.isShopDelivery
Returns whether product is marked as shop delivery.
Example
... product.isShopDelivery // => false ...
string product.metaDescription
Returns the metaDescription field of the product.
Example
... product.metaDescription // => 'some meta description' ...
string product.metaKeywords
Returns the metaKeywords field of the product.
Example
... product.metaKeywords // => 'some keywords' ...
string product.metaTitle
Returns the metaTitle field of the product.
Example
... product.metaTitle ...
string product.name
Returns the name field of the product.
Example
... product.name // => 'the product name' ...
string product.name1
Returns the name1 field of the product.
Example
... product.name1 // => 'name1 content' ...
string product.name2
Returns the name1 field of the product.
Example
... product.name2 // => 'name2 content' ...
int product.originalPrice
Returns the originalPrice field of the product in cent. (Streichpreis)
Example
... product.originalPrice // => 2495 ...
int product.packageId
Returns the packageId field of a product
Example
... product.packageId // => 1 ...
string product.path
Returns the merged custom URI for a product.
Example
... product.path // => '/products/some-product' ...
int[] product.portalIds
Returns a list of portal ids.
Example
... product.portalIds // => [1, 2] ...
portal[] product.portals
Returns a list of JSMA portal to which the product is associated.
Example
... product.portals // => [portal0, portal1] ...
string[] product.previewImageIds
Returns a list of JSMA file uuids.
Example
... product.previewImageIds // => ['UUID_LIKE0', 'UUID_LIKE1'] ...
string[] product.previewImagePaths([max_width], [max_height])
Returns a list of the URIs to the associated previewImages. Optionally resized to a desired value.
Example
... product.previewImagePaths(64, 64) // => ['/media/path0.jpg', '/media/path1.jpg'] ...
Parameter max_width (optional)
An optional integer for the maximum width of the resized image.
Parameter max_height (optional)
An optional integer for the maximum height of the resized image.
file[] product.previewImages
Returns a list of JSMA file of the associated previewImages.
Example
... product.previewImages // => [file0, file1] ...
int product.price
Returns the product price in cents.
Example
... product.price // => 995 ...
string product.printApiId
Returns the printApiId field of the product.
Example
... product.printApiId // => 'UUID_LIKE' ...
file product.productImage
Returns the product image as a JSMA file, if available.
Example
... product.productImage // => file anotherProduct.productImage // => null ...
string product.productImageId
Returns the uuid of the product image.
Example
... product.productImageId // => 'UUID_LIKE' ...
string product.productImagePath([max_width], [max_height])
Returns a URI for the product image. Optionally the image may be resized by setting the arguments for max_width and max_height.
Example
... product.productImagePath(64, 64) // => '/media/some-image-path.jpg' ...
Parameter max_width (optional)
An optional integer for the maximum width of the resized image.
Parameter max_height (optional)
An optional integer for the maximum height of the resized image.
product.remove(key)
Removes the key from the flexAttributes of the product
Example
... product.remove(key) ...
Parameter key:string (required)
The key to be removed from the flexAttributes of the order.
void product.removeFromPortal(id)
Removes the product from the portal specified by id.
Example
... product.removeFromPortal(1); ...
Parameter id (required)
void product.removePreviewImage(uuid)
Removes a preview image by uuid
Example
... product.removePreviewImage('UUID_LIKE'); ...
Parameter uuid (required)
product.set(key, value, [options])
Sets the value of a specified key for a given product.
This function is deprecated! Use update-function instead!
Example
... product.set(key, value, [options]) ...
Parameter key:string (required)
The key to be set in the flexAttributes of the product.
Parameter value:string (required)
The value to be set for the key
Parameter options (optional)
May have a key 'broadcastEvent':bool which determines whether the log message shows up in the websocket log view.
bool product.setDescription(value)
Updates the description with the desired value. Returns whether the update was successful.
This function is deprecated! Use update-function instead!
Example
... product.setDescription('new description') // => true ...
Parameter value (required)
bool product.setProductImage(file)
Replaces or sets the product image. Returns true or false depending on whether the operation was successful.
This function is deprecated! Use update-function instead!
Example
... product.setProductImage(file) // => true ...
Parameter file file (required)
This may be either of
- an uploaded file (from parameter
- a JSMA file
- a string body
bool product.setShortDescription(value)
Sets the short description of the product. Returns whether the update was successful
This function is deprecated! Use update-function instead!
Example
... product.setShortDescription('new short description') // => true ...
Parameter value (required)
bool product.setTags(tags)
Sets the tags of the product to the desired value.
This function is deprecated! Use update-function instead!
Example
... product.setTags('some, tags'); // => true ...
Parameter tags (required)
A comma-separated list of tags.
bool product.setTemplateFile(file)
Sets the template file of the product.
This function is deprecated! Use update-function instead!
Example
... product.setTemplateFile(file) // => true ...
Parameter file (required)
This may be either of
- an uploaded file (from parameter
- a JSMA file
- a string body
string product.shortDescription
Returns the rendered shortDescription field of the product.
This function is deprecated! Use update-function instead!
Example
... product.shortDescription // => 'some short description' ...
string product.shortDescriptionUnprocessed
Returns the unprocessed shortDescription field of the product.
This function is deprecated! Use update-function instead!
Example
... product.shortDescriptionUnprocessed // => 'some unprocessed short description' ...
string product.sku
Returns the SKU field of the product.
Example
... product.sku // => 'the SKU' ...
string[] product.tags
Returns the list of tags of the product.
Example
... product.tags // => ['some', 'tags'] ...
object product.template
Returns the parsed template representation.
Example
... product.template // => { some: { object: {} } } ...
file product.templateFile
Returns the template as a JSMA file if available.
Example
... product.templateFile // => file anotherProduct.templateFile // => null ...
product.templateWithPiced(piced_uuid)
Returns the parsed template representation of an already customized version of the product specified by picedStore UUID.
Example
... product.templateWithPiced('UUID_LIKE') // => { some: { object: {} } } ...
Parameter piced_uuid (required)
string product.typ
Returns the type field from the product.
Example
... product.typ // => 'type content' ...
bool product.undelete()
Removes the deletion marker from the product.
This function is deprecated!
Example
... product.undelete() // => true ...
bool product.update(options)
Updates the product with new attributes from the options object.
Example
... product.update({ name: 'some other name' }) // => true ...
Parameter options (required)
An object that may have the following keys: [name, category, typ, format1, format2, name1, name2, description, shortDescription, metaTitle, metaKeywords, metaDescription]
product.uuid
Returns the uuid of the product.
Example
... var prodUuid = product.uuid; ...
product.vat
Returns the vat
Example
... product.vat ...