/ Published in: PHP
URL: http://api.pinnaclecart.com/docs/
This is a useful class which utilizes Phil Sturgeon's helpful restclient (http://getsparks.org/packages/restclient/versions/HEAD/show). Reference the URL attached for PinnacleCart API docs.
Example request URLs to get products and categories:
Get product by product_id (XX##) or keyword(s)~/products/getProducts/search/10/oj70/oj77/oj75
Recently added products by CategoryID (/cID/batchSize)~/products/getProductsByCategory/92/10
Recently added product images by CategoryID (/cID/batchSize)-- This was to remove the 'Description' key/value for slide shows ~/products/getProductImagesByCategory/92/10
Recently added products by limit~/products/getRecentlyAdded/20
Get all categories~/products/getCategories
Expand |
Embed | Plain Text
<?php class Products extends MX_Controller { function __construct() { parent::__construct(); // Load the rest client spark $this->load->spark('restclient/2.1.0'); // Load the library $this->load->library('rest'); //load domain, format and API creds $this->secure_domain = 'https://www.yoursecuredomain.com/'; $this->user = 'apiuser'; $this->pass = 'apipass'; $this->token = 'apitokenstring'; $this->format = 'json'; } public function getCategories(){ // Run some setup $call = 'GetCategories'; $url = 'content/admin/plugins/openapi/index.php?token=' . $this->token . '&apiType=' . $this->format . '&call=' . $call . '&username=' . $this->user . '&password=' . $this->pass; $categories = $this->rest->get( $url ); } public function getRecentlyAdded($num){ // Run some setup $call = 'GetProducts'; $call .= '&mode=search&BatchPage=3&BatchSize=' . $num . '&CatalogSortBy=date'; $url = 'content/admin/plugins/openapi/index.php?token=' . $this->token . '&apiType=' . $this->format . '&call=' . $call . '&username=' . $this->user . '&password=' . $this->pass; $products = $this->rest->get( $url ); } public function getProductsByCategory($id){ // if URL contains $mode = 'category' then do PrimaryCategory request // URL Scheme : ~/restclient/getProductsByCategory/$catID/$batch_size/ //'mode' => $this->uri->segment(2), -- assumed mode by default -- PrimaryCategory (argument) 'category' => $id, //$this->uri->segment(3) 'batch' => $this->uri->segment(5) ); // Run some setup $call = 'GetProducts'; $args = 'PrimaryCategory=' . $this->uri['category']; $batch_size = $this->uri['batch']; $call .= '&' . $args . '&BatchSize=' . $batch_size . '&CatalogSortBy=date'; //build up args $url = 'content/admin/plugins/openapi/index.php?token=' . $this->token . '&apiType=' . $this->format . '&call=' . $call . '&username=' . $this->user . '&password=' . $this->pass; $products = $this->rest->get( $url ); } public function getProductImagesByCategory($id){ // if URL contains $mode = 'category' then do PrimaryCategory request // URL Scheme : ~/restclient/getProductsByCategory/$catID/$batch_size/ //'mode' => $this->uri->segment(2), -- assumed mode by default -- PrimaryCategory (argument) 'category' => $id, //$this->uri->segment(3) 'batch' => $this->uri->segment(5) ); // Run some setup $call = 'GetProducts'; $args = 'PrimaryCategory=' . $this->uri['category']; $batch_size = $this->uri['batch']; $call .= '&' . $args . '&BatchSize=' . $batch_size . '&CatalogSortBy=date'; //build up args $url = 'content/admin/plugins/openapi/index.php?token=' . $this->token . '&apiType=' . $this->format . '&call=' . $call . '&username=' . $this->user . '&password=' . $this->pass; $products = $this->rest->get( $url ); foreach($products as $i=>$prod){ foreach($prod->Product as $key=>$value){ if($key!='Description') $result[$i]['Product'][$key] = $value; }} } // URL Scheme : ~/restclient/getProducts/$mode/$batch_size/ 'mode' => $mode, 'batch' => $this->uri->segment(5), 'keyword1' => $this->uri->segment(6), 'keyword2' => $this->uri->segment(7), 'keyword3' => $this->uri->segment(8), ); // Run some setup $call = 'GetProducts'; $args = 'mode=' . $this->uri['mode']; if( $this->uri['batch']!='' && $this->uri['mode'] == 'search' ) $args .= '&BatchSize=' . $this->uri['batch']; if( $this->uri['keyword1']!='' ) $args .= '&keywords=' . $this->uri['keyword1']; if( $this->uri['keyword2']!='' ) $args .= ',or,' . $this->uri['keyword2']; if( $this->uri['keyword3']!='' ) $args .= ',or,' . $this->uri['keyword3']; $args .= '&CatalogSortBy=added'; // string : API arguments and URL string $call .= '&' . $args;// . '&BatchSize=' . $batch_size; //build up args $url = 'content/admin/plugins/openapi/index.php?token=' . $this->token . '&apiType=' . $this->format . '&call=' . $call . '&username=' . $this->user . '&password=' . $this->pass; // REST GET REQUEST $products = $this->rest->get( $url ); } }
You need to login to post a comment.
