├── .gitignore ├── bower.json ├── .github └── ISSUE_TEMPLATE.md ├── travis └── travis-ci-apache ├── package.json ├── magento-collect.html ├── LICENSE.md ├── generator ├── templateSingle.txt └── generator.js ├── magento-collect-rma-rma.html ├── magento-collect-sales-order.html ├── magento-collect-tax-tax-rate.html ├── magento-collect-tax-tax-rule.html ├── test ├── static-api-results │ └── products │ │ └── 24-MB01 └── scenarios.js ├── magento-collect-quote-cart-total.html ├── magento-collect-sales-invoice.html ├── magento-collect-sales-shipment.html ├── magento-collect-gift-message-cart.html ├── magento-collect-catalog-product.html ├── magento-collect-sales-creditmemo.html ├── magento-collect-sales-order-item.html ├── magento-collect-sales-transaction.html ├── magento-collect-tax-tax-class.html ├── magento-collect-quote-cart.html ├── magento-collect-catalog-category.html ├── magento-collect-quote-guest-cart.html ├── magento-collect-gift-wrapping-wrapping.html ├── magento-collect-eav-attribute-set.html ├── magento-collect-quote-guest-cart-total.html ├── magento-collect-catalog-product-attribute.html ├── magento-collect-gift-message-guest-cart.html ├── magento-collect-gift-message-item.html ├── magento-collect-catalog-category-attribute.html ├── magento-collect-catalog-attribute-set.html ├── magento-collect-bundle-product-option.html ├── magento-collect-configurable-product-option.html ├── magento-collect-catalog-product-custom-option.html ├── magento-collect-gift-message-guest-item.html ├── .travis.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | .DS_Store 3 | node_modules 4 | demo -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento-collect", 3 | "description": "A Magento WebAPI integration for Polymer", 4 | "main": "magento-collect.html", 5 | "keywords": [ 6 | "web-components", 7 | "polymer", 8 | "magento 2", 9 | "webapi" 10 | ], 11 | "authors": [ 12 | "Bob van Luijt (@bobvanluijt)" 13 | ], 14 | "license": "BSD-3", 15 | "homepage": "https://github.com/bobvanluijt/magento-collect", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests" 22 | ], 23 | "dependencies": { 24 | "polymer": "^1.6.1" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | 4 | ### Expected outcome 5 | 6 | 7 | 8 | ### Actual outcome 9 | 10 | 11 | 12 | ### Live Demo 13 | 14 | 15 | ### Steps to reproduce 16 | 17 | 22 | 23 | ### Browsers Affected 24 | 25 | - [ ] Chrome 26 | - [ ] Firefox 27 | - [ ] Safari 9 28 | - [ ] Safari 8 29 | - [ ] Safari 7 30 | - [ ] Edge 31 | - [ ] IE 11 32 | - [ ] IE 10 33 | -------------------------------------------------------------------------------- /travis/travis-ci-apache: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Options FollowSymLinks MultiViews ExecCGI 5 | AllowOverride All 6 | Order deny,allow 7 | Allow from all 8 | Require all granted 9 | 10 | 11 | # Wire up Apache to use Travis CI's php-fpm. 12 | 13 | 14 | Require all granted 15 | 16 | AddHandler php5-fcgi .php 17 | Action php5-fcgi /php5-fcgi 18 | Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi 19 | FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization 20 | 21 | 22 | ServerName localhost 23 | ServerAlias www.localhost 24 | DocumentRoot /var/www/magento2/pub 25 | 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento-collect", 3 | "description": "A Magento WebAPI integration for Polymer", 4 | "scripts": { 5 | "lint": "eslint ." 6 | }, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dorel/Magento-2-BDD-REST-API.git" 10 | }, 11 | "keywords": [ 12 | "BDD", 13 | "Magento 2" 14 | ], 15 | "bugs": { 16 | "url": "https://github.com/dorel/Magento-2-BDD-REST-API/issues" 17 | }, 18 | "eslintConfig": { 19 | "extends": "google" 20 | }, 21 | "author": "Bob van Luijt ", 22 | "license": "ISC", 23 | "homepage": "https://github.com/dorel/Magento-2-BDD-REST-API#readme", 24 | "devDependencies": { 25 | "assert": "*", 26 | "chai": "*", 27 | "eslint": "^3.5.0", 28 | "eslint-config-google": "^0.6.0", 29 | "should": "*", 30 | "supertest": "*" 31 | }, 32 | "dependencies": { 33 | "request": "^2.81.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /magento-collect.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 19 | 41 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Kubrickology 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of weaviate nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /generator/templateSingle.txt: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-rma-rma.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-sales-order.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-tax-tax-rate.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-tax-tax-rule.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /test/static-api-results/products/24-MB01: -------------------------------------------------------------------------------- 1 | { 2 | id: 1, 3 | sku: '24-MB01', 4 | name: 'Joust Duffle Bag', 5 | attribute_set_id: 15, 6 | price: 34, 7 | status: 1, 8 | visibility: 4, 9 | type_id: 'simple', 10 | created_at: '2016-10-17 13:50:45', 11 | updated_at: '2016-10-17 13:50:45', 12 | extension_attributes: [], 13 | product_links: [], 14 | options: [], 15 | media_gallery_entries: [{ 16 | id: 1, 17 | media_type: 'image', 18 | label: 'Image', 19 | position: 1, 20 | disabled: false, 21 | types: [Object], 22 | file: '/m/b/mb01-blue-0.jpg' 23 | }], 24 | tier_prices: [], 25 | custom_attributes: [{ 26 | attribute_code: 'description', 27 | value: '

