L
L
lie22020-06-25 11:49:52
1C-Bitrix
lie2, 2020-06-25 11:49:52

How to add a property about the availability of goods, or about its deliveries?

Good afternoon.
It is known that in Bitrix there is a check for the availability of goods in warehouses and as a result you get "In stock" and "Out of stock", but this is not enough for everyone, right?
My question is this, there is a quantity file:

<?
$showCatalogQty = ('Y' == $arParams["SHOW_CATALOG_QUANTITY"]);
$showCatalogQtyCnt = ('Y' == $arParams["SHOW_CATALOG_QUANTITY_CNT"]);

if (!function_exists('printAvailHtml'))
{
    function printAvailHtml($qty, $measure, $params, $showCatalogQtyCnt) {
        $html = '<div class="bxr-instock-wrap">';
        if ($qty > 0) {
            $html .= "<i class='fa fa-check'></i>";
        } else {
            $html .= "<i class='fa fa-times'></i>";
        };
        if ($qty > 0) {
            $html .= $params["IN_STOCK"];
        } else {
            $html .= $params["NOT_IN_STOCK"];
        };
        if ($showCatalogQtyCnt && $qty > 0) {
            if ($params["QTY_SHOW_TYPE"] == "NUM") {
                    $qtyText = $qty." ".$measure;
            } elseif ($qty > $params["QTY_MANY_GOODS_INT"]) {
                $qtyText = $params["QTY_MANY_GOODS_TEXT"];
            } else {
                $qtyText = $params["QTY_LESS_GOODS_TEXT"];
            }
            $html .= ' ('.$qtyText.')';
        }
        $html .= '</div>';

        return $html;
    }
}

if ($showCatalogQty) {
    $params = array(
        "IN_STOCK" => $arParams["IN_STOCK"],
        "NOT_IN_STOCK" => $arParams["NOT_IN_STOCK"],
        "QTY_SHOW_TYPE" => $arParams["QTY_SHOW_TYPE"],
        "QTY_MANY_GOODS_INT" => $arParams["QTY_MANY_GOODS_INT"],
        "QTY_MANY_GOODS_TEXT" => $arParams["QTY_MANY_GOODS_TEXT"],
        "QTY_LESS_GOODS_TEXT" => $arParams["QTY_LESS_GOODS_TEXT"]
    );
    if (count($arResult["OFFERS"]) > 0) {?>
        <div class="bxr-main-avail-wrap">
    <?}
    echo printAvailHtml($arResult["CATALOG_QUANTITY"], $arResult["CATALOG_MEASURE_NAME"], $params, $showCatalogQtyCnt);
    if (count($arResult["OFFERS"]) > 0) {?>
        </div>
        <?  foreach ($arResult["OFFERS"] as $offer) {?>
            <div class="bxr-offer-avail-wrap" data-item="<?=$offer["ID"]?>" style="display: none;">
                <?echo printAvailHtml($offer["CATALOG_QUANTITY"], $offer["CATALOG_MEASURE_NAME"], $params, $showCatalogQtyCnt);?>
            </div>
        <?}
    }
}

Here you need to add a check on the delivery property ()
i.e. for the product we create a property with the delivery date, and in the file we take if (([delivery time]-[today]<7 days)&([delivery time]-[today]>0 days)) then we write "Delivery is expected".
I created a product property, but for some reason it is not displayed in any way ... I also tried $html .= $arParams["PROPERTIES"]["DATE_POSTAVKY"]["VALUE"]; and $html .= $arElement['PROPERTIES']['DATE_POSTAVKY']['VALUE']; but it doesn't output anything

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lie2, 2020-06-29
@lie2

Resolved:
2 options were implemented:
1) a product property was added - the delivery date, I compare it with the present date, and if the difference is less than 14 days, the status changes
2) (simpler) property of the list type - select the item "delivery expected" and the status changes .
Important!
Let's go through the code step by step:
1) do a check (by the way, not necessarily) , the main thing is to assign a value

if ($arResult["PROPERTIES"]["ojidaetsya_dostavka"]["VALUE"] !== '') $ojidaetsya_dostavka = $arResult["PROPERTIES"]["ojidaetsya_dostavka"]["VALUE"];

2) pass the result to
echo printAvailHtml($arResult["CATALOG_QUANTITY"], $arResult["CATALOG_MEASURE_NAME"], $params, $showCatalogQtyCnt, $ojidaetsya_dostavka);

and already in the handler we check the condition:
if ($ojidaetsya_dostavka =='да') $params["NOT_IN_STOCK"]="Уточнить наличие"; 
        $html .= $params["NOT_IN_STOCK"];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question