flamix / commerceml
此软件包最新版本(dev-main)没有可用的许可信息。
Flamix软件包用于使用CommerceML
dev-main
2023-02-06 13:54 UTC
Requires
- php: >=7.4
- ext-json: *
- flamix/plugin-helpers: dev-main
This package is auto-updated.
Last update: 2024-09-06 17:06:26 UTC
README
关于
此软件包旨在集成FLAMIX的产品同步应用。该软件包使用简化和改进的CommerceML交换协议。
同步哲学
- 添加、编辑、解析和删除产品、目录和字段仅在站点上执行;
- Bitrix24同步目录结构和产品与字段;
- Bitrix24同步产品库存和价格到网站;
警告!Bitrix24不会上传目录和产品到网站。
概念指南
我们使用CommerceML标准,但为了简化交换并符合我们的同步哲学,采用了以下逻辑概念
- 主要语言 - 英语(在有些地方翻译成俄语以保持向后兼容);
- 同步分步骤进行,每次30个产品;
- 导入后,导入文件将自动删除;
- 所有数据都通过zip进行压缩;
- 如果需要停止操作,请使用
throw new \Exception('您的消息');
API和操作
库存API和同步操作 - https://inventory.app.flamix.solutions/docs
可以作为Postman收集或OpenAPI规范导入和使用。
安装和使用
composer require flamix/commerceml
创建新类
<?php /** * Redefining how the plugin works * If something is not clear, see how it is done in the parent class Flamix\CommerceML\Init */ namespace My\CMS; use Flamix\CommerceML\Init; class Exchange extends Init { /** * CALLBACKS * * Called on export * The export action calls these callbacks to get arrays of properties to be wrapped in xml * @axample public static function get(int $page, array $params = []): array * Note! Every callback must return EXTERNAL_ID as ID, and automatically create it, if it's empty or non exist * Note! $page will be passed automatically */ protected static string $product_callback = '\Exchange\Woo\Products'; protected static string $category_callback = '\Exchange\Woo\Categories'; protected static string $attribute_callback = '\Exchange\Woo\Attributes'; /** * ACTIONS * * If you need to override the behavior of a standard action * For example, it is almost always necessary to override the authorization action behaviors */ public static function actionCheck() { if (Setting::getOption('lead_domain') !== ($_SERVER['PHP_AUTH_USER'] ?? '')) throw new \Exception('Bad login!'); if (Setting::getOption('lead_api') !== ($_SERVER['PHP_AUTH_PW'] ?? '')) throw new \Exception('Bad password!'); // If OK - Print our session_id return CheckAuth::printPhpSession(); } /****************** | HANDLERS | *******************/ /** * HANDLERS (restsHandler, pricesHandler and productsHandler) * * Called on import * If you need to override the behavior of a standard action * For example, it is almost always necessary to override the authorization action behaviors */ public static function restsHandler($product_id, array $rests): bool { $woo_id = Products::getProductBy('EXTERNAL_ID', $product_id); commerceml_log('[restsHandler] Product ' . (($woo_id) ? 'founded with WooCommerce product ID ' . $woo_id : 'not found') . ' by EXTERNAL_ID: ' . $product_id, $rests); if (!$woo_id) return false; $general_quantity = array_sum(array_column($rests, 'quantity')); commerceml_log('[restsHandler] General quantity by all warehouses ' . $general_quantity); if (!$general_quantity) return false; // dd($woo_id, $general_quantity, $rests); return Products::set($woo_id, ['quantity' => $general_quantity]); } }
初始化同步
// Init main settings and include helpers \Flamix\Sync\Init::init(__DIR__); // Start exchange // \My\CMS\Exchange replace to your class if (($_GET['flamix_product'] ?? false) === 'Y') \My\CMS\Exchange::start();