Product Attachments
Product Attachments allow you to upload files that are linked to a specific product.
Creating Attachments
In order to create a new attachment for a product, log in to DXP and navigate to Transactions → Catalogues → Products → (Edit Product) → Attachments:
- Name: The name of the attachment. It must be unique for the attachments under the selected product (case-insensitive). Also, it can only contain alphanumeric characters and the special characters _-. If left blank, the name of the specified file will be used instead.
- Category: The category this attachment belongs to.This is a string used to group together attachments.
- Description: The description of the attachment. HTML markup can be added using the WYSIWYG editor.
- Icon: A string representing an icon for the attachment. Useful for styling attachment's icon in the front-end. For example, a CSS class can be specified here and then retrieved in the front-end template.
- File:(required) The attachment file. Use the option selector under 'File' to select how the file source will be specified. Two options are available:
- Upload file: The file will be uploaded to the server. Its filename must be unique for this product.
- Specify URL: The file will be specfiied by its URL, which can either point to an external source or to a Coredna source.
Retrieving Attachments
You can retrieve attachments for a product by using objects of the Product class, as demonstrated bellow. The retrieved attachments will be sorted in the custom order specified in DXP.
Get all attachments for a product
// Gets all attachments for a product $attachments = $product ->getAllAttachments(); // Gets all attachments for a product that belong to the specified category (case-insensitive): $attachments = $product ->getAttachmentsByCategory( 'manual' ); |
And the following example demonstrates displaying info about the retrieved attachments:
Get Attachment attributes
<{ foreach $attachments as $attachment }> <{ $attachment ->getDescription()}><br> <strong>File:</strong> <a href= "<{$attachment->getUrl()}>" class = "<{$attachment->getIcon()}>" ><{ $attachment ->getName()}></a> <{/ foreach }> |