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/modules/sproduction.datasync/lib/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/sproduction.datasync/lib/portalprices.php
<?php
/**
 * Synchronization of products
 *
 * @mail support@s-production.online
 * @link s-production.online
 */

namespace SProduction\Datasync;

\Bitrix\Main\Loader::includeModule("catalog");

use Bitrix\Main,
	Bitrix\Main\Entity,
	Bitrix\Main\Type,
	Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);


class PortalPrices
{
	public static function getTypes() {
		$list = [];
		$res = Rest::execute('catalog.priceType.list');
		if (isset($res['priceTypes'])) {
			foreach ($res['priceTypes'] as $type) {
				$list[$type['id']] = [
					'id' => $type['id'],
					'name' => $type['name'],
				];
			}
		}
		return $list;
	}

	/**
	 *
	 *
	 * @param $store_product_id
	 *
	 * @return array
	 */
	public static function getCrmPricesFromStore($store_product_id) {
		$prices = [];
		$store_product = StoreProducts::getById($store_product_id);
		$store_prod_prices = $store_product['prices'];
		$ct = SettingsIblocksMain::getPricesCT();
		foreach ($ct as $store_type => $crm_type) {
			if (isset($store_prod_prices[$store_type])) {
				$prices[$crm_type] = [
					'value' => $store_prod_prices[$store_type]['PRICE'],
					'currency' => $store_prod_prices[$store_type]['CURRENCY'],
				];
			}
		}
		return $prices;
	}

	public static function modify(int $crm_product_id, array $new_prices) {
		$req_list = self::modifyReq($crm_product_id, $new_prices);
		FileLog::put('(PortalPrices::modify) req_list ' . print_r($req_list, true));
		$resp = Rest::batch($req_list);
		return $resp[Rest::BATCH_RESP_RESULT]['price'] ?? false;
	}

	public static function modifyReq(int $crm_product_id, array $new_prices) {
		$req_list = [];
		$prices = self::getList($crm_product_id);
		foreach ($new_prices as $pt_id => $item) {
			if (isset($prices[$pt_id])) {
				$req_list[] = self::updateReq($prices[$pt_id]['id'], $item['value'], $item['currency']);
			}
			else {
				$req_list[] = self::addReq($crm_product_id, $pt_id, $item['value'], $item['currency']);
			}
		}
		return $req_list;
	}

	protected static function getList(int $product_id) {
		$list = [];
		$res = Rest::execute('catalog.price.list', [
			'filter' => [
				'productId' => $product_id,
			]
		]);
		if (isset($res['prices'])) {
			foreach ($res['prices'] as $price) {
				$list[$price['catalogGroupId']] = [
					'id' => $price['id'],
					'value' => $price['price'],
				];
			}
		}
		return $list;
	}

	protected static function addReq(int $product_id, $price_type, $value, $currency='RUB') {
		$req_params = [
			'method' => 'catalog.price.add',
			'params' => [
				'fields' => [
					'productId' => $product_id,
					'catalogGroupId' => $price_type,
					'price' => $value,
					'currency' => $currency,
				]
			]
		];
		return $req_params;
	}

	protected static function updateReq(int $price_id, $value, $currency='RUB') {
		$req_params = [
			'method' => 'catalog.price.update',
			'params' => [
				'id' => $price_id,
				'fields' => [
					'price' => $value,
					'currency' => $currency,
				]
			]
		];
		return $req_params;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit