Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //General format
- Easy::{$modelType}($action,$queryParams,$data);
- //or
- Easy::{$modelType}($action,$data); //eg create/add actions
- /**
- * modelTypes
- * ----------
- *
- * Basket & BasketItem
- * User (or Customer)
- * Product
- * Category
- * Page
- * Navigation
- *
- * actions
- * -------
- *
- * read (alias get) - returns 1 based on parameters, searched for on an 'AND' basis - expected usage would be to supply an id, sku or page url
- * query - return many based on parameters, searched for on an 'OR' basis (and maybe 'LIKE')
- * filter - return many based on parameters, searched for on an 'AND' basis (with exact match)
- * create (alias add) - creare an item
- * update - updates many rows based on parameters, searched for on an 'AND' basis
- * delete (alias remove) - deletes ONE row based on parameters, searched for on an 'AND' basis
- *
- * data
- * ----
- *
- * The data to send in the request (adding / updating)
- *
- * Responses
- * =========
- *
- * Each call to Easy will return an instance of Resource,
- * Resource will have at least two public properties, model and store
- * ->store will be a zero-indexed multi dimension array of the requested data
- * ->model will be in instance of model, and will describe the format of the data in the store items
- *
- * To aid development we may also incluse properties such as
- * ->success (bool)
- * ->responseTime (float, milliseconds)
- * ->message (string, a system message)
- *
- * etc
- *
- */
- //eg
- //get information about a basket
- $basket = Easy::Basket('get',['session_id'=>session_id()]);
- $basketItem = Easy::BasketItem('add',[
- 'basket_id'=>$basket->store[0]['id'],
- 'sku'=>$sku,
- 'qty'=>$qty
- ]);
- Easy::BasketItem('update',['id'=>$basketItem->store[0]['id']],['qty'=>$newQty]);
- //get a product by id
- Easy::Product('get',['id'=>$id]);
- //get a product by sku
- $productInfo = Easy::Product('get',['sku'=>$sku]);
- //search for products
- $productSearch = Easy::Product('query',['title'=>$title]);
- //get a page based on the current url
- $page = Easy::Page('get',['url'=>$_SERVER['REQUEST_URI']]);
- //a page response will return the CMS content for the url and also referenece other resources required for the page, eg the product id or category name
- //Category from current url
- $category = Easy::Category('get',['url'=>$_SERVER['REQUEST_URI']]);
- //Category from id
- $category = Easy::Category('get',['id'=>$page->store[0]['resource_id']]);
- //category products (full or list of ids - TBC)
- $category->store[0]['products'];
- //full page navigation
- $siteMap = Easy::Nav('filter',['parent'=>'/']);
- //mega menu
- $siteMap = Easy::Nav('filter',['parent'=>'/','section'=>'main_menu']);
- //navigation from current url
- Easy::Nav('filter',['parent'=>$_SERVER['REQUEST_URI']]);
- ?>
- These will essentially wrap the API, eg
- GET /api/v1/product/8
- POST /api/v1/basketItem {"basket_id":123,"sku":"ABC","qty":1}
- {
- "success":true,
- "basketItem":{
- "id":34,
- "basket_id":123,
- "sku":"ABC",
- "qty":1
- }
- }
- PUT /api/v1/basketItem/34 {"qty":0}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement