ePages 7.25.0 - DE_EPAGES/Product/API/Product.pm

Package DE_EPAGES::Product::API::Product

API helper functions for product variations.

@EXPORT_OK
InsertMultipleSubProducts
ExistsSubProductByAttributeValues
GetSubProductByAttributeValues
SubProductFolder
UsedVariationValues
UpdateAvailability
AddSubProductPricesFromMaster
ScaleImageSizes
TestUPCEAN
DeleteProductImage
RenameProductImageFile
RenameSubProductImageFile
SmartSearchProducts
GenerateCustomizedProductPDF
SendCustomizationDocumentAsPDFMail
GetVisibleProductIDs
StoreProductImages
DeleteProductImageByAttribute
GetScaledImages
GetVisibleSubProductIDs
StartUnityProgressMonitor
UpdateUnityProgressMonitor

Functions

DeleteProductImage
DeleteProductImageByAttribute
ExistsSubProductByAttributeValues
GenerateCustomizedProductPDF
GetScaledImages
GetSubProductByAttributeValues
GetVisibleProductIDs
GetVisibleSubProductIDs
InsertMultipleSubProducts
RenameProductImageFile
RenameSubProductImageFile
ScaleImageSizes
SendCustomizationDocumentAsPDFMail
SmartSearchProducts
StartUnityProgressMonitor
StoreProductImages
SubProductFolder
TestUPCEAN
UpdateAvailability
UpdateUnityProgressMonitor
UsedVariationValues

DeleteProductImage

Deletes an image file and unassigns it from the product, its super product and all sub products.

Syntax
DeleteProductImage($Product, $FileName);
Input
$Product (object)
product object (normal, super or sub product)
$FileName (string)
image name, relative to the product image directory
$hOptions (hash.ref)
with following keys:
  • DontDeleteSubImages -
    changes default behavior, sub images are not deleted - boolean

DeleteProductImageByAttribute

Delete images assigned to given attribute. This method calls DeleteProductImage to remove all assignments from slide show, subproducts and subproduct slide show.

Syntax
DeleteProductImageByAttribute( $Product, $aAttributes );
Input
$Product (DE_EPAGES::Product::API::Object::Product)
product which reference the images
$aAttributes (array.ref.)
attributes which contain image pathes
$hOptions (hash.ref)
with following keys:
  • DontDeleteSubImages -
    changes default behavior, sub images are not deleted - boolean

ExistsSubProductByAttributeValues

Returns true if a sub product exists having both the given superproduct id and the combination of variations. This subroutine should be preferred over GetSubProductByAttributeValues() when the objective is just to get knowledge about whether or not a sub product exists.

Syntax
$Exists = ExistsSubProductByAttributeValues($SuperProductID, $aVariations);
Input
$SuperProductID (int)
product type id (part of primary key)
$aVariations (ref.array.int)
array of PreDefAttribute object ids of the attribute values
Return
$Exists (boolean)
true if subproduct exists, otherwise false

GenerateCustomizedProductPDF

Converts customized product details to pdf document

Syntax
$hPdfContent = GenerateCustomizedProductPDF($ProductLineItem);
Input
$ProductLineItem (object)
Product Lineitem
$MerchantLanguageID (integer)
LanguageID
Return
$hPdfContent (ref.hash)
  • pdf - pdf document - binary
  • filename - name of pdf file - string

GetScaledImages

Resize an uploaded image to the sizes l,m,ms,ml,s,h,xs using the method ScaleImageSizes and returns the related hash.ref

Syntax
GetScaledImages($FilePath, $Shop);
Input
$FilePath (string)
file path of the original image
$Shop (object)
shop
Return
$hScaledImages (hash.ref)
hash with all resized images

GetSubProductByAttributeValues

Returns the sub products of a super product having the given set of variation values. In general, one can expect that only a single sub product will match the given variation combination. It should be noted, however, that the following example might be valid: Given a super product with various variations (e.g. color, size, weight). A user might only be interested in all sub products having the color 'red'. In this case, the result set is likely to be greater than 1. Since this subroutine is used to select a specific sub product in the storefront, such a query does de facto not exist. Hence, if more than one sub product matches, this subroutine returns the error 'TOO_MANY_MATCHING_SUBPRODUCTS'; the subroutine raises the error 'SUBPRODUCT_NOT_EXISTS', if the variation combination ($aVariations) itself does not exist for the given super product.

Syntax
$SubProduct = GetSubProductByAttributeValues($SuperProductID, $aVariations);
Input
$SuperProductID (int)
product type id (part of primary key)
$aVariations (ref.array.int)
array of PreDefAttribute object ids of the attribute values
Return
$SubProduct (object)
sub product object

GetVisibleProductIDs

Returns all visible product IDs.

Syntax
$aProducts = GetVisibleProductIDs($Shop);
Input
$Shop (object)
shop
Return
$aProductIDs (ref.array.int)
product ids

GetVisibleSubProductIDs

Returns all visible sub product IDs for a given (master) product.

Syntax
$aSubProductIDs = GetVisibleSubProductIDs($Product);
Input
$Product (object)
master product
Return
$aSubProductIDs (ref.array.int)
sub product ids

InsertMultipleSubProducts

Creates a set of new sub products for a given master product, every combination of the given variations will be reflected as a own sub product.

Syntax
InsertMultipleSubProducts( $SuperProduct, $ahVariationTypes, $hValues );
InsertMultipleSubProducts( $SuperProduct, $ahVariationTypes, $hValues, $hOptions );
Input
$SuperProduct (object)
super product
$ahVariationTypes (reference to array of hashes)
values for the variation attributes | with following keys:
  • Attribute - variation type attribute - object
  • Values - Values (PreDefAttributes) - reference to array of objects
$hValues (ref of hash)
non variation attribute values for the new sub product
$hOptions (reference to hash)
(optional) params for processing | with following keys:
  • (optional) AliasFromAttributeValueAlias - creates the sub product
    Alias from the Alias of the product + Aliases of the attribute
    values, for example "TshirtRedXXL" - boolean
  • (optional) Monitor - Monitor options,
    if given the Unity progress monitor will be displayed, parameters:
    • Servlet - servlet object - object

RenameProductImageFile

Renames the given old file associated to a product to the given new name. Also renames all derivatives of the file, i.e. when the file is an image rename the smaller images for hotdeal, thumbnail, etc. If the image file was the current product image, update the product's object attributes with the new filename as well. If another file with the given new name already exists, an error is thrown.

Syntax
$hResult = RenameProductImageFile(
        $Product,
        $OldFileName,
        $NewFileName,
        $FileExt
     );
Input
$Product (object)
product object instance
$OldFileName (string)
file name without extension of the current file
$NewFileName (string)
new file name without extension for the file
$FileExt (string)
file extension
Return
$hUpdateProductData (reference to hash)
hash containing the changed product attributes

RenameSubProductImageFile

Renames the given old file associated to a product to the given new name. Also renames all derivatives of the file, i.e. when the file is an image rename the smaller images for hotdeal, thumbnail, etc. If the image file was the current product image, update the product's object attributes with the new filename as well. If another file with the given new name already exists, an error is thrown.

Syntax
$hResult = RenameSubProductImageFile(
        $SubProduct,
        $OldFileName,
        $NewFileName,
        $FileExt
     );
Input
$SubProduct (object)
subproduct object instance
$OldFileName (string)
file name without extension of the current file
$NewFileName (string)
new file name without extension for the file
$FileExt (string)
file extension
Return
$hUpdateSubProductData (reference to hash)
hash containing the changed product attributes

ScaleImageSizes

scale an image by the given scale vars

Syntax
ScaleImageSizes($File,$hParams);
$sample       ScaleImageSizes('C:\test\image.gif',
           { "SCALE_WIDTH_m" => 200,
             "SCALE_WIDTH_s" => 100,
             "SCALE_WIDTH_h" => 150,
             "SCALE_HEIGHT_h" => 150,
             "SCALE_NAME_m" => 'ImageMedium',
             "SCALE_NAME_s" => 'ImageSmall',
             "SCALE_NAME_h" => 'ImageHotDeal',
            });
Input
$FileName (string)
file
$hParams (reference to hash)
params for processing | with following keys:
  • SCALE_WIDTH_* - width of the image - int
  • SCALE_HEIGHT_* - height of the image - int
  • SCALE_NAME_* - attributename of the medium image - int
  • SCALE_QUALITY_* - quality for image - int
Return
$rahResult (reference to array of hashes)
with following keys: depends on the SCALE_NAME_*
  • ImageMedium - filename of meduim image - string
  • ImageSmall - filename of small image - string
  • ImageHotDeal - filename of hotdeal image - string

SendCustomizationDocumentAsPDFMail

Send an customization document as pdf file mail to the given email .

Syntax
SendCustomizationDocumentAsPDFMail($LineItemProduct,$Servlet);
Input
$LineItemProduct (object)
product lineitem
$Servlet (object)
the servlet

SmartSearchProducts

Returns the product objects for a search string (alias)

Syntax
$aProducts = SmartSearchProducts($Shop, $SearchString);
Input
$Shop (object)
shop object instance
$SearchString (string)
an alias search string
Return
$aProducts (reference to array of objects)
reference to array containing the found products

StartUnityProgressMonitor

Starts a progress Monitor in the Unity design.

Syntax
StartUnityProgressMonitor($Servlet, $Product, $aListItems);
Input
$Servlet (object)
servlet object
$Product (object)
product
$aListItems (array.ref)
list of items to process

StoreProductImages

Stores a given image and generate smaller version of this image based on parameter $aSize

Syntax
$hResponse = StoreProductImages( $Product, $ImageName, $ImageBinary, $aSizes );
Input
$Product (DE_EPAGES::Product::API::Object::Product)
Product which will use the images
$ImageName (String)
name of image incl. extension
$ImageBinary (Blob)
Image file content
$aSizes (arra.ref.string)
Image sizes you wan't to generate additionally to original file.
For possible values see DE_EPAGES::Product::API::Constants PRODUCT_IMAGE_SIZE_NAMES
and PRODUCT_IMAGES_SIZES

SubProductFolder

Creates/returns a folder for sub products (type ProductFolder).

Syntax
$Folder = SubProductFolder( $SuperProduct );
Input
$Product (object)
super product
Return
$Folder (object)
sub product folder

TestUPCEAN

Tests if the parameter $EANUPC is a valid EAN-13/EAN-8 or a UPC Version A / UPV Version E or ISBN 10 format.

Syntax
TestUPCEAN($Name, $EANUPC);
Example
TestUPCEAN('EAN', '4004764007974');
TestUPCEAN('UPC', '768268019959');
TestUPCEAN('ISBN', '3-930673-48-7');
TestUPCEAN('ISBN', '3 930673 48 7');
Input
$Name (string)
parameter name
$EANUPC (string)
parameter for test

UpdateAvailability

Updates the IsAvailable attribute of all products in the system based on the AvailabilityDate attribute. Call this function once a day for each shop database.

Syntax
UpdateAvailability();

UpdateUnityProgressMonitor

Updates a progress monitor by increasing the counter.

Syntax
UpdateUnityProgressMonitor($Servlet);
Input
$Servlet (object)
servlet object

UsedVariationValues

Returns the list of all variation values that are actually used by sub products of the given super product. Returns undef if a sub product is passed to this subroutine.

Syntax
$aValueIDs = UsedVariationValues($Product);
Example
my $aValueIDs = UsedVariationValues($Product);
foreach my $ObjectID (@$aValueIDs) {
    print LoadObject($ObjectID)->get('Name'), "\n";
}
Input
$Product (object)
super product
Return
$aValueIDs (ref.array.integer)
list of value ids