{"id":18577546,"url":"https://github.com/ecomplus/neo4j-sync","last_synced_at":"2025-07-13T09:36:06.606Z","repository":{"id":103581312,"uuid":"113851815","full_name":"ecomplus/neo4j-sync","owner":"ecomplus","description":"PHP scripts to sync Neo4j (graphs DB) with E-Com Plus Store API","archived":false,"fork":false,"pushed_at":"2024-02-01T17:44:48.000Z","size":35,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T01:34:02.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/ecomclub/ecomplus-neo4j","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomplus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-11T11:40:54.000Z","updated_at":"2021-11-19T00:23:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"de39f6b2-32d7-49c3-91ff-f416c6461390","html_url":"https://github.com/ecomplus/neo4j-sync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ecomplus/neo4j-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fneo4j-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fneo4j-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fneo4j-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fneo4j-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomplus","download_url":"https://codeload.github.com/ecomplus/neo4j-sync/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fneo4j-sync/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265121267,"owners_count":23714500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T23:29:36.345Z","updated_at":"2025-07-13T09:36:06.589Z","avatar_url":"https://github.com/ecomplus.png","language":"PHP","readme":"![logo](https://avatars3.githubusercontent.com/u/34305306?s=200\u0026v=4\"Logo\")\n# ecomplus-neo4j\nPHP scripts to sync Neo4j (recommendations DB) with E-Com Plus Store API [[1]]\n# Summary\n1. [Introduction](#introduction)\n   * [Requirements](#requirements)\n   * [Installing dependency manager for PHP](#installing-dependency-manager-for-php)\n   * [Dependency installation](#dependency-installation)\n2. [Settings and basic usage](#settings-and-basic-usage)\n   * [Neo4j Settings](#neo4j-settings)\n   * [Basic use](#basic-use)\n     * [Installing the Neo4j library in php](#installing-the-neo4j-library-in-php)\n     * [Creating a node in Neo4j](#creating-a-node-in-neo4j)\n     * [Creating relationship in Neo4j](#creating-relationship-in-neo4j)\n     * [Get node of the Neo4j](#get-node-of-the-neo4j)\n     * [Get API Product and create nodes](#get-api-product-and-create-nodes)\n3. [E-Com Plus Graphs API](#e-com-plus-graphs-api)\n4. [Reference](#reference)\n\n# Introduction\n[Neo4j](https://neo4j.com/) is a non-relational graph-oriented database and is very common in social networks.\nThe idea of using Neo4j in the E-Com Plus API is to use the recommendations system that is widely used in social networks, where in this specific case when choosing a product the API will recommend another product in which it has the highest number of relations with the chosen product.\n\nThe scripts present in this repository are used to get all the public API information and synchronize them with the DB in order to create a product recommendation system.\n## Requirements\n* [PHP](http://www.php.net/) 7\n* Neo4j Database (version 3.3)\n## Installing dependency manager for PHP\nFor more information on how to install the manager [[2]]\n## Dependency installation\nFor more information on installing the dependency required for this project [[3]]\n# Settings and basic usage\n## Neo4j Settings\nTo initialize Neo4j it is recommended that you create a new user in the DB and remove the default user, for this procedure, you use the following command lines[[4]]:\n`$cypher-shell`\n\nusername:`neo4j`\n\npassword: `neo4j`\n\nBy default Neo4j is required to change the default user password:\n``` cypher-shell\n\u003e CALL dbms.security.changePassword('newpassword');\n```\nHere in this example changed to * new password *.\n\nAnd only after changing the default user password that it is possible to add the new user.\n``` cypher-shell\n\u003e CALL dbms.security.createUser('user', 'password', 'false');\n```\n**_ Note:_** _requirePasswordChange_: this is optional, with a default of `true`. If this is true, (i) the user will be forced to change their password when they first log in, and (ii) until the user has changed their password, they will be prohibited from performing any other operation. [[5]]. In the example, the _requirePasswordChange_ is `false`, since it will no longer be necessary to change the password for this user.\n\nAfter the new user is created it is necessary to _logout_:\n```\n\u003e:exit\n```\n_Login_ with the new user:\n```\n$cypher-shell  -u user -p password\n```\nAnd delete the default user:\n```cypher-shell\n\u003e CALL dbms.security.deleteUser('neo4j');\n```\n## Basic use\nAll codes described here are made in php.\nAfter you install the requirements, the dependencies and execute the settings in Neo4j.\n#### Installing the Neo4j library in php\nAdding library to php dependencies\n```\n$composer require neoxygen/neoclient\n```\nIn this project a script was created only for the manipulation of the data with Neo4j (neo4j.php). And to connect the php to Neo4j it is necessary to add the settings in the script, as follows[[3]]:\n```php\nneo4j.php\n\u003c?php\nrequire_once 'vendor/autoload.php';\nuse Neoxygen\\NeoClient\\ClientBuilder;// add libary Neo4J\n$user = 'user'; // DB User\n$password = 'password'; //User Password\n$client = ClientBuilder::create() // create connection Neo4j\n    -\u003eaddConnection('default', 'http', 'localhost', 7474, true, $user, $password ) // initial connection\n    -\u003ebuild();\n```\n###  Creating a node in Neo4j\nTo create a node in Neo4j it is necessary to use the following functions, in this example if you create a product node with the properties id, storeId, name and brands. These properties will be passed as a function parameter to execute the request.\n```php\nneo4j.php\n\u003c?php\nfunction createNode($storeID,$Product)\n{\n    // start string Brands as empty\n    $Brands = 'exemple';\n    // create only one node Products\n    // query to create Product\n    $query .= ' MERGE (p:Product {id:{idProduct}, storeID:{idStore}}) set p.name={nameProduct} set p.brands={brandsProduct}';\n    // parametrs for products, id, name and brands\n    $parameters = [\n      'idProduct' =\u003e $Product['_id'],\n      'nameProduct' =\u003e $Product['name'],\n      'brandsProduct' =\u003e $Brands,\n      'idStore:' =\u003e $storeID,\n    ];\n    // execute query\n    $client-\u003esendCypherQuery($query, $parameters);\n}\n```\n### Creating relationship in Neo4j\nIn this example, you create a relationship between Store and Product using store id, product id as a function parameter.\n```php\nneo4j.php\n\u003c?php\nfunction createRelationship($storeID,$Product)\n{\n    $query = 'MATCH (s:Store {id:{idStore}})';\n    $query .= ' MATCH (p:Product {id:{idProduct}, storeID:{idStore}})'; // query to create Product\n    $query .= ' MERGE (s)-[:Has]-\u003e(p)'; // query to create relationship Product and Store\n    $parameters = [\n      'idProduct' =\u003e $Product['_id'],\n      'idStore:' =\u003e $storeID\n    ];\n    // execute query\n    $client-\u003esendCypherQuery($query, $parameters);\n}\n```\n### Get node of the Neo4j\nIn this example the function will fetch nodes in Neo4j and return them. It was observed that when the result of a request is captured the response of this result (in this case the Body) is protected, using this library, and to be able to manipulate this data uses the function `getBody()`which can be observed in the library file available in: `../vendor/neoxygen/neoClient/src/Request/Response.php`. The following function looks up all the store nodes in Neo4j and returns the id's of them, doing all filtering of the data so that the desired answer is obtained.\n```php\nneo4j.php\n\u003c?php\nfunction getStoreNeo4j()\n{\n    $client = $GLOBALS['client']; // retrieves value from global client variable and saves to a local client variable\n    $query = 'MATCH (s:Store) RETURN s';\n    // function seach Store\n    $result = $client-\u003esendCypherQuery($query);\n    /* get public reponse, because $result is protected\n    see ../vendor/neoxygen/neoClient/src/Request/Response.php */\n    $publicResult = $result-\u003egetBody();\n    $response = $publicResult['results'][0]['data'];\n    // filtering results\n    // exemple of filtering\n    $res = [];\n    for ($i = 0; $i \u003c count($response); ++$i) {\n        $sid = $response[$i]['row'][0]['id'];\n        array_push($res, ['id' =\u003e $sid]);\n    }\n\n    return $res; // return result\n}\n\n```\n### Get API Product and create nodes\nTo get all the products of a store in the API, you need to get the store ID on Neo4j, since they are only available in the database. Soon after obtaining the ids of the stores, for each store will be listed all products and for each product listed, a product node will be created with the properties of that product and the store ID. To get the json of the API response, the functions `curl_()` and `json_decode()`.\nFunction used to get json from a store in the API:\n```php\nindex.php\n\u003c?php\nfunction getUrl($url, $storeID)\n{ // function to get Json in the page, using cURL\n    //  Initiate curl\n    $ch = curl_init();\n    // Set the url\n    curl_setopt($ch, CURLOPT_URL, $url);\n    // Will return the response, if false it print the response\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n\n    curl_setopt($ch, CURLOPT_HEADER, false);\n    // Send header to requisition\n    curl_setopt($ch, CURLOPT_HTTPHEADER, [\n    'Content-Type: application/json',\n    'X-Store-ID:'.$storeID,\n  ]);\n    // Execute\n    $result = curl_exec($ch);\n    // Closing\n    curl_close($ch);\n    // Will dump a beauty json\n    $varRes = json_decode($result, true);\n\n    return $varRes;\n}\n```\nFunction to get product in API and create the node:\n```php\nindex.php\n\u003c?php\nfunction getProduct($storeID)\n{\n    // usleep ( 500 ); // pauses the script 500 milliseconds, to conduct a new store query\n    // Object with all products\n    $varAllProduct = getUrl('https://api.e-com.plus/v1/products.json', $storeID);\n    // for each product, create node in NEO4J with the _id, sku, name and brand property.\n\n    // Filter Object to display only products and their properties\n    $allProduct = $varAllProduct['result'];\n    // attempts for eventual error\n    $attempts = 0;\n    for ($i = 0; $i \u003c count($allProduct); ++$i) {\n        $Product = getUrl('https://api.e-com.plus/v1/products/'.$allProduct[$i]['_id'].'.json', $storeID);\n        createNode($Product[$i], $storeID);\n        createRelationship( $storeID$Product[$i]);\n    }\n}\n```\nFunction to get the stores in neo4j and run the function to get of API and create the products node, this function is responsible for running the whole script:\n```php\nindex.php\n\u003c?php\n// script run\n// Get all the stores on Neo4j, which are returned in an array\n$store = getStoreNeo4j();\n// for each Store,  get all products and save on Neo4j\nfor ($i = 0; $i \u003c count($store); ++$i) {\n    getProduct($store[$i]['id']);\n}\n\n```\n\n\n\n\n# E-Com Plus Graphs API\nNeo4j data is public at the _E-Com Plus Graphs REST API_,\ndocumentation is available here:\n\nhttps://ecomgraphs.docs.apiary.io/#\n\n\n\n# Reference\n[[1]] \u003chttps://ecomstore.docs.apiary.io/#\u003e\n\n[[2]] \u003chttps://getcomposer.org/download/\u003e\n\n[[3]] \u003chttps://github.com/neoxygen/neo4j-neoclient\u003e\n\n[[4]] \u003chttps://neo4j.com/docs/operations-manual/current/reference/user-management-community-edition/\u003e\n\n[[5]] \u003chttps://neo4j.com/docs/operations-manual/current/reference/user-management-community-edition/#userauth-add-user-ce\u003e\n\n[1]: https://github.com/ecomclub/ecomplus-neo4j#reference\n[2]: https://github.com/ecomclub/ecomplus-neo4j#reference\n[3]: https://github.com/ecomclub/ecomplus-neo4j#reference\n[4]: https://github.com/ecomclub/ecomplus-neo4j#reference\n[5]: https://github.com/ecomclub/ecomplus-neo4j#reference\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomplus%2Fneo4j-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomplus%2Fneo4j-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomplus%2Fneo4j-sync/lists"}