Created
February 9, 2012 10:11
-
-
Save makfruit/1779039 to your computer and use it in GitHub Desktop.
Hide prices for particular categories in Inline SEO catalog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function show_ecwid_catalog($ecwid_store_id) { | |
include_once "ecwid_product_api.php"; | |
$ecwid_store_id = intval($ecwid_store_id); | |
$api = new EcwidProductApi($ecwid_store_id); | |
$cat_id = isset($_GET['ecwid_category_id']) ? intval($_GET['ecwid_category_id']) : false; | |
$prod_id = isset($_GET['ecwid_product_id']) ? intval($_GET['ecwid_product_id']) : false; | |
$ecwid_category_id = $cat_id; | |
$ecwid_product_id = $prod_id; | |
$hide_prices = false; | |
$categories_w_hidden_prices = array( | |
1765386, | |
1765387 | |
); | |
if (!empty($ecwid_product_id)) { | |
$params = array( | |
array("alias" => "p", "action" => "product", "params" => array("id" => $ecwid_product_id)), | |
array("alias" => "pf", "action" => "profile") | |
); | |
$batch_result = $api->get_batch_request($params); | |
$product = $batch_result["p"]; | |
$profile = $batch_result["pf"]; | |
// Check if the price should be hidden | |
if ( | |
!empty($categories_w_hidden_prices) | |
&& !empty($product) | |
) { | |
foreach ($product['categories'] as $product_category) { | |
if (in_array($product_category['id'], $categories_w_hidden_prices)) { | |
$hide_prices = true; | |
} | |
} | |
} | |
} | |
else { | |
if (empty($ecwid_category_id)) { | |
$ecwid_category_id = 0; | |
} | |
$params = array( | |
array("alias" => "c", "action" => "categories", "params" => array("parent" => $ecwid_category_id)), | |
array("alias" => "p", "action" => "products", "params" => array("category" => $ecwid_category_id)), | |
array("alias" => "pf", "action" => "profile") | |
); | |
$batch_result = $api->get_batch_request($params); | |
$categories = $batch_result["c"]; | |
$products = $batch_result["p"]; | |
$profile = $batch_result["pf"]; | |
// Check if the price should be hidden | |
if ( | |
!empty($categories_w_hidden_prices) | |
&& in_array($ecwid_category_id, $categories_w_hidden_prices) | |
) { | |
$hide_prices = true; | |
} | |
} | |
$html = ''; | |
if (isset($product) && is_array($product)) { | |
$html = "<div class='hproduct'>"; | |
$html .= "<div class='ecwid_catalog_product_image photo'><img src='" . $product["thumbnailUrl"] . "'/></div>"; | |
$html .= "<div class='ecwid_catalog_product_name fn'>" . htmlentities($product["name"]) . "</div>"; | |
if (!$hide_prices) { | |
$html .= "<div class='ecwid_catalog_product_price price'>Price: " . $product["price"] . " " . $profile["currency"] . "</div>"; | |
} | |
$html .= "<div class='ecwid_catalog_product_description description'>" . $product["description"] . "</div>"; | |
$html .= "</div>"; | |
} else { | |
if (is_array($categories)) { | |
foreach ($categories as $category) { | |
$category_url = ecwid_internal_construct_url($category["url"], array("ecwid_category_id" => $category["id"])); | |
$category_name = $category["name"]; | |
$html .= "<div class='ecwid_catalog_category_name'><a href='" . $category_url . "'>" . $category_name . "</a><br /></div>"; | |
} | |
} | |
if (is_array($products)) { | |
foreach ($products as $product) { | |
$product_url = ecwid_internal_construct_url($product["url"], array("ecwid_product_id" => $product["id"])); | |
$product_name = $product["name"]; | |
$product_price = $product["price"] . " " . $profile["currency"]; | |
$html .= "<div>"; | |
$html .= "<span class='ecwid_product_name'><a href='" . $product_url . "'>" . $product_name . "</a></span>"; | |
if (!$hide_prices) { | |
$html .= " <span class='ecwid_product_price'>" . $product_price . "</span>"; | |
} | |
$html .= "</div>"; | |
} | |
} | |
} | |
return $html; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment