Esempio n. 1
0
 public function getProducts($currentProductId)
 {
     $result = array();
     $api = new EcwidProductApi(self::$storeId);
     $currentProduct = $api->get_product($currentProductId);
     if (!isset($currentProduct["categories"])) {
         return $result;
     }
     $categoryId = null;
     foreach ($currentProduct["categories"] as $category) {
         //if (strpos($category["name"], self::MOD_PEFIX) === 0) {
         $categoryId = $category["id"];
         self::$currentCategory = $category;
         break;
         //}
     }
     if ($categoryId === null) {
         return $result;
     }
     // get products data
     $products = $api->get_products_by_category_id($categoryId);
     if (!$products) {
         return $result;
     }
     $products = self::filterSimilarProducts($currentProduct, $products, 3);
     // 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;
 }