403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/php_interface/wbs24.lib/lib/ApiXml/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/php_interface/wbs24.lib/lib/ApiXml/FlowWow.php
<?php

namespace Wbs24\Lib\ApiXml;

use Bitrix\Main\Loader;
use Bitrix\Main\Config\Option;
use Bitrix\Catalog\CatalogIblockTable;
use Bitrix\Iblock\IblockTable;
use Bitrix\Iblock\SectionTable;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Catalog\CPrice;

class FlowWow {

    protected $settings;


    public function __construct($settings)
    {
        $this->settings = $settings;
    }

    public function launchApi()
    {
        $res = $this->updateProducts();
        //print_r($this->getProducts());
    }
    protected function updateProducts()
    {
        $responseProduct = $this->mergeArray();
        $products = $responseProduct['result'];

        if (!$responseProduct['success']) return 'is not success query';

        $this->createXml();

        return 'success';
    }

    protected function mergeArray()
    {
        $responseProducts = $this->getProducts();

        return $responseProducts;
    }

    protected function getProducts()
    {

        Loader::includeModule('catalog');
        Loader::includeModule('iblock');

        // Идентификатор инфоблока каталога
        $catalogIblockId = Option::get('catalog', 'aspro_next_catalog');

        // Получение информации о каталоге
        $catalog = CatalogIblockTable::getList([
            'filter' => ['=IBLOCK_ID' => $catalogIblockId]
        ])->fetch();

        // Получение свойств инфоблока
        $properties = PropertyTable::getList([
            'filter' => ['=IBLOCK_ID' => $catalogIblockId]
        ])->fetchAll();

        // Формирование массива элементов для фида
        $items = [];

        // Цикл по товарам каталога
        $arSelect = Array("ID", "ACTIVE", "CATALOG_AVAILABLE", "NAME", "DETAIL_PAGE_URL", "SECTION_ID", "DETAIL_TEXT", "DETAIL_PICTURE", "PROPERTY_*");
        $arFilter = Array("IBLOCK_ID" => $catalogIblockId, "ACTIVE"=>"Y", "SECTION_ID" => 880);
        $res = \CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
        while($ob = $res->GetNextElement()) {
            $arFields = $ob->GetFields();
            $arProps = $ob->GetProperties();
            
            $item = [
                'ID' => $arFields['ID'],
                'ACTIVE' => $arFields['ACTIVE'],
                'CATALOG_AVAILABLE' => $arFields['CATALOG_AVAILABLE'],
                'NAME' => $arFields['~NAME'],
                'DETAIL_PAGE_URL' => $arFields['DETAIL_PAGE_URL'],
                'IBLOCK_SECTION_ID' => $arFields['IBLOCK_SECTION_ID'],
                'DETAIL_TEXT' => $arFields['DETAIL_TEXT'],
                'DETAIL_PICTURE' => $arFields['DETAIL_PICTURE'],
                'CATALOG_QUANTITY' => $arFields['CATALOG_QUANTITY'],
                'PROPS' => []
            ];

            foreach ($arProps as $property) {
                $item['PROPS'][$property['CODE']] = $property['VALUE'];
            }
            if(!!$item['PROPS']['FLOWER_COUNT']) {
                $items[] = $item;
            }

        }
        
        $responseProduct = [
            'result' => $items,
            'success' =>  !empty($items) ? 'success' : 'is not success query'
        ];

        return $responseProduct; //product array
    }

    protected function getCategories() {

        Loader::includeModule('iblock');

        $iblockId = 18;

        $sections = SectionTable::getList([
            'filter' => ['IBLOCK_ID' => $iblockId, 'ID' => 880],
            'select' => ['ID', 'NAME', 'IBLOCK_SECTION_ID'],
        ])->fetchAll();

        $categories = array();

        foreach ($sections as $section) {

            $categories[] = $section;
        }

        return $categories;
    }

    protected function getPrice($id, $sale = 1.2) {

        Loader::includeModule('catalog');

        $price_result = \CPrice::GetList(
            array(),
            array(
            "PRODUCT_ID" => $id,
            "BASE" => 'Y',
            )
            );
            while ($arPrices = $price_result->Fetch())
            {
                $myPricesa[] = $arPrices["PRICE"];
            }

            $myPrice = (float)$myPricesa[0] * (float)$sale;
			var_dump($myPricesa);
            var_dump($sale);
            var_dump($myPrice);
            return $myPrice;
    }

    protected function getProductImage($id) {
        Loader::includeModule('main');

        $imagePath = \CFile::GetPath($id);

        return $imagePath;
    }

    protected function getFlowerName($id) {

        Loader::includeModule('highloadblock');

        $hlblock = \Bitrix\Highloadblock\HighloadBlockTable::getList(
            array("filter" => array(
                'TABLE_NAME' => 'b_hlbd_tsvety'
            )))->fetch();

        if (isset($hlblock['ID']))
        {
            $entity = \Bitrix\Highloadblock\HighloadBlockTable::compileEntity($hlblock);
            $entity_data_class = $entity->getDataClass();
            $res = $entity_data_class::getList( array('filter'=>array( 'UF_XML_ID' => $id)) );
            if ($item = $res->fetch())
            {
                $flowerName = $item['UF_NAME'];
            }
        }

        return $flowerName;
    }

