Displaying prices
A set of special functions is used for displaying the information pertaining to the Commercial Catalog module in the public section of the site. Note that in terms of the Commercial Catalog module, a product is an element of an information block. This means that if a function requires a product ID to be passed on input, you have to pass the ID of an information block element.
Function | Description |
---|---|
GetCatalogGroups | Returns a sorted list of price types. |
GetCatalogGroup | Returns an array describing the price type, by its ID. |
GetCatalogProductPrice | Returns the specified price type for the specified product. |
GetCatalogProductPriceList | Returns an array of the product prices given the product ID, optionally sorted. |
GetCatalogProduct | Returns a product by its ID. |
FormatCurrency | Formats the price using the specified formatting options. |
GetCatalogGroups
CDBResult GetCatalogGroups( string by, string order );
The function returns a list of price types. The list returned is sorted by the field by in the order order.
Parameters
Parameter | Description |
---|---|
by |
Field by which the list entries are to be sorted. Can be one of the
following:
|
order |
Sort order. Can be one of the following:
|
Return Values
The function returns a sorted list of the CDBResult records each having the following keys.
Parameter | Description |
---|---|
ID | Price type ID. |
NAME | Internal name of the price type. |
BASE | If "Y", this is the base price type. Otherwise "N". |
SORT | Value of the field Sort weight of the price type. |
NAME_LANG | Name of the price type for the current site. |
CAN_ACCESS | If "Y", the current user is allowed to view prices of this type. If "N", prices of this type should be hidden. |
CAN_BUY | If "Y", the current user is allowed to purchase at prices of this type. Otherwise "N". |
GetCatalogGroup
array GetCatalogGroup( int CATALOG_GROUP_ID );
The function returns a price type description array by the specified ID.
Parameters
Parameter | Description |
---|---|
CATALOG_GROUP_ID | Price type ID. |
Return Values
The function GetCatalogGroup returns an array of the same structure as each entry in a list returned by the function GetCatalogGroups.
GetCatalogProductPrice
array GetCatalogProductPrice( int PRODUCT_ID, int CATALOG_GROUP_ID );
The function returns the price of the type CATALOG_GROUP_ID for the product PRODUCT_ID.
Parameters
Parameter | Description |
---|---|
PRODUCT_ID | Product ID. |
CATALOG_GROUP_ID | Price type ID. |
Return Values
The function GetCatalogProductPrice returns an array with the following keys.
Parameter | Description |
---|---|
ID | Price ID. |
PRODUCT_ID | Product ID. |
EXTRA_ID | The ID of a discount (or extra). |
CATALOG_GROUP_ID | Price type ID. |
PRICE | Price value. |
CURRENCY | Currency of price. |
CATALOG_GROUP_NAME | Name of the price type for the current site. |
CAN_ACCESS | If "Y", the current user is allowed to view prices of this type. If "N", prices of this type should be hidden. |
CAN_BUY | If "Y", the current user is allowed to purchase at prices of this type. Otherwise "N". |
GetCatalogProductPriceList
array GetCatalogProductPriceList( int PRODUCT_ID, string by, string order );
The function returns an array of prices for the product PRODUCT_ID sorted by the field by in the order order.
Parameters
Parameter | Description |
---|---|
PRODUCT_ID | Product ID. |
by |
Field by which the list entries are to be sorted. Can be one of the
following:
|
order |
Sort order. Can be one of the following:
|
Return Values
The function GetCatalogProductPriceList returns an array of the same structure as each entry in a list returned by the function GetCatalogProductPrice.
GetCatalogProduct
array GetCatalogProduct( int PRODUCT_ID );
The function returns information on a product by its ID.
Parameters
Parameter | Description |
---|---|
PRODUCT_ID | Product ID. |
Return Values
The function GetCatalogProduct returns an array with the following keys.
Parameter | Description |
---|---|
ID | Product ID. |
QUANTITY | Quantity of product units. |
QUANTITY_TRACE | "Y" tells the system to keep track of quantity of the product. |
WEIGHT | Product weight. |
FormatCurrency
string FormatCurrency( double PRICE, string CURRENCY );
The function formats the price using the formatting options assigned to the CURRENCY.
Parameters
Parameter | Description |
---|---|
PRICE | Price value. |
CURRENCY | Currency. |
Return Values
String containing the value in the requested format.
Example
The following code illustrates the use of the Commercial Catalog module functions.
<? // // Display price types available to the current user // $db_res = GetCatalogGroups(($b="SORT"), ($o="ASC")); while ($res = $db_res->Fetch()) { if ($res["CAN_ACCESS"]=="Y") { echo $res["NAME_LANG"]; } } ?> <? // // Display prices of the type $TYPE_ID // for the product $PRODUCT_ID // $arProduct = GetCatalogProduct($PRODUCT_ID); if ($res = GetCatalogProductPrice($PRODUCT_ID, $TYPE_ID)) { if ($res["CAN_ACCESS"]=="Y") { echo FormatCurrency($res["PRICE"], $res["CURRENCY"]); echo " (price type ".$res["CATALOG_GROUP_NAME"].") "; // Display the positive purchase offer to the current user // if the product $PRODUCT_ID can be purchased // at the price of the type $TYPE_ID // and the product is either available in stock or // if its availability is not tracked if ($res["CAN_BUY"]=="Y" && (IntVal($arProduct["QUANTITY"])>0 || $arProduct["QUANTITY_TRACE"]!="Y")) { echo "Buy"; } } } ?> <? // // Display a list of allowed price types // for the product $PRODUCT_ID // $arProduct = GetCatalogProduct($PRODUCT_ID); $arPrice = GetCatalogProductPriceList($PRODUCT_ID, "SORT", "ASC"); $bCanBuy = False; for ($i = 0; $i<count($arPrice); $i++) { if ($arPrice[$i]["CAN_ACCESS"]=="Y") { if ($arPrice[$i]["CAN_BUY"]=="Y" && (IntVal($arProduct["QUANTITY"])>0 || $arProduct["QUANTITY_TRACE"]!="Y")) { $bCanBuy = True; } echo $arPrice[$i]["CATALOG_GROUP_NAME"].": "; echo FormatCurrency($arPrice[$i]["PRICE"], $arPrice[$i]["CURRENCY"])."<br>"; } } // Display the positive purchase offer to the current user // if the product can be purchased at one of the available prices // and the product is either available in stock or // if its availability is not tracked if ($bCanBuy) { echo "Buy"; } ?>