예제 #1
0
파일: main.php 프로젝트: phwb/ugraweb.iiko
 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
// импортируем номенклатуру в наш каталог
try
{
    $strImportOKMessage .= \Iiko\Import::getInstance($CATALOG_ID, $arNomenclature)->catalog()->report();
    $strImportOKMessage .= str_replace("#TIME#", roundEx(getmicrotime() - $startImportExecTime, 2), "<br />Загрузка заняла <b>#TIME#</b> сек<br />");
}
catch (Exception $e)
{
    $strImportErrorMessage .= $e->getMessage()."\n";
}

// делаем экспорт в айку
try
{
    /** @var $provider \Iiko\IExportOrder */
    $provider = \Iiko\Config\Option::getProvider();
    if (!\Iiko\Export::getOrderProvider($provider))
    {
        $provider = '\Iiko\OrderProvider';
    }
    $arOrderIDs = $provider::getOrderIDs($SITE_ID);
    $strImportOKMessage .= \Iiko\Export::getInstance($arOrderIDs)->prepareOrders($REST_ID)->registerOrders($iikoCloud)->report();
}
catch (Exception $e)
{
    $strImportErrorMessage .= $e->getMessage()."\n";
}

gg($strImportOKMessage, 0, 'File: '.basename(__FILE__).', Line: '.__LINE__);
die();
예제 #3
0
    private function __construct($IBLOCK_ID, $params = array())
    {
        if (!isset($params['groups']) || !isset($params['products']))
        {
            throw new \Exception("Groups or Products not exist");
        }

        $rsCatalog = \CCatalog::GetList(array(), array('IBLOCK_ID' => intval($IBLOCK_ID)));
        if (!$arCatalog = $rsCatalog->Fetch())
        {
            throw new \Exception('Cant find catalog with ID = '.$IBLOCK_ID);
        }

        $this->CATALOG_ID = intval($arCatalog['IBLOCK_ID']);
        $this->OFFERS_ID = intval(Option::get('modifier_id'));

        if (!$this->OFFERS_ID)
        {
            // этот эксепшн можно заменить на создание инфоблока модификаторов
            throw new \Exception('Need set modifiers iblock');
        }

        $this->defaultSectionID = Option::getDefaultSectionID();
        $this->arModifiers[$this->defaultSectionID] = array(
            'XML_ID' => $this->defaultSectionID,
            'NAME'   => 'Другие модификаторы',
            'CODE'   => $this->defaultSectionID,
            'ACTIVE' => 'Y'
        );
        foreach ($params['groups'] as $arItem)
        {
            $arInfo = json_decode($arItem['additionalInfo'], true);
            $arGroup = array(
                "XML_ID"         => $arItem['id'],
                "SECTION_XML_ID" => $arItem['parentGroup'],
                "NAME"           => $arItem['name'],
                "CODE"           => $arInfo['CODE'],
                "ACTIVE"         => $arInfo['ACTIVE'] === 'N' ? 'N' : 'Y'
            );
            // группа модификаторов
            if (!$arItem['isIncludedInMenu'])
            {
                $this->arModifiers[$arItem['id']] = $arGroup;
                continue;
            }
            // обычная группа
            $this->arGroups[] = $arGroup;
        }

        foreach ($params['products'] as $arItem)
        {
            $arElement = array(
                'ACTIVE'         => 'Y',
                'XML_ID'         => $arItem['id'],
                'NAME'           => $arItem['name'],
                'CODE'           => $arItem['code'],
                'TYPE'           => strtoupper($arItem['type']),
                'DESCRIPTION'    => $arItem['description'],
                'SECTION_XML_ID' => $arItem['parentGroup'],
                'PRICE'          => doubleval($arItem['price']),
                'WEIGHT'         => $arItem['weight'] * 1000
            );
            if ($arItem['type'] === 'modifier')
            {
                $arElement['SECTION_XML_ID'] = $key = strlen($arItem['groupId']) > 0 ? $arItem['groupId'] : $this->defaultSectionID;
                $this->arModifiers[$key]['ITEMS'][] = $arElement;
                continue;
            }
            $arElement = array_merge($arElement, array(
                'MODIFIERS'       => array(),
                'GROUP_MODIFIERS' => array()
            ));
            if (!empty($arItem['modifiers'])) // обычные модификаторы
            {
                foreach ($arItem['modifiers'] as $arModifier)
                {
                    $arElement['MODIFIERS'][] = array(
                        'XML_ID'   => $arModifier['modifierId'],
                        'REQUIRED' => intval($arModifier['required']) > 0 ? 'Y' : 'N'
                    );
                }
            }
            if (!empty($arItem['groupModifiers'])) // групповые модификаторы
            {
                foreach ($arItem['groupModifiers'] as $arModifier)
                {
                    $arElement['GROUP_MODIFIERS'][] = array(
                        'XML_ID'   => $arModifier['modifierId'],
                        'REQUIRED' => intval($arModifier['required']) > 0 ? 'Y' : 'N'
                    );
                }
            }
            $this->arProducts[] = $arElement;
        }

        $iblockFields = \CIBlock::GetFields($this->CATALOG_ID);
        $iblockFields["XML_IMPORT_START_TIME"] = array(
            "NAME"          => "XML_IMPORT_START_TIME",
            "IS_REQUIRED"   => "N",
            "DEFAULT_VALUE" => date("Y-m-d H:i:s"),
        );
        \CIBlock::SetFields($this->CATALOG_ID, $iblockFields);
    }
예제 #4
0
    function sendRequest($method, $params = array(), $checkToken = true, $isPOST = false)
    {
        if ($checkToken)
        {
            if ($this->token == '')
            {
                $this->setToken();
            }
            $params['access_token'] = $this->token;
        }

        $_prefix = Option::getPrefix();
        $_url = Option::getURL();

        $combinedURL = $_url.$_prefix.$method;

        if ($isPOST)
        {
            return $this->curl_post($combinedURL, json_encode($params));
        }
        else
        {
            return $this->curl_get($combinedURL, $params);
        }
    }
예제 #5
0
    /**
     * @param $rest_id
     * @return $this
     */
    function prepareOrders($rest_id)
    {
        $selfDeliveryID = Config\Option::getSelfDeliveryID();
        $defaultSectionID = Config\Option::getDefaultSectionID();

        gg($this->arOrderIDs, 0, 'File: '.basename(__FILE__).', Line: '.__LINE__);
        foreach ($this->arOrderIDs as $orderID)
        {
            // выбираем свойства заказа
            $arOrderProp = array();
            $rsProps = \CSaleOrderPropsValue::GetList(
                array("SORT" => "ASC"),
                array("ORDER_ID" => $orderID)
            );
            while ($arProp = $rsProps->Fetch())
            {
                $arOrderProp[$arProp['ORDER_PROPS_ID']] = $arProp;
            }

            // свойства Пользователя по умолчанию
            $arCustomer = $this->fillProps(Config\Props::getInstance()->getCustomerList(), $arOrderProp);
            $customer = new Customer($arCustomer);

            // свойства Адреса по умолчанию
            $arAddress = $this->fillProps(Config\Props::getInstance()->getAddressList(), $arOrderProp);
            $address = new Address($arAddress);

            // содержимое заказа
            $arBasketItems = $this->getBasketItems($orderID);
            $arItems = array();
            foreach ($arBasketItems as $arBasketItem)
            {
                $modifiers = array();
                foreach ($arBasketItem['PROPS'] as $arModifier)
                {
                    $params = array(
                        'id' => $arModifier['ELEMENT_XML_ID'],
                        'name' => $arModifier['ELEMENT_NAME'],
                    );
                    $modifier = new Item($params);
                    if ($arModifier['SECTION_XML_ID'] !== $defaultSectionID)
                    {
                        $modifier->set('groupId', $arModifier['SECTION_XML_ID']);
                        $modifier->set('groupName', $arModifier['SECTION_NAME']);
                    }
                    $modifiers[] = $modifier->toArray();
                }

                $params = array(
                    'id' => $arBasketItem['XML_ID'],
                    'name' => $arBasketItem['NAME'],
                    'amount' => doubleval($arBasketItem['QUANTITY'])
                );
                $item = new Item($params);
                if (!empty($modifiers))
                {
                    $item->set('modifiers', $modifiers);
                }
                $arItems[] = $item->toArray();
            }

            $params = array(
                'select' => array('DATE_INSERT', 'COMMENTS', 'DELIVERY_ID'),
                'filter' => array(
                    '=ID' => $orderID
                )
            );
            $arOrder = OrderTable::getRow($params);

            // собственно сам заказ
            $order = new Order($address, $customer);
            $order->set('externalId', $orderID);
            $order->set('date', date('Y-m-d H:i:s', $arOrder['DATE_INSERT']->getTimestamp() + 60 * 60));
            $order->set('comment', $arOrder['COMMENTS']);
            $order->set('isSelfService', $arOrder['DELIVERY_ID'] == $selfDeliveryID);
            $order->set('items', $arItems);

            $this->orders[] = new OrderRequest($customer, $order, $rest_id);
        }
        return $this;
    }