Bitrix Site Manager

CPrice::Add

bool
CPrice::Add(
 array arFields
);

The method Add adds a new price to a product.

Parameters

ParameterDescription
arFields Associated array of the price parameters with the following keys.
  • PRODUCT_ID - product ID;
  • EXTRA_ID - the ID of discount or extra;
  • CATALOG_GROUP_ID - price type ID;
  • PRICE - price value;
  • CURRENCY - currency of the price.
If the discount ID is specified, the created price will be automatically recalculated when the base price or discount changes.

Return Values

Returns True on success or False otherwise.

Example



<?
// Assign the price of USD29.95 of the type 2 
// to the product with the ID of 15

$PRODUCT_ID = 15;
$PRICE_TYPE_ID = 2;

$arFields = Array(
    "PRODUCT_ID" => $PRODUCT_ID,
    "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
    "PRICE" => 29.95,
    "CURRENCY" => "USD"
);

$res = CPrice::GetList(($o=""),
                       ($b=""),
                       Array("PRODUCT_ID"=>$PRODUCT_ID,
                             "CATALOG_GROUP_ID"=>$PRICE_TYPE_ID));

if ($arr = $res->Fetch())
{
    CPrice::Update($arr["ID"], $arFields);
}
else
{
    CPrice::Add($arFields);
}
?>