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

Package DE_EPAGES::Product::API::Product

API helper functions for product variations.

@EXPORT_OK
InsertMultipleSubProducts
GetInfoSubProductsBySuperProductID
JoinVariationValues
SplitVariationValues
SubProductFolder
UsedVariationValues
UpdateAvailability
AddSubProductPricesFromMaster
ScaleImageSizes
TestUPCEAN
DeleteProductImage
RenameProductImageFile

Functions

DeleteProductImage
GetInfoSubProductsBySuperProductID
InsertMultipleSubProducts
JoinVariationValues
RenameProductImageFile
ScaleImageSizes
SplitVariationValues
SubProductFolder
TestUPCEAN
UpdateAvailability
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

GetInfoSubProductsBySuperProductID

Returns the sub products with a given set of variation values.

Syntax
$ahResult = GetInfoSubProductsBySuperProductID($SuperProductID, $VariationString);
Input
$SuperProductID (int)
super product identifier
$VariationString (string)
comma-separated list of PreDefAttribute object ids of
the attribute values.
Return
$ahResult (reference to array of hashes)
with following keys:
  • ProductID - sub product id - int
  • SubProductID - sub product id - int
  • SuperProductID - super product id - int
  • VariationString - value string to find the subproduct by values - string

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

JoinVariationValues

Joins the values to one string, comma separated.

Syntax
$ValueString = JoinVariationValues($raValues);
Input
$raValues (string)
each value as string | ref.array.integer
§ret $ValueString | all values separated by comma

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

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

SplitVariationValues

Splits the comma separated string to the values.

Syntax
$raValues = SplitVariationValues($ValueString);
Input
$ValueString (ref.array.integer)
all values separated by comma | string
§ret $raValues | each value as string

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 $EAN is a valid EAN-13/EAN-8 or a UPC Version A / UPV Version E format.

Syntax
TestUPCEAN($Name, $EANUPC);
Example
TestUPCEAN('EAN', '4004764007974');
TestUPCEAN('UPC', '768268019959');
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();

UsedVariationValues

Returns the list of all variation values that are actually used by sub products of this super product.

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