Example #1
0
 function getProductsThatFit($vehicle_object)
 {
     $select = new Elite_Vaf_Select($this->getReadAdapter());
     $select->from('elite_mapping')->whereLevelIdsEqual($vehicle_object->toValueArray());
     $result = $select->query()->fetchAll();
     $products = array();
     foreach ($result as $row) {
         $product = new Elite_Vaf_Model_Catalog_Product();
         $product->setId($row['entity_id']);
         array_push($products, $product);
     }
     return $products;
 }
Example #2
0
 /**
  * @param array conjunction of critera Ex: array('make'=>1'year'=>1)
  * @return array of Vehicle that meet the critera
  */
 function findByLevelIds($levelIds, $mode = false)
 {
     $levelsToSelect = array();
     foreach ($this->schema->getLevels() as $level) {
         if (self::EXACT_ONLY == $mode) {
             $value = 0;
         } else {
             $value = false;
         }
         $value = isset($levelIds[$level]) ? $levelIds[$level] : $value;
         $value = isset($levelIds[$level . '_id']) ? $levelIds[$level . '_id'] : $value;
         unset($levelIds[$level . '_id']);
         $levelIds[$level] = $value;
         if (self::EXACT_ONLY == $mode && !$levelIds[$level]) {
             continue;
         }
         array_push($levelsToSelect, $level);
     }
     $select = new Elite_Vaf_Select($this->getReadAdapter());
     $select->from('elite_definition')->addLevelTitles('elite_definition', $levelsToSelect);
     foreach ($this->schema->getLevels() as $level) {
         $value = false;
         $value = isset($levelIds[$level]) ? $levelIds[$level] : $value;
         $value = isset($levelIds[$level . '_id']) ? $levelIds[$level . '_id'] : $value;
         if ($value != false) {
             $level = str_replace(' ', '_', $level);
             $select->where('`elite_definition`.`' . $level . '_id` = ?', $value);
         }
     }
     if (self::INCLUDE_PARTIALS != $mode) {
         foreach ($this->schema->getLevels() as $level) {
             if (self::EXACT_ONLY != $mode || isset($levelIds[$level]) && $levelIds[$level]) {
                 $level = str_replace(' ', '_', $level);
                 $select->where('elite_definition.' . $level . '_id != 0');
             }
         }
     }
     $result = $this->query($select)->fetchAll(Zend_Db::FETCH_OBJ);
     $return = array();
     foreach ($result as $row) {
         foreach ($this->schema->getLevels() as $level) {
             if (self::EXACT_ONLY == $mode && !in_array($level, $levelsToSelect) && $row->{$level . '_id'}) {
                 foreach ($this->schema->getNextLevelsIncluding($level) as $level) {
                     $row->{$level . '_id'} = 0;
                     $row->{$level} = '';
                 }
                 $vehicle = new Elite_Vaf_Model_Vehicle($this->schema, $row->id, $row);
                 return array($vehicle);
             }
             if ((!isset($levelIds[$level]) || !$levelIds[$level]) && $mode) {
                 $row->{$level . '_id'} = 0;
                 $row->{$level} = '';
             }
             if (isset($levelIds[$level]) && !$levelIds[$level] && $row->{$level . '_id'}) {
                 continue;
             }
             if ((!$mode || self::EXACT_ONLY == $mode) && (!isset($levelIds[$level]) || !$levelIds[$level]) && !$row->{$level . '_id'}) {
                 continue;
             }
         }
         $vehicle = new Elite_Vaf_Model_Vehicle($this->schema, $row->id, $row);
         array_push($return, $vehicle);
     }
     return $return;
 }
 protected function doGetFits($productId)
 {
     $select = new Elite_Vaf_Select($this->getReadAdapter());
     $select->from('elite_mapping')->addLevelTitles()->where('entity_id=?', $productId);
     $result = $this->query($select);
     $fits = array();
     while ($row = $result->fetchObject()) {
         if ($row->universal) {
             continue;
         }
         $fits[] = $row;
     }
     return $fits;
 }