Created
December 1, 2015 12:32
-
-
Save maximzasorin/a58034fbb3338b36a67c to your computer and use it in GitHub Desktop.
Наблюдатель, который устанавливает значение списочного свойства, равным названию группы товара (HostCMS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* В bootstrap.php: | |
// Установка значения свойства «Товары» равным названию группы товара | |
Core_Event::attach('shop_item.onAfterSave', array('Shop_Item_Observers_Updateshopitemtype', 'onAfterSave')); | |
* | |
*/ | |
defined('HOSTCMS') || exit('HostCMS: access denied.'); | |
class Shop_Item_Observers_Updateshopitemtype | |
{ | |
static public function onAfterSave($object, $args) | |
{ | |
$oProperty = Core_Entity::factory('Property', 305); // Свойство «Товары» | |
$aoProperty_Values = $oProperty->getValues($object->id, FALSE); | |
$oProperty_Value = isset($aoProperty_Values[0]) | |
? $aoProperty_Values[0] | |
: $oProperty->createNewValue($object->id); | |
$value = $object->Shop_Group->name; | |
$oList_Item = Core_Entity::factory('List', $oProperty->list_id) | |
->List_Items | |
->getByValue($value, FALSE); | |
if (is_null($oList_Item)) | |
{ | |
$oList_Item = Core_Entity::factory('List_Item') | |
->list_id($oProperty->list_id) | |
->value($value) | |
->save(); | |
} | |
$oProperty_Value->setValue($oList_Item->id); | |
$oProperty_Value->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment