Ejemplo n.º 1
0
 public function setBasePrice($price, $currencyId = 'RUB')
 {
     if (!class_exists('\\CPrice')) {
         \CModule::IncludeModule('catalog');
     }
     return \CPrice::SetBasePrice($this->id, $price, $currencyId);
 }
Ejemplo n.º 2
0
     foreach($fields as $code => $field) {
         if($_REQUEST[$code]) {
             $arUpdate[$code] = $_REQUEST[$code];
         }
     }  
     foreach ($props as $prop) {
         if($_REQUEST['props'][$prop["ID"]]) { 
             CIBlockElement::SetPropertyValuesEx($ID, $IBLOCK_ID, array($prop["ID"] => $_REQUEST['props'][$prop["ID"]]));
         } 
     } 
     if($bCatalog && $_REQUEST['base_price_multiplier'] && isset($_REQUEST['base_price_add']) ) {
                 $arr = CPrice::GetBasePrice($ID);
                 $price = $arr["PRICE"];  
                 $price = $price * $_REQUEST['base_price_multiplier']; 
                 $price = $price + $_REQUEST['base_price_add'];
                 CPrice::SetBasePrice($ID, $price, $arr["CURRENCY"]); 
             }
     if(count($arUpdate)) { 
         $el = new CIBlockElement;  
         $el->Update($ID, $arUpdate);
     }
     break;
 case "delete":
     if (CIBlockElementRights::UserHasRightTo($IBLOCK_ID, $ID, "element_delete")) {
         @set_time_limit(0);
         $DB->StartTransaction();
         $APPLICATION->ResetException();
         if (!CIBlockElement::Delete($ID)) {
             $DB->Rollback();
             if ($ex = $APPLICATION->GetException())
                 $lAdmin->AddGroupError(GetMessage("IBLOCK_DELETE_ERROR") . " [" . $ex->GetString() . "]", $ID);
Ejemplo n.º 3
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;
    }