Пример #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);
 }
Пример #2
0
 protected static function getOrderInfo($orderId)
 {
     // order itself
     $order = \CSaleOrder::getById($orderId);
     // buyer info
     $siteUserId = $order['USER_ID'];
     $phone = '';
     $email = '';
     $result = \CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $orderId));
     while ($row = $result->fetch()) {
         if (empty($phone) && stripos($row['CODE'], 'PHONE') !== false) {
             $stPhone = static::normalizePhoneNumber($row['VALUE']);
             if (!empty($stPhone)) {
                 $phone = sha1($stPhone);
             }
         }
         if (empty($email) && stripos($row['CODE'], 'EMAIL') !== false) {
             if (!empty($row['VALUE'])) {
                 $email = sha1($row['VALUE']);
             }
         }
     }
     // products info
     $products = array();
     $result = \CSaleBasket::getList(array(), $arFilter = array('ORDER_ID' => $orderId, 'MODULE' => 'catalog'), false, false, array('PRODUCT_ID', 'RECOMMENDATION', 'QUANTITY', 'PRICE', 'CURRENCY'));
     while ($row = $result->fetch()) {
         $productInfo = \CCatalogSKU::GetProductInfo($row['PRODUCT_ID']);
         $iblockId = 0;
         if (!empty($productInfo['ID'])) {
             $realProductId = $productInfo['ID'];
             $iblockId = $productInfo['IBLOCK_ID'];
         } else {
             $realProductId = $row['PRODUCT_ID'];
             // get iblock id
             $element = \Bitrix\Iblock\ElementTable::getRow(array('select' => array('IBLOCK_ID'), 'filter' => array('=ID' => $realProductId)));
             if (!empty($element)) {
                 $iblockId = $element['IBLOCK_ID'];
             }
         }
         $products[] = array('product_id' => $realProductId, 'iblock_id' => $iblockId, 'quantity' => $row['QUANTITY'], 'price' => $row['PRICE'], 'currency' => $row['CURRENCY'], 'recommendation' => $row['RECOMMENDATION']);
     }
     // all together
     $data = array('order_id' => $orderId, 'user_id' => $siteUserId, 'phone' => $phone, 'email' => $email, 'products' => $products, 'price' => $order['PRICE'], 'currency' => $order['CURRENCY']);
     return $data;
 }
Пример #3
0
 static function getByPropCode($code)
 {
     if (strpos($code, self::PREFIX) !== false)
     {
         $id = str_replace(self::PREFIX, '', $code);
         $params = array(
             'select' => array(
                 'ELEMENT_XML_ID' => 'XML_ID',
                 'ELEMENT_NAME'   => 'NAME',
                 'SECTION_NAME'   => 'SECTION.NAME',
                 'SECTION_XML_ID' => 'SECTION.XML_ID'
             ),
             'filter' => array(
                 '=ID' => $id
             ),
             'runtime' => array(
                 new ReferenceField(
                     'SECTION',
                     '\Bitrix\Iblock\SectionTable',
                     array('=this.IBLOCK_SECTION_ID' => 'ref.ID'),
                     array('join_type' => 'LEFT')
                 )
             )
         );
         return ElementTable::getRow($params);
     }
     return '';
 }
Пример #4
0
    private function importElement($arItems, $IBLOCK_ID = 0, $event = 'element')
    {
        if (!$IBLOCK_ID)
        {
            $IBLOCK_ID = $this->CATALOG_ID;
        }
        $arResult = array();
        $arOffers = array();

        $el = new \CIBlockElement;
        foreach ($arItems as $arItem)
        {
            if (!strlen($arItem['XML_ID']))
            {
                throw new \Exception('Empty element XML ID '.$arItem['name']);
            }
            $boolUpdate = true;

            if (!strlen($arItem['CODE']))
            {
                $arItem['CODE'] = \CUtil::translit($arItem['NAME'], 'ru', array(
                    "replace_space" => '-',
                    "replace_other" => '-'
                ));
            }
            $arLoadProduct = array(
                'ACTIVE'      => $arItem['ACTIVE'],
                'XML_ID'      => $arItem['XML_ID'],
                'NAME'        => $arItem['NAME'],
                'CODE'        => $arItem['CODE'],
                'DETAIL_TEXT' => $arItem['DESCRIPTION'],
            );
            $params = array(
                'select' => array('ID', 'ACTIVE'),
                'filter' => array(
                    '=IBLOCK_ID' => $IBLOCK_ID,
                    '=XML_ID'    => $arItem['XML_ID']
                )
            );
            $arElem = ElementTable::getRow($params);
            if ($arElem['ID'] > 0)
            {
                $boolUpdate = !App::compareHash($arItem);
                if ($boolUpdate || $arItem['ACTIVE'] !== $arElem['ACTIVE'])
                {
                    $el->Update($arElem['ID'], $arLoadProduct);
                    Report::update($event);
                }
            }
            else
            {
                $arSection = $this->getSectionByXML($arItem['SECTION_XML_ID'], $IBLOCK_ID);
                if (!$arSection['ID'])
                {
                    throw new \Exception('Cant find section with XML ID: '.$arItem['SECTION_XML_ID']);
                }
                $arLoadProduct = array_merge($arLoadProduct, array(
                    'IBLOCK_SECTION_ID' => $arSection['ID'],
                    'IBLOCK_ID'         => $IBLOCK_ID
                ));
                $arElem['ID'] = $el->Add($arLoadProduct);

                App::compareHash($arItem);
                Report::create($event);
            }

            // если элемент не нашли и не создали, выплюнем эксепшен
            if (!$arElem['ID'])
            {
                throw new \Exception('Cant create element');
            }
            $arResult[$arItem['XML_ID']] = $arElem['ID'];

            if ($boolUpdate)
            {
                $arCatalogProduct = array(
                    "ID"     => $arElem['ID'],
                    "WEIGHT" => $arItem['WEIGHT']
                );
                \CCatalogProduct::Add($arCatalogProduct);                      // добавим элемент в каталог
                \CPrice::SetBasePrice($arElem['ID'], $arItem['PRICE'], "RUB"); // установим базовую цену

                $arOfferProp = array();
                if (!empty($arItem['MODIFIERS']))
                {
                    foreach ($arItem['MODIFIERS'] as $arMod)
                    {
                        $arOfferProp[] = array(
                            'XML_ID'       => $this->defaultSectionID,
                            'VALUE_XML_ID' => $arMod['XML_ID'],
                            'REQUIRED'     => $arMod['REQUIRED']
                        );
                    }
                }
                if (!empty($arItem['GROUP_MODIFIERS'])) // тут то же самое, только нужно создать ТП из всего свойства, а не из конкретного значения
                {
                    foreach ($arItem['GROUP_MODIFIERS'] as $arMod)
                    {
                        $arOfferProp[] = array(
                            'XML_ID'       => $arMod['XML_ID'],
                            'VALUE_XML_ID' => '',
                            'REQUIRED'     => $arMod['REQUIRED']
                        );
                    }
                }

                if (!empty($arOfferProp))
                {
                    $arOffers[] = array(
                        'ID'     => $arElem['ID'],
                        'NAME'   => $arItem['NAME'],
                        'OFFERS' => $arOfferProp
                    );
                }
            }
        }

        if (!empty($arOffers)) // импорт ТП
        {
            $this->importOffers($arOffers);
        }

        return $arResult;
    }