public function getProducts($currentProductId) { $result = array(); $api = new EcwidProductApi(self::$storeId); $product = $api->get_product($currentProductId); if (!isset($product["categories"])) { return $result; } // find "Related" category $categoryId = null; foreach ($product["categories"] as $category) { if (strpos($category["name"], self::RELATED_PEFIX) === 0) { $categoryId = $category["id"]; break; } } if ($categoryId === null) { return $result; } // get products data $products = $api->get_products_by_category_id($categoryId); if (!$products) { return $result; } // exclude current product foreach ($products as $i => $product) { if ($product["id"] == $currentProductId) { unset($products[$i]); break; } } // get detail info for products $params = array(); foreach ($products as $i => $product) { $params[$i] = array("alias" => "p" . $i, "action" => "product", "params" => array("id" => $product["id"])); } $batchResult = $api->get_batch_request($params); if (!$batchResult) { return $result; } // find real category (for real url to related product) foreach ($products as $i => $product) { $res = $batchResult["p" . $i]; $realCategory = null; foreach ($res["categories"] as $category) { if (strpos($category["name"], self::RELATED_PEFIX) !== 0) { $realCategory = $category; break; } } $products[$i]["realCategory"] = $realCategory; $products[$i]["details"] = $res; $products[$i]["siteProductUrl"] = self::getProductUrl($products[$i]); } $result = $products; return $result; }
function ecwid_get_mixed_data($get_category_only = false) { include_once "lib/ecwid_product_api.php"; $ecwid_store_id = intval(get_ecwid_store_id()); $api = new EcwidProductApi($ecwid_store_id); global $wp_query; $ecwid_category_id = intval($wp_query->query_vars['ecwid_category_id']); $ecwid_product_id = intval($wp_query->query_vars['ecwid_product_id']); if (empty($ecwid_category_id)) { $ecwid_category_id = 0; } if ($get_category_only) { $params = array(array("alias" => "c", "action" => "category", "params" => array("id" => $ecwid_category_id))); return $api->get_batch_request($params); } if (!empty($ecwid_product_id) && !$get_category_only) { $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); } else { $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); } return $batch_result; }
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; 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"]; } 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"]; } $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>"; $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>"; $html .= " <span class='ecwid_product_price'>" . $product_price . "</span>"; $html .= "</div>"; } } } return $html; }