Moving to a new version of php 7 in bitrix 16.5 and I'm trying to write the name of an individual into the database with the help of the code:

https://gist.github.com/vasilukwolf/c2dfaf819de9d9b65a18b0264757c3a0

However, the recording fails. I tried to change events, I tried to just send, the result is the same. Record locked. Tried to even use the advice:

http://fmwd.ru/stati/cms/1c-bitrix/pochemu-ne-rabotaet-csaleorderpropsvalue.html

But writing to the database does not occur. However, everything is fine writes to the cache. The question is how to write this information base, similar to OnOrderSave:

https://gist.github.com/vasilukwolf/995446e77fedf29014d5bfa640734b94

  • Waiting for CodeReview for an answer. - Basil Jimmy

3 answers 3

Unfortunately, only this helped:

https://stackoverflow.com/questions/11761140/mysql-on-duplicate-key-update-trouble

As a result, made a direct request:

$strSql = "INSERT INTO `b_sale_order_props_value` SET `ORDER_ID`=" . $value_id . ", `ORDER_PROPS_ID`=" . $ar['ID'] . ", `NAME`='PRIVATE_PERSON', `VALUE`='" . $PRIVATE_PERSON_VALUE . "' ON DUPLICATE KEY UPDATE `NAME`='PRIVATE_PERSON', `VALUE`='" . $PRIVATE_PERSON_VALUE . "';" 

Who sent to the database and everything works. Why is another request in the regular bitrix function? I wrote a request to bitrix, maybe I will add more.

  • This is very similar to a crutch, and it is rather dirty, which can then go sideways. You have this problem in Bitrix as a bug? - Andrewus

Here is the answer to the question:

 \Bitrix\Main\EventManager::getInstance()-> addEventHandler("sale", "OnSaleOrderBeforeSaved", "OnSHandler"); function OnSHandler(Bitrix\Main\Event $event) { $order = $event->getParameter("ENTITY"); $propertyCollection = $order->getPropertyCollection(); foreach ($propertyCollection->getGroups() as $group) { foreach ($propertyCollection->getGroupProperties($group['ID']) as $property) { $p = $property->getProperty(); if (15 == $p["ID"]) { $family = $property->getField("VALUE"); } if (19 == $p["ID"]) { $name = $property->getField("VALUE"); } if ("PRIVATE_PERSON" == $p["CODE"]) { $property->setValue($name . ' ' . $family); } } } } 

I publish with the purpose of CodeReview. Support answered:

QUOTATION You do not need to write to the database in this event. You just need to take the collection of the properties of the $ order object and add your own data to it, or modify the existing ones. The system itself will then save everything to the database:

$ propertyCollection = $ order-> getPropertyCollection ();

$ propertyCollection = $ order-> getPropertyCollection ();

foreach ($ propertyCollection-> getGroups () as $ group) {

foreach ($ propertyCollection-> getGroupProperties ($ group ['ID']) as $ property) {

$ p = $ property-> getProperty (); if ($ p ["CODE"] == "CONTACT_PERSON") $ property-> setValue ("VASYA");

}}

Sincerely, Leading Specialist of the Technical Support Department Shestopalov Lev

In doing so, we used the OnSaleOrderBeforeSaved event.

To finish it helped me:

https://mrcappuccino.ru/blog/post/work-with-basket-bitrix-d7

    But what about PHP7. You write in black and white: violation of the uniqueness of the key IX_SOPV_ORD_PROP_UNI. It does not depend on the version of PHP in any way. It looks like there is some kind of trigger triggered by updating this table. You need to deal with this ... Perhaps something is wrong with you updated with a serious update or wherever you turn to the database, bypassing the API and there is something nkosyachili.

    • Everything would be cool if it were not for an update. - Basil Jimmy
    • I need an example of adding an event to add to the basket, and not advice from the series, something there violates the key's uniqueness. Apparently I break it. The question is why? - Basil Jimmy
    • Then this error can be ignored - Basil Jimmy
    • So what? The update is one table - it pulls for a change in another, and there is a violation of integrity. "Why" should look at the data in your database. Find which table this index belongs to. Think about how they are interrelated with the one that updates and already on the basis of the information received to draw a further conclusion. Here is an example dev.1c-bitrix.ru/api_d7/bitrix/sale/events/sale_entitysaved.php , but you probably saw it .... Understand why there is a violation of integrity - solve your problem ... - Vorobyev Alexander