Skip to content

Instantly share code, notes, and snippets.

@nico159

nico159/.htaccess Secret

Created Oct 24, 2018
Embed
What would you like to do?
Zakeke Configurator Product Sync API
RewriteEngine on
RewriteRule ^products/?$ api.php?type=products [L,QSA]
RewriteRule ^products/configurator/?$ api.php?type=product [L,QSA]
RewriteRule ^products/configurator/(.*)$ api.php?type=productDelete&code=$1 [L,QSA]
RewriteRule ^products/(.*)/options/?$ api.php?type=productOptions&code=$1 [L,QSA]
<?php
define("PRODUCT_PER_PAGE", 20);
// The response must always be in json format
header("Content-Type: application/json");
// Dummy data
$products = [
[
"code" => "1343242",
"name" => "Woman handbag",
"thumbnail" => "https://..."
],
[
"code" => "1343243",
"name" => "Watch",
"thumbnail" => "https://...",
"metadata" => [
"additional_info" => "info"
]
]
];
$productOptions = [
"1343242" => [
[
"code" => "34523",
"name" => "Color",
"values" => [
[
"code" => "537564567",
"name" => "White"
],
[
"code" => "646456464",
"name" => "Black"
]
]
]
]
];
function products($page) {
global $products;
// Return an empty array in case of a missing resoult
echo json_encode(array_slice($products, PRODUCT_PER_PAGE * ($page - 1), PRODUCT_PER_PAGE));
}
function product() {
$data = json_decode(file_get_contents("php://input"), true);
$code = $data["code"];
// Set the product as configurable
}
function productDelete($code) {
// Set the product as not longer configurable.
}
function productOptions($code) {
global $productOptions;
// Return an empty array in case of a missing resoult
echo json_encode(isset($productOptions[$code]) ? $productOptions[$code] : []);
}
switch($_REQUEST["type"]) {
case "products":
products(isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1);
break;
case "product":
product();
break;
case "productDelete":
productDelete($_REQUEST["code"]);
break;
case "productOptions":
productOptions($_REQUEST["code"]);
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.