Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/php_interface/wbs24.lib/lib/Stocks/ |
Upload File : |
<?php namespace Wbs24\Lib\Stocks; use Bitrix\{ Main, Catalog, Sale }; class CatalogProvider extends LegacyCatalogProvider { protected static function getCatalogProducts(array $list, array $select): array { if (empty($select)) { $select = ['*']; } elseif (!in_array('ID', $select)) { $select[] = 'ID'; } Main\Type\Collection::normalizeArrayValuesByInt($list, true); if (empty($list)) { return []; } $resultList = []; foreach (array_chunk($list, 500) as $pageIds) { $iterator = Catalog\Model\Product::getList([ 'select' => $select, 'filter' => ['@ID' => $pageIds], ]); while ($row = $iterator->fetch()) { Catalog\Product\SystemField::prepareRow($row, Catalog\Product\SystemField::OPERATION_PROVIDER); $row['CHECK_QUANTITY'] = ($row['QUANTITY_TRACE'] === 'Y' && $row['CAN_BUY_ZERO'] === 'N'); $row['ID'] = (int)$row['ID']; $row['TYPE'] = (int)$row['TYPE']; $row['QUANTITY'] = (float)$row['QUANTITY']; $row['QUANTITY_RESERVED'] = (float)$row['QUANTITY_RESERVED']; $resultList[$row['ID']] = $row; } } // wholesale call $resultList = self::getCatalogProductsForWholesaleBuyers($resultList); //debug /* $log = date("Y.m.d H:i:s")."\r\n".print_r($resultList, true)."\r\n\r\n"; if ($log) { $handle = @fopen($_SERVER['DOCUMENT_ROOT']."/upload/resultList.txt", "a"); fwrite($handle, $log); fclose($handle); } */ return $resultList; } protected static function getCatalogProductsForWholesaleBuyers(array $resultList, ?Wholesale $wholesaleObject = null): array { if (!$wholesaleObject) $wholesaleObject = new Wholesale(); $resultList = $wholesaleObject->getCatalogProducts($resultList); return $resultList; } protected static function reserveQuantityWithDisabledReservation(array $productData): Sale\Result { $result = new Sale\Result(); $catalogData = $productData['CATALOG']; $isQuantityTrace = $catalogData["QUANTITY_TRACE"] == 'Y'; $productQuantity = 0; if (array_key_exists('QUANTITY', $productData)) { $productQuantity = $productData['QUANTITY']; } elseif (!empty($productData['QUANTITY_LIST'])) { foreach ($productData['QUANTITY_LIST'] as $basketCode => $quantity) { $productQuantity += $quantity; } } $catalogQuantity = 0; if (array_key_exists('QUANTITY', $catalogData)) { $catalogQuantity = floatval($catalogData['QUANTITY']); } elseif (!empty($catalogData['PRICE_LIST'])) { foreach ($catalogData['PRICE_LIST'] as $basketCode => $catalogValue) { $catalogQuantity += floatval($catalogValue['QUANTITY']); } } $isUpdated = true; $fields = array( 'QUANTITY' => $catalogQuantity ); if ($isQuantityTrace) { $productId = $productData['PRODUCT_ID']; $fields['QUANTITY'] -= $productQuantity; if ($catalogData["CAN_BUY_ZERO"] != "Y" && ($catalogQuantity < $productQuantity)) { $result->addWarning( new Sale\ResultWarning( Main\Localization\Loc::getMessage( "RESERVE_QUANTITY_NOT_ENOUGH_ERROR", array_merge( self::getProductCatalogInfo($productId), array("#PRODUCT_ID#" => $productId) ) ), "RESERVE_QUANTITY_NOT_ENOUGH_ERROR" ) ); $fields['QUANTITY'] = 0; } // original call //$isUpdated = \CCatalogProduct::Update($productId, $fields); // wholesale call $wholesale = new Wholesale(); $isUpdated = $wholesale->updateStocks($productId, $fields['QUANTITY']); } if ($isUpdated) { $result->setData($fields); } return $result; } }