Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. <?php
  2. //General format
  3. Easy::{$modelType}($action,$queryParams,$data);
  4. //or
  5. Easy::{$modelType}($action,$data); //eg create/add actions
  6.  
  7. /**
  8. * modelTypes
  9. * ----------
  10. *
  11. * Basket & BasketItem
  12. * User (or Customer)
  13. * Product
  14. * Category
  15. * Page
  16. * Navigation
  17. *
  18. * actions
  19. * -------
  20. *
  21. * 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
  22. * query - return many based on parameters, searched for on an 'OR' basis (and maybe 'LIKE')
  23. * filter - return many based on parameters, searched for on an 'AND' basis (with exact match)
  24. * create (alias add) - creare an item
  25. * update - updates many rows based on parameters, searched for on an 'AND' basis
  26. * delete (alias remove) - deletes ONE row based on parameters, searched for on an 'AND' basis
  27. *
  28. * data
  29. * ----
  30. *
  31. * The data to send in the request (adding / updating)
  32. *
  33. * Responses
  34. * =========
  35. *
  36. * Each call to Easy will return an instance of Resource,
  37. * Resource will have at least two public properties, model and store
  38. * ->store will be a zero-indexed multi dimension array of the requested data
  39. * ->model will be in instance of model, and will describe the format of the data in the store items
  40. *
  41. * To aid development we may also incluse properties such as
  42. * ->success (bool)
  43. * ->responseTime (float, milliseconds)
  44. * ->message (string, a system message)
  45. *
  46. * etc
  47. *
  48. */
  49.  
  50. //eg
  51.  
  52. //get information about a basket
  53. $basket = Easy::Basket('get',['session_id'=>session_id()]);
  54.  
  55. $basketItem = Easy::BasketItem('add',[
  56. 'basket_id'=>$basket->store[0]['id'],
  57. 'sku'=>$sku,
  58. 'qty'=>$qty
  59. ]);
  60.  
  61. Easy::BasketItem('update',['id'=>$basketItem->store[0]['id']],['qty'=>$newQty]);
  62.  
  63. //get a product by id
  64. Easy::Product('get',['id'=>$id]);
  65.  
  66. //get a product by sku
  67. $productInfo = Easy::Product('get',['sku'=>$sku]);
  68.  
  69. //search for products
  70. $productSearch = Easy::Product('query',['title'=>$title]);
  71.  
  72. //get a page based on the current url
  73. $page = Easy::Page('get',['url'=>$_SERVER['REQUEST_URI']]);
  74.  
  75. //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
  76.  
  77. //Category from current url
  78. $category = Easy::Category('get',['url'=>$_SERVER['REQUEST_URI']]);
  79.  
  80. //Category from id
  81. $category = Easy::Category('get',['id'=>$page->store[0]['resource_id']]);
  82.  
  83. //category products (full or list of ids - TBC)
  84. $category->store[0]['products'];
  85.  
  86. //full page navigation
  87. $siteMap = Easy::Nav('filter',['parent'=>'/']);
  88.  
  89. //mega menu
  90. $siteMap = Easy::Nav('filter',['parent'=>'/','section'=>'main_menu']);
  91.  
  92. //navigation from current url
  93. Easy::Nav('filter',['parent'=>$_SERVER['REQUEST_URI']]);
  94.  
  95. ?>
  96.  
  97.  
  98. These will essentially wrap the API, eg
  99.  
  100. GET /api/v1/product/8
  101.  
  102. POST /api/v1/basketItem {"basket_id":123,"sku":"ABC","qty":1}
  103.  
  104. {
  105. "success":true,
  106. "basketItem":{
  107. "id":34,
  108. "basket_id":123,
  109. "sku":"ABC",
  110. "qty":1
  111. }
  112. }
  113.  
  114.  
  115. PUT /api/v1/basketItem/34 {"qty":0}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement