dikey58
@dikey58
Самоучка - web-разработчик

Почему при изменении поля на событии MeasureRation::onBeforeAdd modifyFields() вызывает ошибку mysql 1062?

Завязал событие
\Bitrix\Main\EventManager::getInstance()->addEventHandler("catalog", "\Bitrix\Catalog\MeasureRatio::OnBeforeAdd", ["MeasureRatioUpdate", "waydevOnMeasureRatioHandler"] );

И делаю обработчик:
function waydevOnMeasureRatioHandler(\Bitrix\Main\Event $event)
    {
        $result = new \Bitrix\Main\Entity\EventResult;
        $arFields = $event->getParameter("fields");

        if($arFields["RATIO"] == self::$minPartiya)
        {
            return;
        }

        $arModified = $arFields;
        $arModified["RATIO"] = self::$minPartiya;

        $result->modifyFields($arModified);

        return $result;
    }

Но при создание товара возникает ошибка:
[Bitrix\Main\DB\SqlQueryException] 
Mysql query error: (1062) Duplicate entry '511194-29' for key 'IX_B_CATALOG_MEASURE_RATIO' (400)
INSERT INTO `b_catalog_measure_ratio`(`IS_DEFAULT`, `PRODUCT_ID`, `RATIO`) VALUES ('Y', 511194, '29')
/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/main/lib/db/mysqliconnection.php:153
#0: Bitrix\Main\DB\MysqliConnection->queryInternal(string, array, NULL)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/main/lib/db/connection.php:327
#1: Bitrix\Main\DB\Connection->query(string, NULL)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/main/lib/db/connection.php:376
#2: Bitrix\Main\DB\Connection->queryExecute(string)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/main/lib/db/connection.php:451
#3: Bitrix\Main\DB\Connection->add(string, array, string)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/main/lib/orm/data/datamanager.php:937
#4: Bitrix\Main\ORM\Data\DataManager::add(array)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/catalog/general/measure_ratio.php:109
#5: CCatalogMeasureRatioAll::add(array)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/catalog/admin/templates/product_edit_action.php:446
#6: include(string)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/modules/iblock/admin/iblock_element_edit.php:1231
#7: include(string)
	/home/s/suppoiaf/mirpp.suppoiaf.beget.tech/public_html/bitrix/admin/cat_product_edit.php:3
  • Вопрос задан
  • 89 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы