Answer the question
In order to leave comments, you need to log in
Bitrix Reset to zero when the property is active. as?
Tell me where to dig, full 0.
earlier, when setting the property (withdrawn from sale), the rest of the goods were reset, the available quantity field.
The product remained hanging on the site, but it was impossible to order.
After the next update (unfortunately I have no idea which one), this processing stopped working.
In the init.php file, I found a function that was responsible for this.
AddEventHandler("catalog", "OnBeforeProductAdd", "OnBeforeProductAddUpdateHandler");
AddEventHandler("catalog", "OnBeforeProductUpdate", "OnBeforeProductAddUpdateHandler");
function OnBeforeProductAddUpdateHandler(&$arFields)
{
$ID = $arFields['ID'];
//Обнуляем остатки и запрещаем продавать в минус при активном свойстве "Снят с продажи"
if (CModule::IncludeModule("iblock")) {
$rsElement = CIBlockElement::GetByID($ID);
if ($obElement = $rsElement->GetNextElement()) {
$arElement = $obElement->GetFields();
$arElement["PROPERTIES"] = $obElement->GetProperties();
if (intval($arElement["IBLOCK_ID"]) === 30) {
if (!empty($arElement["PROPERTIES"]["NOT_FOR_SALE"]["VALUE"])) {
$arFields["QUANTITY"] == 0;
$arFields["CAN_BUY_ZERO"] == "N";
} else {
$arFields["CAN_BUY_ZERO"] == "D";
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Cmodule::IncludeModule('catalog');
$el = new CIBlockElement;
if (!empty($arElement["PROPERTIES"]["NOT_FOR_SALE"]["VALUE"])) {
$arFields = array("QUANTITY" => 0, "CAN_BUY_ZERO"=> "N");
CCatalogProduct::Update($ID, $arFields);
} else {
$arFields = array("CAN_BUY_ZERO"=> "D");
CCatalogProduct::Update($ID, $arFields);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question