sv1ft / exchange1c
1c - CommerceML 协议的目录加载器
1.3.5
2023-03-25 09:07 UTC
Requires
- php: >=7.1
- ext-simplexml: *
- carono/commerceml: ^0.2.3
Requires (Dev)
- illuminate/session: ^5.7
- phpunit/phpunit: ^7
- symfony/event-dispatcher: ^4.1
- symfony/http-foundation: ^4.1
README
安装此库应简化将1C集成到您网站的过程。
该库包含一组必须实现的接口,以获取与1C交换商品和文件的能力。假设您拥有1C:Предприятие 8, Управление торговлей", 版本11.3.2,在8.3.9.2033平台上。
如果您配置的版本更低,则该库仍然可能工作,因为1C从版本到版本与网站交换的很大一部分并没有太大变化。
该库是在模块 https://github.com/carono/yii2-1c-exchange 的基础上编写的 - 所有主要接口都来自该模块。
依赖关系
- php ^7.1
- carono/commerceml
- symfony/http-foundation ^4.1
安装
composer require Sv1fT/exchange1c
使用
为了使用此库,您需要定义配置数组并在您的模型中实现接口。示例中使用了 symfony/event-dispatcher 的适配器 - https://github.com/Sv1fT/exchange1c-symfony-bridge 您还可以使用用于集成Laravel的包适配器 - https://github.com/Sv1fT/laravel-exchange1c
require_once './../vendor/autoload.php'; //Подулючаем автолоад // Определяем конфиг $configValues = [ 'import_dir' => '1c_exchange', 'login' => 'admin', 'password' => 'admin', 'use_zip' => false, 'file_part' => 0, 'models' => [ \Sv1fT\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, \Sv1fT\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, \Sv1fT\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, ], ]; $config = new \Sv1fT\Exchange1C\Config($configValues); $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); $symfonyDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher = new \Sv1fT\Exchange1C\SymfonyEventDispatcher($symfonyDispatcher); $modelBuilder = new \Sv1fT\Exchange1C\ModelBuilder(); // Создаем необходимые сервисы $loaderService = new \Sv1fT\Exchange1C\Services\FileLoaderService($request, $config); $authService = new \Sv1fT\Exchange1C\Services\AuthService($request, $config); $categoryService = new \Sv1fT\Exchange1C\Services\CategoryService($request, $config, $dispatcher, $modelBuilder); $offerService = new \Sv1fT\Exchange1C\Services\OfferService($request, $config, $dispatcher, $modelBuilder); $catalogService = new \Sv1fT\Exchange1C\Services\CatalogService($request, $config, $authService, $loaderService, $categoryService, $offerService); $mode = $request->get('mode'); $type = $request->get('type'); try { if ($type == 'catalog') { if (!method_exists($catalogService, $mode)) { throw new Exception('not correct request, mode=' . $mode); } //Запускаем сервис импорта каталога $body = $catalogService->$mode(); $response = new \Symfony\Component\HttpFoundation\Response($body, 200, ['Content-Type', 'text/plain']); $response->send(); } else { throw new \LogicException(sprintf('Logic for method %s not released', $type)); } } catch (\Exception $e) { $body = "failure\n"; $body .= $e->getMessage() . "\n"; $body .= $e->getFile() . "\n"; $body .= $e->getLine() . "\n"; $response = new \Symfony\Component\HttpFoundation\Response($body, 500, ['Content-Type', 'text/plain']); $response->send(); }
有关接口及其实现的更详细信息,请参阅文档 https://github.com/carono/yii2-1c-exchange 文档将稍后补充。
许可证
本软件包是开源代码,采用MIT许可。