    protected function createXml()
    {
        $path = '/upload/flowwow_export.xml';
        $baseFileName = $this->settings['ourPath']. $path;

        file_put_contents($baseFileName, '');

        $xml = new \DOMDocument('1.0', 'utf-8');
        $xml->encoding = 'utf-8';

        $this->addToFile('<?xml version="1.0" encoding="utf-8"?>');

        $catalog = $xml->appendChild($xml->createElement('yml_catalog'));
        $catalog->setAttribute('date', date("Y.m.d H:i:s"));

        $shop = $catalog->appendChild($xml->createElement('shop'));

        $shop->appendChild($xml->createElement('name', $this->settings['name']));
        $shop->appendChild($xml->createElement('company', $this->settings['company']));
        $shop->appendChild($xml->createElement('url', $this->settings['ourUrl']));
        $shop->appendChild($xml->createElement('platform', '1C-Bitrix'));

        $currencies = $shop->appendChild($xml->createElement('currencies'));

        $currency = $currencies->appendChild($xml->createElement('currency'));
        $currency->setAttribute('id', 'RUR');
        $currency->setAttribute('rate', '1');

        $categories = $shop->appendChild($xml->createElement('categories'));

        $catList = $this->getCategories();
        foreach($catList as $cat) {
            $category = $categories->appendChild($xml->createElement('category', $cat['NAME']));
            $category->setAttribute('id', $cat['ID']);
            if($cat['IBLOCK_SECTION_ID'] != NULL) {
                $category->setAttribute('parentId', $cat['IBLOCK_SECTION_ID']);
            }
        }

        $offers = $shop->appendChild($xml->createElement('offers'));

        $products = $this->getProducts();

        foreach($products['result'] as $product) {
            $offer = $offers->appendChild($xml->createElement('offer'));
            $offer->setAttribute('id', $product['ID']);
            $offer->setAttribute('available', $product['CATALOG_AVAILABLE'] == 'Y' ? 'true' : 'false');

            $offer->appendChild($xml->createElement('url', $this->settings['ourUrl'] . $product["DETAIL_PAGE_URL"]));
            $offer->appendChild($xml->createElement('price', $this->getPrice($product['ID'], $product['PROPS']["WOWLOW_SALE"])));
            $offer->appendChild($xml->createElement('currencyId', 'RUR'));
            $offer->appendChild($xml->createElement('categoryId', $product["IBLOCK_SECTION_ID"]));
            $offer->appendChild($xml->createElement('picture', $this->settings['ourUrl'] . $this->getProductImage($product["DETAIL_PICTURE"])));

            foreach($product["PROPS"]["MORE_PHOTO"] as $photo) {
                $offer->appendChild($xml->createElement('picture', $this->settings['ourUrl'] . $this->getProductImage($photo)));
            }

            $offer->appendChild($xml->createElement('name', htmlspecialchars($product["NAME"], ENT_XML1, 'UTF-8')));
            $offer->appendChild($xml->createElement('description', htmlspecialchars($product["DETAIL_TEXT"], ENT_XML1, 'UTF-8')));

            if($product["PROPS"]["WIDTH_CM"] != '') {
                $width = $offer->appendChild($xml->createElement('params', $product["PROPS"]["WIDTH_CM"]));
                $width->setAttribute('name', 'Ширина, См');
			}

            if($product["PROPS"]["HEIGHT_CM"] != '') {
                $height = $offer->appendChild($xml->createElement('params', $product["PROPS"]["HEIGHT_CM"]));
                $height->setAttribute('name', 'Высота, См');
            }

            if($product["PROPS"]["LENGTH_CM"] != '') {
                $lenght = $offer->appendChild($xml->createElement('params', $product["PROPS"]["LENGTH_CM"]));
                $lenght->setAttribute('name', 'Длина, См');
            }

            $flowers = $product["PROPS"]["FLOWER"];
            $flowersCount = $product["PROPS"]["FLOWER_COUNT"];

            if(count((array)$flowers) >= 0) {
                foreach($flowers as $index => $flower) {
					if ($flowersCount[$index] > 0) {
						$flow = $offer->appendChild($xml->createElement('consist', $flowersCount[$index]));
                    	$flow->setAttribute('name', $this->getFlowerName($flower));
                    	$flow->setAttribute('unit', 'шт');
					}
                }
			} 
        }

       $feed = $xml->saveHTML($xml->documentElement);

       $feed = str_replace('&nbsp', ' ', $feed);
       $feed = str_replace('params', 'param', $feed);

       $this->addToFile($feed);


    }

    protected function addToFile($xml)
    {
        $path = '/upload/flowwow_export.xml';
        $baseFileName = $this->settings['ourPath']. $path;

        file_put_contents($baseFileName, $xml, FILE_APPEND);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit