Example #1
0
 function onIBlockElementDelete($id)
 {
     $modifier_id = intval(Option::get('modifier_id'));
     $params = array(
         'select' => array('IBLOCK_ID'),
         'filter' => array(
             '=ID' => $id
         )
     );
     $arElement = ElementTable::getRow($params);
     if (intval($arElement['IBLOCK_ID']) !== $modifier_id)
     {
         return ElementModifiers::delete($id);
     }
     return Modifiers::delete($id);
 }
Example #2
0
        'runtime' => array(
            new \Bitrix\Main\Entity\ReferenceField(
                'ELEMENT',
                '\Bitrix\Iblock\ElementTable',
                array('=this.ELEMENT_ID' => 'ref.ID'),
                array('join_type' => 'LEFT')
            ),
            new \Bitrix\Main\Entity\ReferenceField(
                'SECTION',
                '\Bitrix\Iblock\SectionTable',
                array('=this.SECTION_ID' => 'ref.ID'),
                array('join_type' => 'LEFT')
            )
        )
    );
    $arElements = \Iiko\Modifiers::getList($params)->fetchAll();

    // разбиваем элементы по разделам
    foreach ($arElements as $arElem)
    {
        $sectionID = $arElem['SECTION_ID'];
        if (!isset($arModifiers[$sectionID]))
        {
            $arModifiers[$sectionID] = array(
                'ID'   => $arElem['SECTION_ID'],
                'NAME' => $arElem['SECTION_NAME']
            );
        }
        $arModifiers[$sectionID]['ITEMS'][] = $arElem;
    }
}
Example #3
0
    private function importModifiers($arModifiers = array())
    {
        $arElements = array();
        $arSections = array();
        foreach ($arModifiers as $arSection)
        {
            $arElements = array_merge($arElements, $arSection['ITEMS']);
            unset($arSection['ITEMS']);
            $arSections[] = $arSection;
        }
        $this->importSection($arSections, $this->OFFERS_ID, 'mod_section');
        $arIDs = $this->importElement($arElements, $this->OFFERS_ID, 'mod_elem');

        // добавим модификаторы в БД
        foreach ($arElements as $arElement)
        {
            Modifiers::add($arIDs[$arElement['XML_ID']], array(
                'NAME'       => $arElement['NAME'],
                'PRICE'      => $arElement['PRICE'],
                'WEIGHT'     => $arElement['WEIGHT']
            ));
        }
    }