Example #1
0
function CheckSKUProperty($ID, $SKUID)
{
    $arResult = false;
    $ID = (int) $ID;
    $SKUID = (int) $SKUID;
    if ($ID > 0 && $SKUID > 0) {
        $intSKUPropID = 0;
        $ibp = new CIBlockProperty();
        $arProp = GetSKUProperty($ID, $SKUID);
        if (empty($arProp) || is_array($arProp) && $arProp['MULTIPLE'] != 'N') {
            $arOFProperty = array('NAME' => GetMessage('IB_E_OF_SKU_PROPERTY_NAME'), 'IBLOCK_ID' => $SKUID, 'PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_ELEMENT, 'USER_TYPE' => CIBlockPropertyTools::USER_TYPE_SKU_LINK, 'LINK_IBLOCK_ID' => $ID, 'ACTIVE' => 'Y', 'SORT' => '5', 'MULTIPLE' => 'N', 'CODE' => CIBlockPropertyTools::CODE_SKU_LINK, 'XML_ID' => CIBlockPropertyTools::XML_SKU_LINK, 'FILTRABLE' => 'Y', 'SEARCHABLE' => 'N');
            $intSKUPropID = $ibp->Add($arOFProperty);
            if (!$intSKUPropID) {
                $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => $ibp->LAST_ERROR);
            }
        } elseif ($arProp['USER_TYPE'] != CIBlockPropertyTools::USER_TYPE_SKU_LINK || $arProp['XML_ID'] != CIBlockPropertyTools::XML_SKU_LINK) {
            $arFields = array('USER_TYPE' => CIBlockPropertyTools::USER_TYPE_SKU_LINK, 'XML_ID' => CIBlockPropertyTools::XML_SKU_LINK);
            $boolFlag = $ibp->Update($arProp['ID'], $arFields);
            if (false === $boolFlag) {
                $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => $ibp->LAST_ERROR);
            } else {
                $intSKUPropID = $arProp['ID'];
            }
        } else {
            $intSKUPropID = $arProp['ID'];
        }
        $intSKUPropID = (int) $intSKUPropID;
        if ($intSKUPropID > 0) {
            $arResult = array('RESULT' => 'OK', 'VALUE' => $intSKUPropID);
        }
    } else {
        $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => GetMessage('IB_E_OF_ERR_SKU_IBLOCKS_IS_ABSENT'));
    }
    return $arResult;
}
function CheckSKUProperty($ID, $SKUID)
{
    $arResult = false;
    $ID = intval($ID);
    $SKUID = intval($SKUID);
    if (0 < $ID && 0 < $SKUID) {
        $intSKUPropID = 0;
        $ibp = new CIBlockProperty();
        $arProp = GetSKUProperty($ID, $SKUID);
        if (false === $arProp || true == is_array($arProp) && 'N' != $arProp['MULTIPLE']) {
            $arOFProperty = array('NAME' => GetMessage('IB_E_OF_SKU_PROPERTY_NAME'), 'IBLOCK_ID' => $SKUID, 'PROPERTY_TYPE' => 'E', 'USER_TYPE' => 'SKU', 'LINK_IBLOCK_ID' => $ID, 'ACTIVE' => 'Y', 'SORT' => '5', 'MULTIPLE' => 'N', 'CODE' => 'CML2_LINK', 'XML_ID' => 'CML2_LINK', "FILTRABLE" => "Y", "SEARCHABLE" => "N");
            $intSKUPropID = $ibp->Add($arOFProperty);
            if (!$intSKUPropID) {
                $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => $ibp->LAST_ERROR);
            }
        } elseif ('SKU' != $arProp['USER_TYPE'] || 'CML2_LINK' != $arProp['XML_ID']) {
            $arFields = array('USER_TYPE' => 'SKU', 'XML_ID' => 'CML2_LINK');
            $boolFlag = $ibp->Update($arProp['ID'], $arFields);
            if (false === $boolFlag) {
                $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => $ibp->LAST_ERROR);
            } else {
                $intSKUPropID = $arProp['ID'];
            }
        } else {
            $intSKUPropID = $arProp['ID'];
        }
        if (0 < intval($intSKUPropID)) {
            $arResult = array('RESULT' => 'OK', 'VALUE' => $intSKUPropID);
        }
    } else {
        $arResult = array('RESULT' => 'ERROR', 'MESSAGE' => GetMessage('IB_E_OF_ERR_SKU_IBLOCKS_IS_ABSENT'));
    }
    return $arResult;
}