function CatalogBasketCancelCallback($PRODUCT_ID, $QUANTITY, $bCancel) { $PRODUCT_ID = intval($PRODUCT_ID); $QUANTITY = doubleval($QUANTITY); $bCancel = $bCancel ? true : false; if ($bCancel) { CCatalogProduct::QuantityTracer($PRODUCT_ID, -$QUANTITY); } else { CCatalogProduct::QuantityTracer($PRODUCT_ID, $QUANTITY); } }
/** * * @param $productID * @param $quantity * @param $renewal */ function CatalogBasketOrderCustomCallback($productID, $quantity, $renewal = "N") { $productID = IntVal($productID); $quantity = DoubleVal($quantity); $renewal = (($renewal == "Y") ? "Y" : "N"); $arResult = array(); if ($arCatalogProduct = CCatalogProduct::GetByID($productID)) { if ($arCatalogProduct["QUANTITY_TRACE"]=="Y" && DoubleVal($arCatalogProduct["QUANTITY"])<doubleVal($quantity)) return $arResult; } $rs = CPrice::GetList(array(), array("CATALOG_GROUP_NAME" => GetCityPrice(), "PRODUCT_ID" => $productID), false, false); $ar = $rs -> Fetch(); $arPrice = array(); $arPrice[] = array( "ID" => $ar["ID"], "PRICE" => $ar["PRICE"], "CURRENCY" => $ar["CURRENCY"], "CATALOG_GROUP_ID" => $ar["CATALOG_GROUP_ID"] ); $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $GLOBALS["USER"]->GetUserGroupArray(), $renewal, $arPrice); if (!$arPrice || count($arPrice) <= 0) { if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $GLOBALS["USER"]->GetUserGroupArray())) { $quantity = $nearestQuantity; $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $GLOBALS["USER"]->GetUserGroupArray(), $renewal); } } if (!$arPrice || count($arPrice) <= 0) { return $arResult; } $dbIBlockElement = CIBlockElement::GetList( array(), array( "ID" => $productID, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y" ) ); $arProduct = $dbIBlockElement->GetNext(); $currentPrice = $arPrice["PRICE"]["PRICE"]; $currentDiscount = 0.0; //SIGURD: logic change. see mantiss 5036. // discount applied to a final price with VAT already included. if ($arPrice['PRICE']['VAT_INCLUDED'] == 'N') { if(DoubleVal($arPrice['PRICE']['VAT_RATE']) > 0) { $currentPrice *= (1 + $arPrice['PRICE']['VAT_RATE']); $arPrice['PRICE']['VAT_INCLUDED'] = 'Y'; } } if (isset($arPrice["DISCOUNT"]) && count($arPrice["DISCOUNT"]) > 0) { if ($arPrice["DISCOUNT"]["VALUE_TYPE"]=="F") { if ($arPrice["DISCOUNT"]["CURRENCY"] == $arPrice["PRICE"]["CURRENCY"]) $currentDiscount = $arPrice["DISCOUNT"]["VALUE"]; else $currentDiscount = CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT"]["VALUE"], $arPrice["DISCOUNT"]["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]); } else $currentDiscount = $currentPrice * $arPrice["DISCOUNT"]["VALUE"] / 100.0; $currentDiscount = roundEx($currentDiscount, SALE_VALUE_PRECISION); if (DoubleVal($arPrice["DISCOUNT"]["MAX_DISCOUNT"]) > 0) { if ($arPrice["DISCOUNT"]["CURRENCY"] == $baseCurrency) $maxDiscount = $arPrice["DISCOUNT"]["MAX_DISCOUNT"]; else $maxDiscount = CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT"]["MAX_DISCOUNT"], $arPrice["DISCOUNT"]["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]); $maxDiscount = roundEx($maxDiscount, CATALOG_VALUE_PRECISION); if ($currentDiscount > $maxDiscount) $currentDiscount = $maxDiscount; } $currentPrice = $currentPrice - $currentDiscount; } $arResult = array( "PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"], "PRICE" => $currentPrice, "VAT_RATE" => $arPrice['PRICE']['VAT_RATE'], "CURRENCY" => $arPrice["PRICE"]["CURRENCY"], "QUANTITY" => $quantity, "WEIGHT" => 0, "NAME" => $arProduct["~NAME"], "CAN_BUY" => "Y", "NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DISCOUNT_PRICE" => $currentDiscount, ); if(!empty($arPrice["DISCOUNT"])) { if(strlen($arPrice["DISCOUNT"]["COUPON"])>0) $arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"]; if($arPrice["DISCOUNT"]["VALUE_TYPE"]=="P") $arResult["DISCOUNT_VALUE"] = $arPrice["DISCOUNT"]["VALUE"]."%"; else $arResult["DISCOUNT_VALUE"] = SaleFormatCurrency($arPrice["DISCOUNT"]["VALUE"], $arPrice["DISCOUNT"]["CURRENCY"]); $arResult["DISCOUNT_NAME"] = "[".$arPrice["DISCOUNT"]["ID"]."] ".$arPrice["DISCOUNT"]["NAME"]; $dbCoupon = CCatalogDiscountCoupon::GetList( array(), array("COUPON" => $arPrice["DISCOUNT"]["COUPON"]), false, false, array("ID", "ONE_TIME") ); if ($arCoupon = $dbCoupon->Fetch()) { $arFieldsCoupon = Array("DATE_APPLY" => Date($GLOBALS["DB"]->DateFormatToPHP(CSite::GetDateFormat("FULL", SITE_ID)))); if ($arCoupon["ONE_TIME"] == "Y") { $arFieldsCoupon["ACTIVE"] = "N"; foreach($_SESSION["CATALOG_USER_COUPONS"] as $k => $v) { if(trim($v) == trim($arPrice["DISCOUNT"]["COUPON"])) { unset($_SESSION["CATALOG_USER_COUPONS"][$k]); $_SESSION["CATALOG_USER_COUPONS"][$k] == ""; } } } CCatalogDiscountCoupon::Update($arCoupon["ID"], $arFieldsCoupon); } } if ($arCatalogProduct) { $arResult["WEIGHT"] = IntVal($arCatalogProduct["WEIGHT"]); } CCatalogProduct::QuantityTracer($productID, $quantity); return $arResult; }