Update
Description and parameters
bool CPrice::Update( int ID, array arFields, boolean $boolRecalc = false, );
Method updates price parameters for a product and sources them from arFields array. Non-static method.
Important! Starting from Catalog module version 16.0.3, when passing the key PRICE, its strongly recommended to pass the key CURRENCY as well. This will allow to exclude additional database query inside the method.
This method operational, but has deprecated. It's recommended to use \Bitrix\Catalog\Model\Price::update
instead.
Call parameters
Parameter | Description | Available from version |
---|---|---|
ID | Price ID. Code must be retrieved via this method. | |
arFields | Associative array with new price parameters with keys as price field names, and new values.
Permissible keys:
| |
boolRecalc | Recalculate price. When passing true, enables mechanism of price recalculation.
Upon updating base price (price type indicated in CATALOG_GROUP_ID being base price), recalculates all the rest of prices for product with surcharge ID. Updating another price (non-basic) with already specified surcharge ID and already existing base price - recalculates PRICE and CURRENCY values. Optional parameter. Default value - false. |
Returned values
Returns ID for updated price on successfully saved price and false otherwise. You need to call $APPLICATION->GetException() to get detailed error information.
Events
Method handles events OnBeforePriceUpdate and OnPriceUpdate.
Notes:
- When parameter $boolRecalc = true, you still have to indicate price and currency (in case of non-basic price type). Updates price and currency, if base price exists; if not - updates surcharge ID to null.
- OnBeforePriceUpdate event handlers can restrict or, otherwise, enable price recalculation. The key RECALC for array data, passed to handler is responsible for this.
See Also
- Catalog entity fields
- [link=1401849]CPrice::CheckFields[/link]
- CPrice::Add
- OnBeforePriceUpdate event
- OnPriceUpdate event
Examples
<? // Set for product with ID = 15 price type 2 as the value 29.95 USD $PRODUCT_ID = 15; $PRICE_TYPE_ID = 2; $arFields = Array( "PRODUCT_ID" => $PRODUCT_ID, "CATALOG_GROUP_ID" => $PRICE_TYPE_ID, "PRICE" => 29.95, "CURRENCY" => "USD", "QUANTITY_FROM" => 1, "QUANTITY_TO" => 10 ); $res = CPrice::GetList( array(), array( "PRODUCT_ID" => $PRODUCT_ID, "CATALOG_GROUP_ID" => $PRICE_TYPE_ID ) ); if ($arr = $res->Fetch()) { CPrice::Update($arr["ID"], $arFields); } else { CPrice::Add($arFields); } ?>
© «Bitrix24», 2001-2024