Skip to content

Instantly share code, notes, and snippets.

@reginaldojunior
Created October 22, 2017 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reginaldojunior/0c7627e32f3e35ad8172b4eeae98da09 to your computer and use it in GitHub Desktop.
Save reginaldojunior/0c7627e32f3e35ad8172b4eeae98da09 to your computer and use it in GitHub Desktop.
opencart-products-actives.php
<?php
ini_set('memory_limit', '-1');
error_reporting(0);
class ControllerApiCiawn extends Controller
{
/**
* @example http://domain.com/index.php?route=api/ciawn/getProductsActives
* @param @name
**/
public function getProductsActives()
{
$this->load->model('catalog/product');
$name = $this->request->get['name'];
$data = array(
'filter_status' => 1
);
if (isset($name) && !empty($name)) {
$data['filter_name'] = $name;
}
$response = $this->model_catalog_product->getProducts($data);
if (isset($this->request->server['HTTP_ORIGIN'])) {
$this->response->addHeader(
'Access-Control-Allow-Origin: ' . $this->request->server['HTTP_ORIGIN']
);
$this->response->addHeader(
'Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'
);
$this->response->addHeader(
'Access-Control-Max-Age: 1000'
);
$this->response->addHeader(
'Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With'
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($response));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment