Example #1
0
 /**
  * Search products  
  * 
  * @param string $needed
  * @param integer $locale
  * @return ArrayObject
  */
 public static function search($needed, $locale = 1, $retarray = TRUE)
 {
     $data = array();
     $dq = Doctrine_Query::create()->select('p.*, pag.code as groupcode, pd.name as name, pd.shortdescription as shortdescription, pd.metakeywords as keywords, pm.path as imgpath')->from('Products p')->leftJoin("p.ProductsData pd WITH pd.language_id = {$locale}")->leftJoin("p.ProductsMedia pm")->leftJoin("p.ProductsAttributesGroups pag")->where("pd.name like ? and p.enabled = ?", array("%{$needed}%", 1))->orWhere("pd.shortdescription like ?", "%{$needed}%")->orWhere("pd.description like ?", "%{$needed}%")->orWhere("pd.metakeywords like ?", "%{$needed}%")->addWhere("p.isp_id = ?", Isp::getCurrentId());
     if ($retarray) {
         $data = $dq->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     } else {
         // Create the pagination of the records
         $dq = self::pager($dq, 5);
         // Execute the query
         $products = $dq->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
         foreach ($products as $product) {
             $product['reviews'] = Reviews::countItems($product['product_id']);
             // Add the total of the reviews for each product
             $data['records'][] = ProductsData::checkTranslation($product);
             // Check the product data translation text
         }
         // Get the pager object
         $data['pager'] = $dq->display(null, true);
     }
     return $data;
 }
Example #2
0
 /**
  * Get a list ready of producs using the category Uri
  * @return array
  */
 public static function getProductListbyCatUri($uri, $fields = "*", $locale = 1, $rows = 8)
 {
     $data = array();
     $isp_id = Shineisp_Registry::get('ISP')->isp_id;
     $locale = intval($locale);
     $rows = intval($rows);
     //$category = Doctrine::getTable ( 'ProductsCategories' )->findBy ( 'uri', $uri, Doctrine_Core::HYDRATE_ARRAY );
     $category = Doctrine_Query::create()->select('category_id')->from('ProductsCategories')->where('isp_id = ?', $isp_id)->addWhere('uri = ?', $uri)->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     $category = is_array($category) ? array_shift($category) : null;
     $category_id = isset($category['category_id']) ? intval($category['category_id']) : 0;
     if ($category_id) {
         $dq = Doctrine_Query::create()->select($fields)->from('Products p')->leftJoin("p.ProductsData pd WITH pd.language_id = " . $locale)->leftJoin("p.ProductsAttributesGroups pag")->where('p.enabled = ?', 1)->addWhere('p.isp_id = ?', $isp_id)->andWhere("(categories LIKE '" . $category_id . "/%' OR categories LIKE '%/" . $category_id . "' OR categories LIKE '%/" . $category_id . "/%' OR categories = '{$category_id}')")->orderBy('position asc');
         $dq = self::pager($dq, $rows);
         $products = $dq->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
         foreach ($products as $product) {
             $categories = explode("/", $product['categories']);
             if (in_array($category_id, $categories)) {
                 $data['records'][] = ProductsData::checkTranslation($product);
                 // Check the product data translation text
             }
         }
         $data['pager'] = $dq->display(null, true);
     }
     return $data;
 }