本文整理汇总了PHP中CCatalogProduct::Update方法的典型用法代码示例。如果您正苦于以下问题:PHP CCatalogProduct::Update方法的具体用法?PHP CCatalogProduct::Update怎么用?PHP CCatalogProduct::Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCatalogProduct
的用法示例。
在下文中一共展示了CCatalogProduct::Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCatalogProducts
protected function addCatalogProducts($arParams){
if (!CModule::IncludeModule("iblock") && !CModule::IncludeModule("catalog") && !CModule::IncludeModule("sale")):
return false;
endif;
$arFields = array(
"ID" => $arParams["PRODUCT_ID"],
"QUANTITY" => $arParams["BALANCE"],
"CAN_BUY_ZERO" => "Y",
"NEGATIVE_AMOUNT_TRACE" => "Y",
"QUANTITY_TRACE" => "Y"
);
$db_res = CCatalogProduct::GetList(
array(),
array("ID" => $arParams["PRODUCT_ID"]),
false,
array()
);
if ($ar_res = $db_res->Fetch()):
if (!CCatalogProduct::Update($ar_res["ID"], $arFields)):
return false;
endif;
else:
if(!CCatalogProduct::Add($arFields)):
return false;
endif;
endif;
return true;
}
示例2: Add
public function Add($arFields, $boolCheck = true)
{
global $DB;
$boolFlag = false;
$boolCheck = (false == $boolCheck ? false : true);
$arFields["ID"] = intval($arFields["ID"]);
if ($arFields["ID"]<=0)
return false;
if ($boolCheck)
{
$db_result = $DB->Query("SELECT 'x' FROM b_catalog_product WHERE ID = ".$arFields["ID"], false, "File: ".__FILE__."<br>Line: ".__LINE__);
if ($db_result->Fetch())
{
$boolFlag = true;
}
}
if (true == $boolFlag)
{
return CCatalogProduct::Update($arFields["ID"], $arFields);
}
else
{
foreach (GetModuleEvents("catalog", "OnBeforeProductAdd", true) as $arEvent)
{
if (ExecuteModuleEventEx($arEvent, array(&$arFields))===false)
return false;
}
if (!CCatalogProduct::CheckFields("ADD", $arFields, 0))
return false;
$arInsert = $DB->PrepareInsert("b_catalog_product", $arFields);
$strSql = "INSERT INTO b_catalog_product(".$arInsert[0].") VALUES(".$arInsert[1].")";
$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
foreach (GetModuleEvents("catalog", "OnProductAdd", true) as $arEvent)
{
ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
}
// strange copy-paste bug
foreach (GetModuleEvents("sale", "OnProductAdd", true) as $arEvent)
{
ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
}
}
return true;
}
示例3: Add
public function Add($arFields, $boolCheck = true)
{
global $DB;
$existProduct = false;
$boolCheck = $boolCheck !== false;
if (empty($arFields['ID'])) {
return false;
}
$arFields['ID'] = (int) $arFields['ID'];
if ($arFields['ID'] <= 0) {
return false;
}
if ($boolCheck) {
$existProduct = Catalog\ProductTable::isExistProduct($arFields['ID']);
}
if ($existProduct) {
return CCatalogProduct::Update($arFields['ID'], $arFields);
} else {
foreach (GetModuleEvents("catalog", "OnBeforeProductAdd", true) as $arEvent) {
if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
return false;
}
}
if (!CCatalogProduct::CheckFields("ADD", $arFields, 0)) {
return false;
}
$arInsert = $DB->PrepareInsert("b_catalog_product", $arFields);
$strSql = "INSERT INTO b_catalog_product(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
Catalog\ProductTable::clearProductCache($arFields['ID']);
foreach (GetModuleEvents("catalog", "OnProductAdd", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
}
// strange copy-paste bug
foreach (GetModuleEvents("sale", "OnProductAdd", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
}
}
return true;
}
示例4: ImportElementPrices
//.........这里部分代码省略.........
$arElement["DISCOUNTS"][$discount_value] = $discount_percent;
}
}
}
}
}
if (array_key_exists($this->mess["IBLOCK_XML2_AMOUNT"], $arXMLElement)) {
$arElementTmp = array();
$arElement["QUANTITY_RESERVED"] = 0;
if ($arElement["ID"]) {
$arElementTmp = CCatalogProduct::GetById($arElement["ID"]);
}
if (is_array($arElementTmp) && !empty($arElementTmp) && isset($arElementTmp["QUANTITY_RESERVED"])) {
$arElement["QUANTITY_RESERVED"] = $arElementTmp["QUANTITY_RESERVED"];
}
$arElement["QUANTITY"] = $this->ToFloat($arXMLElement[$this->mess["IBLOCK_XML2_AMOUNT"]]) - doubleval($arElement["QUANTITY_RESERVED"]);
}
if (isset($arElement["PRICES"]) && $this->bCatalog) {
if (isset($arElement["QUANTITY"])) {
$arProduct["QUANTITY"] = $arElement["QUANTITY"];
} elseif (isset($arElement["STORE_AMOUNT"]) && !empty($arElement["STORE_AMOUNT"])) {
$arProduct["QUANTITY"] = array_sum($arElement["STORE_AMOUNT"]);
}
$rsWeight = CIBlockElement::GetProperty($IBLOCK_ID, $arElement["ID"], array(), array("CODE" => "CML2_TRAITS"));
while ($arWeight = $rsWeight->Fetch()) {
if ($arWeight["DESCRIPTION"] == $this->mess["IBLOCK_XML2_WEIGHT"]) {
$arProduct["WEIGHT"] = $this->ToFloat($arWeight["VALUE"]) * 1000;
}
}
$rsUnit = CIBlockElement::GetProperty($IBLOCK_ID, $arElement["ID"], array(), array("CODE" => "CML2_BASE_UNIT"));
while ($arUnit = $rsUnit->Fetch()) {
if ($arUnit["DESCRIPTION"] > 0) {
$arProduct["MEASURE"] = $arUnit["DESCRIPTION"];
}
}
//Here start VAT handling
//Check if all the taxes exists in BSM catalog
$arTaxMap = array();
$rsTaxProperty = CIBlockElement::GetProperty($IBLOCK_ID, $arElement["ID"], array("sort" => "asc"), array("CODE" => "CML2_TAXES"));
while ($arTaxProperty = $rsTaxProperty->Fetch()) {
if (strlen($arTaxProperty["VALUE"]) > 0 && strlen($arTaxProperty["DESCRIPTION"]) > 0 && !array_key_exists($arTaxProperty["DESCRIPTION"], $arTaxMap)) {
$arTaxMap[$arTaxProperty["DESCRIPTION"]] = array("RATE" => $this->ToFloat($arTaxProperty["VALUE"]), "ID" => $this->CheckTax($arTaxProperty["DESCRIPTION"], $this->ToFloat($arTaxProperty["VALUE"])));
}
}
//First find out if all the prices have TAX_IN_SUM true
$TAX_IN_SUM = "Y";
foreach ($arElement["PRICES"] as $price) {
if ($price["PRICE"]["TAX_IN_SUM"] !== "true") {
$TAX_IN_SUM = "N";
break;
}
}
//If there was found not included tax we'll make sure
//that all prices has the same flag
if ($TAX_IN_SUM === "N") {
foreach ($arElement["PRICES"] as $price) {
if ($price["PRICE"]["TAX_IN_SUM"] !== "false") {
$TAX_IN_SUM = "Y";
break;
}
}
//Check if there is a mix of tax in sum
//and correct it by recalculating all the prices
if ($TAX_IN_SUM === "Y") {
foreach ($arElement["PRICES"] as $key => $price) {
if ($price["PRICE"]["TAX_IN_SUM"] !== "true") {
$TAX_NAME = $price["PRICE"]["TAX_NAME"];
if (array_key_exists($TAX_NAME, $arTaxMap)) {
$PRICE_WO_TAX = $this->ToFloat($price[$this->mess["IBLOCK_XML2_PRICE_FOR_ONE"]]);
$PRICE = $PRICE_WO_TAX + $PRICE_WO_TAX / 100.0 * $arTaxMap[$TAX_NAME]["RATE"];
$arElement["PRICES"][$key][$this->mess["IBLOCK_XML2_PRICE_FOR_ONE"]] = $PRICE;
}
}
}
}
}
if ($TAX_IN_SUM == "Y" && $arTaxMap) {
$vat = current($arTaxMap);
$arProduct["VAT_ID"] = $vat["ID"];
} else {
foreach ($arElement["PRICES"] as $price) {
$TAX_NAME = $price["PRICE"]["TAX_NAME"];
if (array_key_exists($TAX_NAME, $arTaxMap)) {
$arProduct["VAT_ID"] = $arTaxMap[$TAX_NAME]["ID"];
break;
}
}
}
$arProduct["VAT_INCLUDED"] = $TAX_IN_SUM;
CCatalogProduct::Add($arProduct);
$this->SetProductPrice($arElement["ID"], $arElement["PRICES"], $arElement["DISCOUNTS"]);
} elseif ($this->bCatalog && isset($arElement["STORE_AMOUNT"]) && !empty($arElement["STORE_AMOUNT"]) && CCatalogProduct::GetById($arElement["ID"])) {
CCatalogProduct::Update($arElement["ID"], array("QUANTITY" => array_sum($arElement["STORE_AMOUNT"])));
} elseif ($this->bCatalog && isset($arElement["QUANTITY"]) && CCatalogProduct::GetById($arElement["ID"])) {
CCatalogProduct::Update($arElement["ID"], array("QUANTITY" => $arElement["QUANTITY"]));
}
}
$counter["UPD"]++;
return $arElement["ID"];
}
示例5: AuthtorizeAfterAds
/**
* функция после добавлением элемента в инфоблока
* @param $arFields поля элемента ифоблока
* для страницы Объявления
* eсли VIP объявление то добавляет корзину
* привязывает по ID созданное объявления к товару в корзине
* редирект на необходимы url
*/
function AuthtorizeAfterAds(&$arFields){
unset($_SESSION['user777999authorize']);
if($arFields['PROPERTY_VALUES']['114']){
foreach($arFields['PROPERTY_VALUES']['114'] as $key114 => $item114){
if($item114['VALUE']){
foreach($arFields['PROPERTY_VALUES']['113'] as $key113 => $item113){
if($item113['VALUE']){
$arFields['PROPERTY_VALUES']['113'][$key113]=ConvertDateTime($item114['VALUE'], "YYYY-MM-DD HH:MI:SS");
}else{
$arFields['PROPERTY_VALUES']['113'][n0]=ConvertDateTime($item114['VALUE'], "YYYY-MM-DD HH:MI:SS");
}
}
}
}
}
if(($arFields["IBLOCK_ID"] == 16)&&(!CUser::IsAuthorized())){
global $USER;
$rsUser = CUser::GetByID($_SESSION['NEW_USER_ID']);
$arUser = $rsUser->Fetch();
$_SESSION['$arUser']=$arUser;
$USER = new CUser;
$arAuthResult = $USER->Login($arUser['LOGIN'], $arUser['PASSWORD'], "Y","N");
}
//$_SESSION['user777authorize']=$arFields;
if(($arFields["IBLOCK_ID"] == 16)&&(CModule::IncludeModule("catalog"))&&(CModule::IncludeModule("sale"))){
$price_product=floatval($arFields["PROPERTY_VALUES"][86]);
$quantity_product=floatval($arFields["PROPERTY_VALUES"][87]);
if($price_product){
$PRODUCT_ID = $arFields['ID'];
$PRICE_TYPE_ID = 1;
$arFieldsprice = Array(
"PRODUCT_ID" => $PRODUCT_ID,
"CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
"PRICE" =>$price_product,
"CURRENCY" => "RUB",
"QUANTITY_FROM" => 1,
);
$res = CPrice::GetList(
array(),
array(
"PRODUCT_ID" => $PRODUCT_ID,
"CATALOG_GROUP_ID" => $PRICE_TYPE_ID
)
);
if ($arr = $res->Fetch())
{
CPrice::Update($arr["ID"], $arFieldsprice);
}
else
{
CPrice::Add($arFieldsprice,true);
}
}
}
if (
(
(($arFields["IBLOCK_ID"] == 2)&& (is_numeric($arFields["PROPERTY_VALUES"][73])))
||
(($arFields["IBLOCK_ID"] == 15)&& (is_numeric($arFields["PROPERTY_VALUES"][76])))
||
(($arFields["IBLOCK_ID"] == 14)&& (is_numeric($arFields["PROPERTY_VALUES"][78])))
)
&&
CModule::IncludeModule("catalog")
&&
CModule::IncludeModule("sale")
&&
((strstr($_SERVER['REQUEST_URI'],'/personal/moy-magazin/'))||(strstr($_SERVER['REQUEST_URI'],'/obyavleniya/add-ads/')))
)
{
switch($arFields["IBLOCK_ID"]){
case 2:
$price_product=floatval($arFields["PROPERTY_VALUES"][73]);
$quantity_product=floatval($arFields["PROPERTY_VALUES"][75]);
break;
case 14:
$price_product=floatval($arFields["PROPERTY_VALUES"][78]);
$quantity_product=floatval($arFields["PROPERTY_VALUES"][79]);
//.........这里部分代码省略.........
示例6: cancellationDocument
/**
* @param $arFields
* @return array|bool
*/
public static function cancellationDocument($arFields)
{
global $DB;
$id = intval($arFields["ID"]);
$i = 0;
$dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $id));
while ($arDocElement = $dbDocElements->Fetch()) {
$arResult = array();
$arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]);
$newReserved = $arProductInfo["QUANTITY_RESERVED"] + $arDocElement["AMOUNT"];
$arResult["QUANTITY_RESERVED"] = $newReserved;
$dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arDocElement["ELEMENT_ID"] . " AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true);
if ($arAmount = $dbAmount->Fetch()) {
$arResult["QUANTITY"] = doubleval($arAmount["SUM"] - $newReserved);
if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arResult)) {
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
return false;
}
}
$i++;
}
if ($i > 0) {
return true;
}
return false;
}
示例7: DeductProduct
public static function DeductProduct($arParams)
{
global $DB;
$arRes = array();
$arFields = array();
$strUseStoreControl = COption::GetOptionString('catalog', 'default_use_store_control', 'N');
if (intval($arParams["PRODUCT_ID"]) <= 0) {
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("RSRV_INCORRECT_ID"), "NO_ORDER_ID");
$arRes["RESULT"] = false;
return $arRes;
}
$arParams["QUANTITY"] = doubleval($arParams["QUANTITY"]);
if (intval($arParams["UNDO_DEDUCTION"]) != "Y") {
$arParams["UNDO_DEDUCTION"] = "N";
}
if (intval($arParams["EMULATE"]) != "Y") {
$arParams["EMULATE"] = "N";
}
if (intval($arParams["PRODUCT_RESERVED"]) != "Y") {
$arParams["PRODUCT_RESERVED"] = "N";
}
if (!isset($arParams["STORE_DATA"])) {
$arParams["STORE_DATA"] = array();
}
if (!is_array($arParams["STORE_DATA"])) {
$arParams["STORE_DATA"] = array($arParams["STORE_DATA"]);
}
$rsProducts = CCatalogProduct::GetList(array(), array('ID' => $arParams["PRODUCT_ID"]), false, false, array('ID', 'QUANTITY', 'QUANTITY_RESERVED'));
if ($arProduct = $rsProducts->Fetch()) {
if ($arParams["UNDO_DEDUCTION"] == "N") {
if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N") {
$arRes["RESULT"] = true;
} else {
if ($strUseStoreControl == "Y") {
if (!empty($arParams["STORE_DATA"])) {
$totalAmount = 0;
foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
if (!isset($arRecord["STORE_ID"]) || intval($arRecord["STORE_ID"]) < 0 || !isset($arRecord["QUANTITY"]) || intval($arRecord["QUANTITY"]) < 0) {
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_STORE_ERROR");
$arRes["RESULT"] = false;
return $arRes;
}
$rsProps = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $arParams["PRODUCT_ID"], "STORE_ID" => $arRecord["STORE_ID"]), false, false, array('ID', 'AMOUNT'));
if ($arProp = $rsProps->Fetch()) {
if ($arProp["AMOUNT"] < $arRecord["QUANTITY"]) {
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_QUANTITY_STORE_ERROR", array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord["STORE_ID"]))), "DDCT_DEDUCTION_QUANTITY_STORE_ERROR");
$arRes["RESULT"] = false;
return $arRes;
} else {
$res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] - $arRecord["QUANTITY"]));
if ($res) {
$arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
$totalAmount += $arRecord["QUANTITY"];
//deleting barcodes
if (isset($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"]) && count($arRecord["BARCODE"]) > 0) {
foreach ($arRecord["BARCODE"] as $barcodeId => $barcodeValue) {
$arFields = array("STORE_ID" => $arRecord["STORE_ID"], "BARCODE" => $barcodeValue, "PRODUCT_ID" => $arParams["PRODUCT_ID"]);
$dbres = CCatalogStoreBarcode::GetList(array(), $arFields, false, false, array("ID", "STORE_ID", "BARCODE", "PRODUCT_ID"));
if ($arRes = $dbres->Fetch()) {
CCatalogStoreBarcode::Delete($arRes["ID"]);
}
}
}
} else {
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
$arRes["RESULT"] = false;
return $arRes;
}
}
}
}
//updating total sum
//TODO
// $dbAmount = $DB->Query("SELECT SUM(AMOUNT) as AMOUNT FROM b_catalog_store_product WHERE PRODUCT_ID = ".intval($arParams["PRODUCT_ID"])." ", true);
// if ($amount = $dbAmount->Fetch())
// {
if ($arParams["PRODUCT_RESERVED"] == "Y") {
if ($totalAmount <= $arProduct["QUANTITY_RESERVED"]) {
$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $totalAmount;
} else {
if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
$arFields["QUANTITY_RESERVED"] = 0;
$arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($totalAmount - $arProduct["QUANTITY_RESERVED"]);
} else {
$arRes["RESULT"] = false;
return $arRes;
}
}
} else {
if ($totalAmount <= $arProduct["QUANTITY"]) {
$arFields["QUANTITY"] = $arProduct["QUANTITY"] - $totalAmount;
} else {
if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
$arFields["QUANTITY"] = 0;
$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - ($totalAmount - $arProduct["QUANTITY"]);
} else {
$arRes["RESULT"] = false;
return $arRes;
}
}
//.........这里部分代码省略.........
示例8: QuantityTracer
/**
* <p>Уменьшает количество на складе товара с кодом PRODUCT_ID на величину DELTA_QUANTITY, если указанное количество есть на складе и у товара установлен флаг "уменьшать количество товара при заказе" </p>
*
*
*
*
* @param int $PRODUCT_ID Код товара.
*
*
*
* @param int $DELTA_QUANTITY Число, на которое нужно уменьшить количество товара на складе.
*
*
*
* @return bool <p>Возвращает <i>true</i> в случае успешного уменьшения и <i>false</i> - в
* противном случае </p><a name="examples"></a>
*
*
* <h4>Example</h4>
* <pre>
* <?
* // Уменьшим количество на складе товара 5 на 12 штук
* CCatalogProduct::QuantityTracer(5, 12);
* ?>
* </pre>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproduct/ccatalogproduct__quantitytracer.8cc817fa.php
* @author Bitrix
*/
public static function QuantityTracer($ProductID, $DeltaQuantity)
{
global $DB;
global $CACHE_MANAGER;
$boolClearCache = false;
$ProductID = intval($ProductID);
if (0 >= $ProductID)
return false;
$DeltaQuantity = doubleval($DeltaQuantity);
if ($DeltaQuantity==0)
return false;
$rsProducts = CCatalogProduct::GetList(
array(),
array('ID' => $ProductID),
false,
false,
array('ID', 'CAN_BUY_ZERO', 'NEGATIVE_AMOUNT_TRACE', 'QUANTITY_TRACE', 'QUANTITY', 'ELEMENT_IBLOCK_ID')
);
if (($arProduct = $rsProducts->Fetch())
&& ($arProduct["QUANTITY_TRACE"]=="Y"))
{
$strAllowNegativeAmount = $arProduct["NEGATIVE_AMOUNT_TRACE"];
$arFields = array();
$arFields["QUANTITY"] = doubleval($arProduct["QUANTITY"]) - $DeltaQuantity;
if ('Y' != $arProduct['CAN_BUY_ZERO'])
{
if (defined("BX_COMP_MANAGED_CACHE"))
{
$boolClearCache = (0 >= $arFields["QUANTITY"]*$arProduct["QUANTITY"]);
}
}
if ('Y' != $arProduct['CAN_BUY_ZERO'] || 'Y' != $strAllowNegativeAmount)
{
if (0 >= $arFields["QUANTITY"])
$arFields["QUANTITY"] = 0;
}
$arFields['OLD_QUANTITY'] = $arProduct["QUANTITY"];
CCatalogProduct::Update($arProduct["ID"], $arFields);
if ($boolClearCache)
$CACHE_MANAGER->ClearByTag('iblock_id_'.$arProduct['ELEMENT_IBLOCK_ID']);
$arProduct['OLD_QUANTITY'] = $arFields['OLD_QUANTITY'];
$arProduct['QUANTITY'] = $arFields['QUANTITY'];
$arProduct['ALLOW_NEGATIVE_AMOUNT'] = $strAllowNegativeAmount;
$arProduct['DELTA'] = $DeltaQuantity;
foreach (GetModuleEvents("catalog", "OnProductQuantityTrace", true) as $arEvent)
{
ExecuteModuleEventEx($arEvent, array($arProduct["ID"], $arProduct));
}
return true;
}
return false;
}
示例9: Update
public static function Update($ID, $arFields)
{
if (!CModule::IncludeModule('catalog')) {
return false;
}
global $DB;
if (!self::CheckFields('UPDATE', $arFields, $ID)) {
return false;
}
if (isset($arFields['NAME']) || isset($arFields['SECTION_ID']) || isset($arFields['SORT']) || isset($arFields['ACTIVE']) || isset($arFields['DETAIL_PICTURE']) || isset($arFields['DESCRIPTION']) || isset($arFields['DESCRIPTION_TYPE']) || isset($arFields['PREVIEW_PICTURE']) || isset($arFields['PREVIEW_TEXT']) || isset($arFields['PREVIEW_TEXT_TYPE']) || isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID']) || isset($arFields['XML_ID']) || isset($arFields['PROPERTY_VALUES'])) {
$element = new CIBlockElement();
$obResult = $element->GetById($ID);
if ($arElement = $obResult->Fetch()) {
// files
$arElement['PREVIEW_PICTURE'] = CFile::MakeFileArray($arElement['PREVIEW_PICTURE']);
$arElement['DETAIL_PICTURE'] = CFile::MakeFileArray($arElement['DETAIL_PICTURE']);
if (isset($arFields['NAME'])) {
$arElement['NAME'] = $arFields['NAME'];
}
if (isset($arFields['SECTION_ID'])) {
$arElement['IBLOCK_SECTION_ID'] = $arFields['SECTION_ID'];
}
if (isset($arFields['SORT'])) {
$arElement['SORT'] = $arFields['SORT'];
}
if (isset($arFields['ACTIVE'])) {
$arElement['ACTIVE'] = $arFields['ACTIVE'];
}
if (isset($arFields['DETAIL_PICTURE'])) {
$arElement['DETAIL_PICTURE'] = $arFields['DETAIL_PICTURE'];
}
if (isset($arFields['DESCRIPTION'])) {
$arElement['DETAIL_TEXT'] = $arFields['DESCRIPTION'];
}
if (isset($arFields['DESCRIPTION_TYPE'])) {
$arElement['DETAIL_TEXT_TYPE'] = $arFields['DESCRIPTION_TYPE'];
}
if (isset($arFields['PREVIEW_PICTURE'])) {
$arElement['PREVIEW_PICTURE'] = $arFields['PREVIEW_PICTURE'];
}
if (isset($arFields['PREVIEW_TEXT'])) {
$arElement['PREVIEW_TEXT'] = $arFields['PREVIEW_TEXT'];
$arElement['PREVIEW_TEXT_TYPE'] = 'text';
}
if (isset($arFields['PREVIEW_TEXT_TYPE'])) {
$arElement['PREVIEW_TEXT_TYPE'] = $arFields['PREVIEW_TEXT_TYPE'];
}
if (isset($arFields['XML_ID'])) {
$arElement['XML_ID'] = $arElement['EXTERNAL_ID'] = $arFields['XML_ID'];
} else {
if (isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID'])) {
if (strlen($arFields['ORIGINATOR_ID']) > 0 && strlen($arFields['ORIGIN_ID']) > 0) {
$arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . '#' . $arFields['ORIGIN_ID'];
} else {
$delimiterPos = strpos($arElement['XML_ID'], '#');
if (strlen($arFields['ORIGINATOR_ID']) > 0) {
if ($delimiterPos !== false) {
$arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . substr($arElement['XML_ID'], $delimiterPos);
} else {
$arElement['XML_ID'] = $arFields['ORIGINATOR_ID'];
}
} else {
if ($delimiterPos !== false) {
$arElement['XML_ID'] = substr($arElement['XML_ID'], 0, $delimiterPos) . $arFields['ORIGIN_ID'];
} else {
$arElement['XML_ID'] = '#' . $arFields['ORIGINATOR_ID'];
}
}
}
}
}
if (isset($arFields['PROPERTY_VALUES'])) {
$arElement['PROPERTY_VALUES'] = $arFields['PROPERTY_VALUES'];
}
if (!$element->Update($ID, $arElement)) {
self::$LAST_ERROR = $element->LAST_ERROR;
return false;
}
}
}
// update VAT
$CCatalogProduct = new CCatalogProduct();
$arCatalogProductFields = array();
if (isset($arFields['VAT_INCLUDED'])) {
$arCatalogProductFields['VAT_INCLUDED'] = $arFields['VAT_INCLUDED'];
}
if (isset($arFields['VAT_ID']) && !empty($arFields['VAT_ID'])) {
$arCatalogProductFields['VAT_ID'] = $arFields['VAT_ID'];
}
if (isset($arFields['MEASURE']) && !empty($arFields['MEASURE'])) {
$arCatalogProductFields['MEASURE'] = $arFields['MEASURE'];
}
if (count($arCatalogProductFields) > 0) {
$CCatalogProduct->Update($ID, $arCatalogProductFields);
}
if (isset($arFields['PRICE']) && isset($arFields['CURRENCY_ID'])) {
self::setPrice($ID, $arFields['PRICE'], $arFields['CURRENCY_ID']);
} else {
if (isset($arFields['PRICE']) || isset($arFields['CURRENCY_ID'])) {
$CPrice = new CPrice();
//.........这里部分代码省略.........
示例10: recalculateStoreBalances
function recalculateStoreBalances($id)
{
global $DB;
$arFields = array();
if (COption::GetOptionString('catalog', 'default_use_store_control', 'N') != 'Y') {
return false;
}
$dbStoreProduct = CCatalogStoreProduct::GetList(array(), array("STORE_ID" => $id, "!AMOUNT" => 0), false, false, array("PRODUCT_ID", "AMOUNT"));
while ($arStoreProduct = $dbStoreProduct->Fetch()) {
$dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED, CS.ACTIVE FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arStoreProduct['PRODUCT_ID'] . " AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED, ACTIVE ", true);
if ($arAmount = $dbAmount->Fetch()) {
$arFields["QUANTITY"] = doubleval($arAmount["SUM"] - $arAmount["RESERVED"]);
} else {
if ($arReservAmount = CCatalogProduct::GetByID($arStoreProduct['PRODUCT_ID'])) {
$arFields["QUANTITY"] = doubleval(0 - $arReservAmount["QUANTITY_RESERVED"]);
}
}
if (!CCatalogProduct::Update($arStoreProduct["PRODUCT_ID"], $arFields)) {
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
return false;
}
}
return true;
}
示例11: cancellationDocument
/**
* @param $documentId
* @param $userId
* @return bool
*/
public static function cancellationDocument($documentId, $userId)
{
global $DB, $APPLICATION;
$documentId = (int) $documentId;
$i = 0;
$dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $documentId));
while ($arDocElement = $dbDocElements->Fetch()) {
$arResult = array();
$arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]);
$newReserved = $arProductInfo["QUANTITY_RESERVED"] + $arDocElement["AMOUNT"];
$arResult["QUANTITY_RESERVED"] = $newReserved;
$dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arDocElement["ELEMENT_ID"] . " AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true);
if ($arAmount = $dbAmount->Fetch()) {
$arResult["QUANTITY"] = doubleval($arAmount["SUM"] - $newReserved);
if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arResult)) {
$APPLICATION->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
return false;
}
if (self::isNeedClearPublicCache($arProductInfo['QUANTITY'], $arResult['QUANTITY'], $arProductInfo['QUANTITY_TRACE'], $arProductInfo['CAN_BUY_ZERO'])) {
$productInfo = array('CAN_BUY_ZERO' => $arProductInfo['CAN_BUY_ZERO'], 'NEGATIVE_AMOUNT_TRACE' => $arProductInfo['NEGATIVE_AMOUNT_TRACE'], 'QUANTITY_TRACE' => $arProductInfo['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProductInfo['QUANTITY'], 'QUANTITY' => $arResult['QUANTITY'], 'DELTA' => $arResult['QUANTITY'] - $arProductInfo['QUANTITY']);
self::clearPublicCache($arProductInfo['ID'], $productInfo);
}
}
$i++;
}
return $i > 0;
}
示例12: recalculateStoreBalances
function recalculateStoreBalances($id)
{
global $DB;
$arFields = array();
if (COption::GetOptionString('catalog', 'default_use_store_control', 'N') != 'Y') {
return true;
}
$dbStoreProduct = CCatalogStoreProduct::GetList(array(), array("STORE_ID" => $id, "!AMOUNT" => 0), false, false, array("PRODUCT_ID", "AMOUNT"));
while ($arStoreProduct = $dbStoreProduct->Fetch()) {
$dbAmount = $DB->Query("select SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED, CS.ACTIVE FROM b_catalog_store_product SP inner join b_catalog_product CP on SP.PRODUCT_ID = CP.ID inner join b_catalog_store CS on SP.STORE_ID = CS.ID where SP.PRODUCT_ID = " . $arStoreProduct['PRODUCT_ID'] . " and CS.ACTIVE = 'Y' group by QUANTITY_RESERVED, ACTIVE", true);
if ($arAmount = $dbAmount->Fetch()) {
$arFields["QUANTITY"] = doubleval($arAmount["SUM"] - $arAmount["RESERVED"]);
} else {
if ($arReservAmount = CCatalogProduct::GetByID($arStoreProduct['PRODUCT_ID'])) {
$arFields["QUANTITY"] = doubleval(0 - $arReservAmount["QUANTITY_RESERVED"]);
}
}
CCatalogProduct::Update($arStoreProduct["PRODUCT_ID"], $arFields);
}
return true;
}
示例13: DeductProduct
//.........这里部分代码省略.........
if (!isset($arRecord["STORE_ID"]) || intval($arRecord["STORE_ID"]) < 0 || !isset($arRecord["QUANTITY"]) || intval($arRecord["QUANTITY"]) < 0)
{
$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_STORE_ERROR");
$arRes["RESULT"] = false;
return $arRes;
}
$rsProps = CCatalogStoreProduct::GetList(
array(),
array(
"PRODUCT_ID" => $arParams["PRODUCT_ID"],
"STORE_ID" => $arRecord["STORE_ID"]
),
false,
false,
array('ID', 'AMOUNT')
);
if ($arProp = $rsProps->Fetch())
{
if ($arProp["AMOUNT"] < $arRecord["QUANTITY"])
{
$APPLICATION->ThrowException(
Loc::getMessage(
"DDCT_DEDUCTION_QUANTITY_STORE_ERROR",
array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord["STORE_ID"]))
),
"DDCT_DEDUCTION_QUANTITY_STORE_ERROR"
);
$arRes["RESULT"] = false;
return $arRes;
}
else
{
$res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] - $arRecord["QUANTITY"]));
if ($res)
{
$arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
$totalAmount += $arRecord["QUANTITY"];
//deleting barcodes
if (isset($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"]) && count($arRecord["BARCODE"]) > 0)
{
foreach ($arRecord["BARCODE"] as $barcodeId => $barcodeValue)
{
$arFields = array(
"STORE_ID" => $arRecord["STORE_ID"],
"BARCODE" => $barcodeValue,
"PRODUCT_ID" => $arParams["PRODUCT_ID"]
);
$dbres = CCatalogStoreBarcode::GetList(
array(),
$arFields,
false,
false,
array("ID", "STORE_ID", "BARCODE", "PRODUCT_ID")
);
if ($arRes = $dbres->Fetch())
{
CCatalogStoreBarcode::Delete($arRes["ID"]);
}
else
{
$APPLICATION->ThrowException(
示例14: intval
$arCatalogProduct['QUANTITY_TRACE'] = $arFields['CATALOG_QUANTITY_TRACE'];
if ('Y' != $strUseStoreControl)
{
if (isset($arFields['CATALOG_QUANTITY']) && '' != $arFields['CATALOG_QUANTITY'])
$arCatalogProduct['QUANTITY'] = $arFields['CATALOG_QUANTITY'];
}
if (!CCatalogProduct::IsExistProduct($ID))
{
$arCatalogProduct['ID'] = $ID;
CCatalogProduct::Add($arCatalogProduct, false);
}
else
{
if (!empty($arCatalogProduct))
CCatalogProduct::Update($ID, $arCatalogProduct);
}
if (isset($arFields['CATALOG_MEASURE_RATIO']) && '' != trim($arFields['CATALOG_MEASURE_RATIO']))
{
$intRatioID = 0;
$rsRatios = CCatalogMeasureRatio::getList(
array(),
array('PRODUCT_ID' => $ID),
false,
false,
array('ID', 'PRODUCT_ID')
);
if ($arRatio = $rsRatios->Fetch())
{
$intRatioID = intval($arRatio['ID']);
示例15: array
if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) {
break;
}
}
}
// update or delete 'not-in-file' elements
if ($bAllLinesLoaded && $outFileAction != "F") {
$arProductArray = array('QUANTITY' => 0, 'QUANTITY_TRACE' => 'Y', 'CAN_BUY_ZERO' => 'N', 'NEGATIVE_AMOUNT_TRACE' => 'N');
$res = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid), false, false, array('ID'));
while ($arr = $res->Fetch()) {
if ($outFileAction == "D") {
CIBlockElement::Delete($arr["ID"], "Y", "N");
$killed_lines++;
} elseif ($outFileAction == "F") {
} elseif ($bIBlockIsCatalog && $outFileAction == "M") {
CCatalogProduct::Update($arr['ID'], $arProductArray);
$killed_lines++;
} else {
$bDeactivationStarted = true;
$el->Update($arr["ID"], array("ACTIVE" => "N", "TMP_ID" => $tmpid));
$killed_lines++;
}
if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) {
break;
}
}
}
// delete 'not-in-file' element prices
if ($bAllLinesLoaded && $bIBlockIsCatalog && 'Y' == $bUpdatePrice && $outFileAction == "D") {
$res = CPrice::GetList(array(), array("ELEMENT_IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid), false, false, array("ID"));
while ($arr = $res->Fetch()) {