The sporty Joust Duffle Bag can\'t be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it\'s ideal for athletes with places to go.

\n

' 28 | }, { 29 | attribute_code: 'image', 30 | value: '/m/b/mb01-blue-0.jpg' 31 | }, { 32 | attribute_code: 'small_image', 33 | value: '/m/b/mb01-blue-0.jpg' 34 | }, { 35 | attribute_code: 'thumbnail', 36 | value: '/m/b/mb01-blue-0.jpg' 37 | }, { 38 | attribute_code: 'category_ids', 39 | value: [Object] 40 | }, { 41 | attribute_code: 'required_options', 42 | value: '0' 43 | }, { 44 | attribute_code: 'has_options', 45 | value: '0' 46 | }, { 47 | attribute_code: 'url_key', 48 | value: 'joust-duffle-bag' 49 | }] 50 | } -------------------------------------------------------------------------------- /magento-collect-quote-cart-total.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-sales-invoice.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-sales-shipment.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-gift-message-cart.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-catalog-product.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-sales-creditmemo.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-sales-order-item.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-sales-transaction.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-tax-tax-class.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-quote-cart.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-catalog-category.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-quote-guest-cart.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-gift-wrapping-wrapping.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-eav-attribute-set.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-quote-guest-cart-total.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-catalog-product-attribute.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-gift-message-guest-cart.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-gift-message-item.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-catalog-category-attribute.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-catalog-attribute-set.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-bundle-product-option.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-configurable-product-option.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-catalog-product-custom-option.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /magento-collect-gift-message-guest-item.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 42 | -------------------------------------------------------------------------------- /test/scenarios.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* . . . . 3 | _|_ | | _|_ 4 | .--.--. .-. .-.. .-. .--. | .-. ____ .-..-. | | .-. .-.| 5 | | | |( )( |(.-' | | | ( ) ( ( )| |(.-'( | 6 | ' ' `-`-'`-`-`| `--'' `-`-'`-' `-'`-' `-`-`--'`-'`-' 7 | ._.' https://github.com/bobvanluijt/magento-collect 8 | */ 9 | 10 | var assert = require('assert'); 11 | var request = require('supertest'); 12 | var should = require('should'); 13 | 14 | var magentoRestUrl = 'http://localhost/index.php/rest/default/V1'; // set in travis yaml file. 15 | 16 | describe('Alice\'s Shopping Experience', () => { 17 | 18 | it('should get a product', function(done) { 19 | 20 | this.timeout(10000); // set timeout to 10seconds because all caches are disabled 21 | 22 | request(magentoRestUrl) // set the request url 23 | .get('/products/24-MB01') // always JSON 24 | .expect('Content-Type', /json/) // always JSON 25 | .expect(200, (err, res) => { 26 | let result = res.body; // load the result into a let 27 | console.log(result); 28 | console.log("\n=======\n"); 29 | done(); 30 | }); 31 | 32 | }); 33 | 34 | it('should get a product', function(done) { 35 | 36 | this.timeout(10000); // set timeout to 10seconds because all caches are disabled 37 | 38 | request(magentoRestUrl) // set the request url 39 | .get('/products') // always JSON 40 | .expect('Content-Type', /json/) // always JSON 41 | .expect(200, (err, res) => { 42 | let result = res.body; // load the result into a let 43 | console.log(result); 44 | console.log("\n=======\n"); 45 | done(); 46 | }); 47 | 48 | }); 49 | 50 | }); -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # . . . . 2 | # _|_ | | _|_ 3 | # .--.--. .-. .-.. .-. .--. | .-. ____ .-..-. | | .-. .-.| 4 | # | | |( )( |(.-' | | | ( ) ( ( )| |(.-'( | 5 | # ' ' `-`-'`-`-`| `--'' `-`-'`-' `-'`-' `-`-`--'`-'`-' 6 | # ._.' https://github.com/bobvanluijt/magento-collect 7 | 8 | dist: trusty 9 | 10 | sudo: required 11 | 12 | language: php 13 | 14 | php: 15 | - 7.0 16 | 17 | addons: 18 | apt: 19 | packages: 20 | - mysql-server-5.6 21 | - mysql-client-core-5.6 22 | - mysql-client-5.6 23 | 24 | before_install: 25 | # Install nodejs 26 | - sudo apt-get -qq update 27 | - sudo apt-get -qq install nodejs npm -y 28 | # Install Apache and Php Fpm 29 | - sudo apt-get install -y -qq apache2 libapache2-mod-fastcgi wget 30 | - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf 2>/dev/null || true 31 | - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf 32 | - sudo a2enmod rewrite actions fastcgi alias 33 | - echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini 34 | - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm 35 | - sudo cp -f travis/travis-ci-apache /etc/apache2/sites-available/000-default.conf 36 | - sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf 37 | # Install Magento 38 | - composer selfupdate 39 | - sudo mkdir -p /var/www && sudo chmod 777 /var/www && cd /var/www 40 | - wget https://github.com/magento/magento2/archive/2.1.1.tar.gz 41 | - tar -xzf 2.1.1.tar.gz 42 | - mv magento2-2.1.1/ magento2/ 43 | # Deploy sample data 44 | - cd /var/www 45 | - git clone https://github.com/magento/magento2-sample-data.git 46 | - cd magento2-sample-data/dev/tools 47 | - php -f build-sample-data.php -- --ce-source="/var/www/magento2" 48 | # Continue installation 49 | - cd /var/www/magento2 50 | - sudo find . -type f -exec chmod 644 {} \; 51 | - sudo find . -type d -exec chmod 755 {} \; 52 | - sudo find ./var -type d -exec chmod 777 {} \; 53 | - sudo find ./pub/media -type d -exec chmod 777 {} \; 54 | - sudo find ./pub/static -type d -exec chmod 777 {} \; 55 | - sudo chmod 777 ./app/etc 56 | - sudo chmod 644 ./app/etc/*.xml 57 | - composer install -q 58 | - chmod +x /var/www/magento2/bin/magento 59 | # Setup Magento 60 | - mysql -uroot -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; CREATE DATABASE magentodb;' 61 | - /var/www/magento2/bin/magento setup:install --quiet --backend-frontname="adminlogin" --db-host="127.0.0.1" --db-name="magentodb" --db-user="root" --db-password="" --language="en_US" --currency="USD" --timezone="America/New_York" --use-rewrites=1 --use-secure=0 --base-url="http://localhost" --base-url-secure="https://localhost" --admin-user=adminuser --admin-password=admin123@ --admin-email=admin@newmagento.com --admin-firstname=admin --admin-lastname=user --cleanup-database 62 | # Enable web api 63 | - mysql -uroot -e 'USE magentodb; REPLACE INTO core_config_data (path, value) VALUES("webapi/webapisecurity/allow_insecure", 1);' 64 | - /var/www/magento2/bin/magento cache:disable 65 | # restart apache 66 | - sudo service apache2 restart 67 | 68 | before_script: 69 | # Install npm deps globally 70 | - npm install -i -g gulp mocha supertest should chai assert 71 | # Country roads, take me home to the place I belong. 72 | - cd /home/travis/build/bobvanluijt/magento-collect 73 | - npm install 74 | 75 | script: 76 | # Start Testing! 77 | - mocha -------------------------------------------------------------------------------- /generator/generator.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The generator file generates elements based on Magento 2 Swagger document and template file 3 | * Author: @bobvanluijt 4 | */ 5 | var magentoSwaggerUrl = "http://devdocs.magento.com/swagger/schemas/latest-2.1.schema.json"; 6 | 7 | /** 8 | * Do not edit under this line 9 | */ 10 | var request = require("request"), 11 | fs = require('fs'); 12 | 13 | // reserve variable for restful URN inside this scope 14 | var RESTfulUrn; 15 | 16 | // template for documents 17 | const templateSingle = fs.readFileSync("generator/templateSingle.txt", "utf8"); 18 | 19 | /** 20 | * Capitalize the first character 21 | * @param {*String} string 22 | */ 23 | var capitalizeFirstLetter = (string) => { 24 | return string.charAt(0).toUpperCase() + string.slice(1); 25 | } 26 | 27 | /** 28 | * Generate the HTML files 29 | * @param {*String} filename 30 | * @param {*String} content 31 | */ 32 | var generateDocument = (filename, content) => { 33 | try { 34 | // write to file 35 | fs.writeFileSync(filename, content, 'utf8'); 36 | console.log("write file: ", filename); 37 | } 38 | catch(err) { 39 | // Sh*t! 40 | console.error("ERROR => write file: ", filename); 41 | } 42 | } 43 | 44 | /** 45 | * Generate the Polymer element 46 | * @param {*String} pathUrn 47 | * @param {*Obj} buildObj 48 | */ 49 | var generatePolymerElement = (pathUrn, buildObj) => { 50 | var elementNameArray = capitalizeFirstLetter(buildObj.operationId).match(/[A-Z]*[^A-Z]+/g); 51 | elementNameArray = elementNameArray.slice(0, -4); 52 | var elementName = elementNameArray.join("-").toLowerCase(); 53 | var documentName = "magento-collect-" + elementName + ".html"; 54 | var documentContent = templateSingle; 55 | var propertiesJs = ""; 56 | 57 | // edit pathUrn { & } to [[ & ]] 58 | pathUrn = pathUrn.replace('{', '[[').replace('}', ']]'); 59 | 60 | // get all available query parameters to create properties 61 | for (var params in buildObj.parameters) { 62 | var paramObj = buildObj.parameters[params]; 63 | if(paramObj.in === "path"){ 64 | propertiesJs += paramObj.name + `: { type: String, notify: true },`; 65 | } 66 | } 67 | 68 | // replace the RESTful url 69 | documentContent = documentContent 70 | .replace(/%%URLPATH%%/g , RESTfulUrn + pathUrn) 71 | .replace(/%%PROPERTIES%%/g , propertiesJs) 72 | .replace(/%%HTMLNAME%%/g , elementName) 73 | .replace(/%%SWAGGERID%%/g , buildObj.operationId) 74 | .replace(/%%DESCRIPTION%%/g, buildObj.description) 75 | 76 | // generate the actual documents 77 | generateDocument(documentName, documentContent); 78 | } 79 | 80 | /** 81 | * Get the operation Ids 82 | * @param {*String} pathKey 83 | * @param {*Obj} pathKeyObject 84 | */ 85 | var getOperationIds = (pathKey, pathKeyObject) => { 86 | if(pathKeyObject.get != undefined && pathKeyObject.get.operationId.indexOf("RepositoryV1GetGet") !== -1){ 87 | generatePolymerElement(pathKey, pathKeyObject.get) 88 | } 89 | } 90 | 91 | /** 92 | * Get te path from the object 93 | * @param {*Obj} i input obj 94 | */ 95 | var getPaths = (i) => { 96 | for (var pathKey in i.paths) { 97 | if (i.paths.hasOwnProperty(pathKey)) { 98 | getOperationIds(pathKey, i.paths[pathKey]) 99 | } 100 | } 101 | } 102 | 103 | /** 104 | * Start the request 105 | */ 106 | request({ 107 | url: magentoSwaggerUrl, 108 | json: true 109 | }, function (error, response, body) { 110 | if (!error && response.statusCode === 200) { 111 | // make url available in global scope 112 | RESTfulUrn = body.basePath; 113 | // set the paths based on the body of the response 114 | getPaths(body) 115 | } 116 | }) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # magento-collect 2 | 3 | Master branch | Develop branch 4 | --- | --- | --- 5 | [![Build Status](https://travis-ci.org/bobvanluijt/magento-collect.svg?branch=master)](https://travis-ci.org/bobvanluijt/magento-collect) | [![Build Status](https://travis-ci.org/bobvanluijt/magento-collect.svg?branch=develop)](https://travis-ci.org/bobvanluijt/magento-collect) 6 | 7 | _Note: this element is still in progress, watch it to follow the progress. This is like [Agile and stuff](https://media.makeameme.org/created/agile-quotmindsetquot.jpg)_ 8 | 9 | [#UseThePlatform](https://twitter.com/hashtag/usetheplatform)! The `magento` element is used to integrate Magento 2 through its [RESTful APIs](http://devdocs.magento.com/guides/v2.0/get-started/bk-get-started-api.html) directly into a Polymer app or website. 10 | 11 | The `magento-collect` element is an [extension for Polymer](https://elements.polymer-project.org) and handles the collection of Magento 2 data through its REST API. 12 | 13 | ## Installation 14 | 15 | `$ bower install --save bobvanluijt/magento-collect` 16 | 17 | Setup within Magento: 18 | - Enable the API: In case you setup Magento via the UI: webapi -> security -> allow insecure = true 19 | - Enable the API: in MySql: `REPLACE INTO core_config_data (path, value) VALUES("webapi/webapisecurity/allow_insecure", 1);` 20 | - Enable CORS on your webserver. [Nginx CORS](http://enable-cors.org/server_nginx.html), [Apache 2 CORS](http://enable-cors.org/server_apache.html) 21 | 22 | You need to define these global settings: 23 | 24 | ``` 25 | 35 | ``` 36 | 37 | ## Architectural principle 38 | 39 | [Magento 2](https://github.com/magento/magento2) has a [RESTful API](http://devdocs.magento.com/guides/v2.0/rest/bk-rest.html). 40 | 41 | The API follows the plural nouns RESTful approach. Example: `/products/{id}` for a single product and `/products` for a list of products. 42 | 43 | The `magento-collect` element follows this pattern by using plural and singular nouns. Based on Swagger document: http://devdocs.magento.com/swagger/index_20.html 44 | 45 | | Element | Resource | 46 | | -----------------------------|-------------------------------------------------------| 47 | | `magento-collect-products` | catalogProductRepositoryV1 - GET /V1/products | 48 | | `magento-collect-product` | catalogProductRepositoryV1 - GET /V1/products/{id} | 49 | | `magento-collect-categories` | catalogCategoryManagementV1 - GET /V1/categories | 50 | | `magento-collect-category` | catalogCategoryRepositoryV1 - GET /V1/categories/{id} | 51 | 52 | The `collector` attribute defines which `{id}` should be collected. 53 | 54 | The object returned is available through the `` element. 55 | 56 | A complete example: 57 | 58 | ``` 59 | 60 |

61 |

62 |
63 | ``` 64 | 65 | ## Immutable Store 66 | 67 | Immutable storage is inspired by [Netflix's Falcor](https://github.com/Netflix/falcor). If you collect data, you can store it locally during a session. When a user goes back to a previously visited page, it will first travel the local object to find the information needed rather than going to the API directly. 68 | 69 | ## Usage and overview of available sub-elements 70 | 71 | Overview: 72 | - [magento-collect-product](#magento-collect-product) 73 | - [magento-collect-products](#magento-collect-products) 74 | - [magento-collect-item](#magento-collect-item) 75 | - _...soon more to follow..._ 76 | 77 | #### <magento-collect-product> 78 | 79 | ```html 80 | 81 | ``` 82 | 83 | The complete product becomes available with by binding it within the tags. 84 | 85 | ```html 86 | 87 | 88 | 89 | ``` 90 | 91 | You can also combine data bindings with conditionals. 92 | 93 | ```html 94 | 95 | 98 | 99 | ``` 100 | 101 | #### <magento-collect-products> 102 | 103 | You can also collect products using filters, for example all products that start with a certain name. This might also be use to collect multiple products. 104 | 105 | You can define multiple filters by using a semicolon as seperator. 106 | 107 | ```html 108 | 109 | ``` 110 | 111 | The complete product becomes available with double curly braces. The filtering work as follows: 112 | - Add `filter=""` tag and add 113 | 114 | ```html 115 | 116 | 119 | 120 | ``` 121 | 122 | The filters and criteria are based on the [Magento 2 WebAPI Search Criteria](http://devdocs.magento.com/guides/v2.1/howdoi/webapi/search-criteria.html). 123 | 124 | ### The Mage-Polymer-Object 125 | 126 | The Magento 2 Object is saved following the GET endpoint responses. 127 | 128 | For example: 129 | 130 | When an element has the following bindings: `{{ MAGE.product.name}}` and `{{ MAGE.product.weigth}}` it will result in the request: `[RESTURL]/products/24-MB01?fields=name,weigth`. It will locally create the following MAGE object: 131 | 132 | ``` 133 | { 134 | "MAGE": { 135 | "/products/24-MB01": { 136 | "name": "Joust Duffle Bag", 137 | "weight": 0 138 | } 139 | } 140 | } 141 | ``` 142 | 143 | If a new call is done to the Magento 2 API it will first check the collected information in the `MAGE` object. If it is not available in the object it will collect it from the Magento API setting the filter for this specific values. 144 | 145 | In the above example, requesting: `{{ MAGE.product.name }}` and `{{ MAGE.product.type_id }}` will result in the request: `[RESTURL]/products/24-MB01?fields=type_id` 146 | 147 | This feature can be disabled (see (Installation)[#Installation] ) 148 | 149 | ## Contributing 150 | 151 | 1. Fork it! 152 | 2. Create your feature branch: `git checkout -b my-new-feature` 153 | 3. Commit your changes: `git commit -am 'Add some feature'` 154 | 4. Push to the branch: `git push origin my-new-feature` 155 | 5. Submit a pull request :D 156 | 157 | ## Credits 158 | 159 | Bob van Luijt (@bobvanluijt) 160 | 161 | ## License 162 | 163 | See license.md file. 164 | --------------------------------------------------------------------------------