Ejemplo 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;
 }
Ejemplo n.º 2
0
<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('ABSOLUTE_PATH', dirname(__FILE__));
define('RELATIVE_PATH', 'modules' . DS . 'mod_ecwid_similarproducts');
define('JPATH_BASE', str_replace(RELATIVE_PATH, "", ABSOLUTE_PATH));
require_once JPATH_BASE . DS . 'includes' . DS . 'defines.php';
require_once JPATH_BASE . DS . 'includes' . DS . 'framework.php';
require_once dirname(__FILE__) . DS . 'helper.php';
$rokecwidPath = JPATH_SITE . DS . 'components' . DS . 'com_rokecwid' . DS . 'helpers';
require_once $rokecwidPath . DS . 'ecwid_product_api.php';
require_once $rokecwidPath . DS . 'ecwid_catalog.php';
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
modEcwidSimilarProducts::init();
$productId = JRequest::getVar("product");
$products = modEcwidSimilarProducts::getProducts($productId);
$productsTable = modEcwidSimilarProducts::getTable($products);
$category = modEcwidSimilarProducts::$currentCategory;
$tmpu = parse_url($category["url"]);
$category["url"] = modEcwidSimilarProducts::$siteCatalogPath . "#" . $tmpu["fragment"];
require dirname(__FILE__) . DS . 'tmpl' . DS . 'products.php';
<?php

// no direct access
defined('_JEXEC') or die('Restricted access');
require_once dirname(__FILE__) . DS . 'helper.php';
$rokecwidPath = JPATH_SITE . DS . 'components' . DS . 'com_rokecwid' . DS . 'helpers';
if (!file_exists($rokecwidPath . DS . 'ecwid_catalog.php') || !file_exists($rokecwidPath . DS . 'ecwid_product_api.php')) {
    print "Need rokecwid component api files (ecwid_catalog.php, ecwid_product_api.php)\n    for this module";
} else {
    modEcwidSimilarProducts::init();
    modEcwidSimilarProducts::addCustomHeaders();
    $modulePath = modEcwidSimilarProducts::$path;
    $basePath = JURI::base();
    $storeId = modEcwidSimilarProducts::$storeId;
    require JModuleHelper::getLayoutPath('mod_ecwid_similarproducts');
}