diff --git a/backend/config/main.php b/backend/config/main.php index 48da3c9..0be9e74 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -51,6 +51,7 @@ 'viewPath' => '@artbox/webcomment/views/manage', ], 'export' => 'artbox\catalog\controllers\ExportController', + 'odoo' => 'artbox\odoo\controllers\OdooController', ], 'components' => [ 'assetManager' => [ diff --git a/common/config/bootstrap.php b/common/config/bootstrap.php index ed3315a..ec88b84 100755 --- a/common/config/bootstrap.php +++ b/common/config/bootstrap.php @@ -18,4 +18,7 @@ } if (!Yii::getAlias('@artbox/webcomment', false)) { Yii::setAlias('@artbox/webcomment', dirname(dirname(__DIR__)) . '/artweb/artbox-webcomment'); + } + if (!Yii::getAlias('@artbox/odoo', false)) { + Yii::setAlias('@artbox/odoo', dirname(dirname(__DIR__)) . '/artweb/artbox-odoo'); } \ No newline at end of file diff --git a/common/config/main.php b/common/config/main.php index 0f86266..f6f6089 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -2,6 +2,7 @@ use artbox\catalog\helpers\FilterHelper; use artbox\core\components\AliasCache; use artbox\core\components\SeoComponent; + use artbox\odoo\components\OdooMapper; return [ 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', @@ -56,6 +57,10 @@ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@eauth/messages', ], + 'odoo' => [ + 'class' => 'yii\i18n\PhpMessageSource', + 'basePath' => '@artbox/odoo/messages', + ], ], ], 'filedb' => [ @@ -83,5 +88,90 @@ 'aliasCache' => [ 'class' => AliasCache::className(), ], + 'odooMapper' => [ + 'class' => OdooMapper::className(), + 'map' => [ + 'id' => 'remote_id', + 'active' => 'status', + 'create_date' => [ + 'attribute' => 'created_at', + 'artbox' => function ($field) { + return strtotime($field); + }, + 'odoo' => function ($field) { + return date('Y-m-d H:i:s', $field); + }, + ], + '__last_update' => [ + 'attribute' => 'updated_at', + 'artbox' => function ($field) { + return strtotime($field); + }, + 'odoo' => function ($field) { + return date('Y-m-d H:i:s', $field); + }, + ], + 'name' => 'title', + 'default_code' => 'sku', + 'list_price' => 'price', + 'product_id' => [ + 'attribute' => 'variant_id', + 'artbox' => function ($field) { + return $field[ 0 ]; + }, + 'odoo' => function ($field) { + return [ $field ]; + }, + ], + 'price_unit' => 'price', + 'product_uom_qty' => 'count', + 'categ_id' => 'category', + 'contact_address' => [ + 'attribute' => 'address', + 'artbox' => function ($field) { + return strval($field); + }, + 'odoo' => function ($field) { + return boolval($field); + }, + ], + 'phone' => [ + 'attribute' => 'phone', + 'artbox' => function ($field) { + return strval($field); + }, + 'odoo' => function ($field) { + return boolval($field); + }, + ], + 'email' => [ + 'attribute' => 'email', + 'artbox' => function ($field) { + return strval($field); + }, + 'odoo' => function ($field) { + return boolval($field); + }, + ], + 'city' => [ + 'attribute' => 'city', + 'artbox' => function ($field) { + return strval($field); + }, + 'odoo' => function ($field) { + return boolval($field); + }, + ], + 'comment' => [ + 'attribute' => 'comment', + 'artbox' => function ($field) { + return strval($field); + }, + 'odoo' => function ($field) { + return boolval($field); + }, + ], + ], + ], ], ]; diff --git a/composer.json b/composer.json index 6716977..504e350 100755 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "kartik-v/yii2-widget-datepicker": "@dev", "nodge/yii2-eauth": "~2.0", "skeeks/yii2-assets-auto-compress": "*", - "zyx/zyx-phpmailer": "@stable" + "zyx/zyx-phpmailer": "@stable", + "darkaonline/ripcord": "*" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", @@ -79,7 +80,8 @@ "artbox\\core\\": "artweb/artbox-core/", "artbox\\catalog\\": "artweb/artbox-catalog/", "artbox\\order\\": "artweb/artbox-order/", - "artbox\\weblog\\": "artweb/artbox-weblog/" + "artbox\\weblog\\": "artweb/artbox-weblog/", + "artbox\\odoo\\": "artweb/artbox-odoo/" } } } diff --git a/composer.lock b/composer.lock index 77d6058..1a51834 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "f5d818fe2726a09810a6587656444937", + "content-hash": "a27711284fb6ee8108327ae9dff29060", "packages": [ { "name": "2amigos/yii2-tinymce-widget", @@ -605,6 +605,47 @@ "time": "2017-02-14T19:40:03+00:00" }, { + "name": "darkaonline/ripcord", + "version": "v0.1.4", + "source": { + "type": "git", + "url": "https://github.com/DarkaOnLine/Ripcord.git", + "reference": "b485483a931d68f0935933ad563e3a164e873df3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DarkaOnLine/Ripcord/zipball/b485483a931d68f0935933ad563e3a164e873df3", + "reference": "b485483a931d68f0935933ad563e3a164e873df3", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Ripcord\\": "src/Ripcord" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Darius Matulionis", + "email": "darius@matulionis.lt" + } + ], + "description": "RPC client and server around PHP's xmlrpc library", + "keywords": [ + "rpc", + "xml", + "xmlrpc" + ], + "time": "2017-05-24T05:49:36+00:00" + }, + { "name": "ezyang/htmlpurifier", "version": "v4.9.3", "source": { diff --git a/console/controllers/TestController.php b/console/controllers/TestController.php new file mode 100644 index 0000000..cceb637 --- /dev/null +++ b/console/controllers/TestController.php @@ -0,0 +1,195 @@ + [ 'name' ] ], + ] + ); + var_dump($models); + } + + public function actionT() + { + /** + * @var \artbox\odoo\components\Connection $odoo + */ + $odoo = \Yii::$app->get('odoo'); + + /** + * @var \artbox\odoo\components\Connection $connection + */ + $result = $odoo->createCommand( + 'product.template', + 'search_read', + [ + [ + [ + 'list_price', + '=', + 10, + ], + ], + ], + [ + 'fields' => [ + 'name', + 'list_price', + ], + ] + ) + ->execute(); + var_dump($result); + } + + public function actionK() + { + /** + * @var \artbox\odoo\components\Connection $odoo + */ + $odoo = \Yii::$app->get('odoo'); + + $result = $odoo->createCommand( + 'product.template', + 'create', + [ + [ + 'name' => 'Test10', + ], + ] + ) + ->execute(); + var_dump($result); + } + + public function actionQ() + { + /** + * @var \artbox\odoo\components\Connection $odoo + * @var \artbox\odoo\components\OdooMapper $mapper + */ + $odoo = \Yii::$app->get('odoo'); + $mapper = \Yii::$app->get('odooMapper'); + $result = ( new Query() )->from('product.template') + ->where( + [ + 'id', + '=', + 3, + ] + ) + ->one(); + $mapped = $mapper->toArtbox($result); + var_dump($mapped); + die(); + var_dump($mapper->toOdoo($mapped)); + } + + public function actionW() + { + /** + * @var \artbox\odoo\components\Connection $odoo + * @var \artbox\odoo\components\OdooMapper $mapper + */ + $odoo = \Yii::$app->get('odoo'); + $mapper = \Yii::$app->get('odooMapper'); + $result = ( new Query() )->from('sale.order') + ->where( + [ + 'id', + '=', + 1, + ] + ) + ->one(); + $products = ( new Query() )->from('sale.order.line') + ->where( + [ + 'order_id', + '=', + $result[ 'id' ], + ] + ) + ->all(); + foreach ($products as $product) { + var_dump($mapper->toArtbox($product)); + } + } + + public function actionE() + { + /** + * @var \artbox\odoo\components\Connection $odoo + */ + $odoo = \Yii::$app->get('odoo'); + $builder = new Builder($odoo); + $userId = $builder->setParam('name', 'Test1') + ->create('res.partner') + ->execute(); + $command = $builder->setParam('name', 'Test123') + ->setParam('partner_id', $userId) + ->create('sale.order'); + var_dump($command->execute()); + } + + public function actionR() + { + /** + * @var Order $order + */ + $order = Order::find() + ->with('orderProducts.variant.product') + ->one(); + $odooHelper = new OdooHelper(); + $odooHelper->ensureSaleOrderLine($order); + } + } \ No newline at end of file -- libgit2 0.21.4