protected function saveLeafLevels() { $schema = new VF_Schema(); $select = $this->getReadAdapter()->select() ->from( 'elite_' . $schema->getLeafLevel() ); $result = $select->query(); $vehicleFinder = new VF_Vehicle_Finder( $schema ); while( $row = $result->fetchObject() ) { $vehicle = $vehicleFinder->findByLeaf( $row->id ); $bind = array(); foreach( $schema->getLevels() as $level ) { $bind[ $level . '_id' ] = $vehicle->getLevel( $level )->getId(); } try { $this->getReadAdapter()->insert( 'elite_definition', $bind ); } catch( Exception $e ) { } } }
/** * @deprecated */ function getFitForSku($sku, $schema = null) { if (is_null($schema)) { $schema = new VF_Schema; } $sql = sprintf( "SELECT `entity_id` from `test_catalog_product_entity` WHERE `sku` = %s", $this->getReadAdapter()->quote($sku) ); $r = $this->query($sql); $product_id = $r->fetchColumn(); $r->closeCursor(); $sql = sprintf( "SELECT `%s_id` from `elite_1_mapping` WHERE `entity_id` = %d AND `universal` = 0", $schema->getLeafLevel(), $product_id ); $r = $this->query($sql); $leaf_id = $r->fetchColumn(); $r->closeCursor(); if (!$leaf_id) { return false; } $finder = new VF_Vehicle_Finder($schema); return $finder->findByLeaf($leaf_id); }
function testVehicleExists() { return $this->markTestIncomplete(); $schema = VF_Schema::create('foo,bar'); $finder = new VF_Vehicle_Finder($schema); $this->assertFalse($finder->vehicleExists(array('foo'=>'test','bar'=>'doesntexist')), 'vehicle should not exist'); }
function testDoesNotImportBlankDefinition() { $this->mappingsImport('sku, make, model, year, universal "sku","","","","1"'); $vehicleFinder = new VF_Vehicle_Finder(new VF_Schema()); $vehicles = $vehicleFinder->findAll(); $this->assertEquals(0, count($vehicles)); }
function test2() { $this->importVehiclesList('make, model, year honda, ci-vic, 2000 honda, ci-vic, 2001'); $finder = new VF_Vehicle_Finder(new VF_Schema()); $vehicles = $finder->findByLevels(array('make' => 'honda', 'model' => 'ci-vic', 'year' => '2001')); $this->assertEquals(1, count($vehicles)); }
/** @todo move/rename this to definition finder -> find all in use() method */ function getDefinitions($perPage = false, $offset = false, $productId = null) { $return = array(); $vehicleFinder = new VF_Vehicle_Finder($this->getSchema()); $vehicles = $this->doGetDefinitions($perPage, $offset, $productId); foreach ($vehicles as $vehicleStdClass) { $vehicle = $vehicleFinder->findOneByLevelIds($vehicleStdClass, VF_Vehicle_Finder::EXACT_ONLY); array_push($return, $vehicle); } return $return; }
function testComma() { $importer = $this->vehiclesListImporter('"make", "model", "year" "honda", "accord,civic", "2000,2003"'); $importer->import(); $vehicleFinder = new VF_Vehicle_Finder(new VF_Schema()); $vehicles = $vehicleFinder->findByLevels(array('make' => 'honda')); $this->assertEquals(4, count($vehicles), 'should enumerate out options'); $this->assertEquals('honda accord 2000', $vehicles[0]->__toString()); $this->assertEquals('honda accord 2003', $vehicles[1]->__toString()); $this->assertEquals('honda civic 2000', $vehicles[2]->__toString()); $this->assertEquals('honda civic 2003', $vehicles[3]->__toString()); }
function testFindByLeaf() { $vehicle = $this->createMMY(); $yearId = $vehicle->getValue('year'); $finder = new VF_Vehicle_Finder(new VF_Schema()); $this->getReadAdapter()->getProfiler()->clear(); $this->getReadAdapter()->getProfiler()->setEnabled(true); $finder->findByLeaf($yearId); $finder->findByLeaf($yearId); $finder->findByLeaf($yearId); $finder->findByLeaf($yearId); $queries = $this->getReadAdapter()->getProfiler()->getQueryProfiles(); $this->assertTrue(count($queries) <= 2); }
function getDefinitions() { VF_Singleton::getInstance()->storeFitInSession(); if ($this->lastLevelAlreadySelected()) { return array(); } $vehicles = array(); $vehicleFinder = new VF_Vehicle_Finder($this->getSchema()); foreach ($this->getItems() as $level) { $vehicle = $vehicleFinder->findByLevel($level->getType(), $level->getId()); array_push($vehicles, $vehicle); } return $vehicles; }
function explode($input) { $this->input = $input; if (!$this->hasWildCards()) { return array($input); } $this->result = array(); $this->i = 0; $this->replaceAllWithWildcard(); $result = array(); $finder = new VF_Vehicle_Finder($this->getSchema()); foreach ($finder->findByLevels($this->input) as $vehicle) { array_push($result, $vehicle->toTitleArray()); } return $result; }
protected function saveLeafLevels() { $schema = VF_Singleton::getInstance()->schema(); $select = $this->getReadAdapter()->select()->from('elite_' . $schema->getLeafLevel()); $result = $select->query(); $vehicleFinder = new VF_Vehicle_Finder($schema); foreach ($result->fetchAll(Zend_Db::FETCH_OBJ) as $row) { $vehicle = $vehicleFinder->findByLeaf($row->id); $bind = array(); foreach ($schema->getLevels() as $level) { $bind[$level . '_id'] = $vehicle->getLevel($level)->getId(); } try { $this->getReadAdapter()->insert('elite_definition', $bind); } catch (Exception $e) { } } }
function saveAction() { $dataToSave = $this->requestLevels(); $vehiclesFinder = new \VF_Vehicle_Finder(new \VF_Schema()); $vehicle = $vehiclesFinder->findOneByLevelIds($dataToSave, \VF_Vehicle_Finder::INCLUDE_PARTIALS); if ($vehicle) { $dataToSave = $vehicle->toTitleArray(); } else { $dataToSave = array(); } $dataToSave[$this->params()->fromQuery('entity')] = $this->params()->fromQuery('title'); $vehicle = \VF_Vehicle::create(new \VF_Schema(), $dataToSave); $vehicle->save(); if (1 || $this->getRequest()->isXmlHttpRequest()) { echo $vehicle->getValue($this->params()->fromQuery('entity')); exit; } }
function execute(VF_Schema $schema) { $this->legacyNumericSearch = (bool) $this->getConfig()->search->legacyNumericSearch; $this->schema = $schema; $levels = $schema->getLevels(); $c = count($levels); $levelFinder = new VF_Level_Finder($schema); /** @var VF_Level_Finder|VF_Level_Finder_Selector $levelFinder */ if (isset($_GET['front'])) { $product = isset($_GET['product']) ? $_GET['product'] : null; if (!$this->legacyNumericSearch) { if ($this->shouldListAll()) { $levelsToSelect = array($this->requestLevel()); $where = $this->requestLevels(); $vehicleFinder = new VF_Vehicle_Finder($schema); $vehicles = $vehicleFinder->findDistinct($levelsToSelect, $where); $children = array(); foreach ($vehicles as $vehicle) { /** @var VF_Vehicle $vehicle */ array_push($children, $vehicle->getLevel($this->requestLevel())); } } else { $children = $levelFinder->listInUseByTitle(new VF_Level($this->requestLevel()), $this->requestLevels(), $product); } } else { if ($this->shouldListAll()) { $children = $levelFinder->listAll(new VF_Level($this->requestLevel()), $this->requestLevels(), $product); } else { $children = $levelFinder->listInUse(new VF_Level($this->requestLevel()), $this->requestLevels(), $product); } } } else { $children = $levelFinder->listAll($this->requestLevel(), $this->requestLevels()); } echo $this->renderChildren($children); }
function vehicle($vehicleID) { $vehicleFinder = new VF_Vehicle_Finder(new VF_Schema()); return $vehicleFinder->findById($vehicleID); }
function save() { $bind = array(); foreach ($this->getLevelObjs() as $level) { if (!$level->getTitle()) { $bind[$level->getType() . '_id'] = 0; continue; } $level->save(null, null, false); $bind[str_replace(' ', '_', $level->getType()) . '_id'] = $level->getId(); $bind[str_replace(' ', '_', $level->getType())] = $level->getTitle(); } $finder = new VF_Vehicle_Finder($this->schema); if ($finder->vehicleExists($this->toTitleArray())) { $vehicle = $finder->findOneByLevels($this->toTitleArray()); return $this->row->id = $vehicle->getId(); } // doesnt exist, insert it $insertAdapter = new VF_Db_Adapter_InsertWrapper($this->getReadAdapter()); $insertAdapter->insert($this->schema()->definitionTable(), $bind); $this->row->id = $this->getReadAdapter()->lastInsertId(); }
function getFlexibleDefinition() { $this->storeFitInSession(); try { $level = $this->getLevel(); $selectedVehicles = $this->vehicleSelection(); if (!count($selectedVehicles)) { return false; } $selectedVehicle = $selectedVehicles[0]; $levelObj = $selectedVehicle->getLevel($level); if (!$level || !$levelObj || !$levelObj->getId()) { return false; } $vehicleFinder = new VF_Vehicle_Finder($this->schema()); $vehicle = $vehicleFinder->findOneByLevelIds($this->vehicleRequestParams()); } catch (VF_Exception_DefinitionNotFound $e) { return false; } return $vehicle; }
function saveAction() { $schema = new VF_Schema($this->getRequest()->getParam('schema')); $dataToSave = $this->requestLevels(); $vehiclesFinder = new VF_Vehicle_Finder($schema); $vehicle = $vehiclesFinder->findOneByLevelIds($dataToSave, VF_Vehicle_Finder::INCLUDE_PARTIALS); if ($vehicle) { $dataToSave = $vehicle->toTitleArray(); } else { $dataToSave = array(); } $dataToSave[$this->getRequest()->getParam('entity')] = $this->getRequest()->getParam('title'); $vehicle = VF_Vehicle::create($schema, $dataToSave); $vehicle->save(); if ($this->getRequest()->isXmlHttpRequest()) { echo $vehicle->getValue($this->getRequest()->getParam('entity')); exit; } $this->doSave(); }
function findVehicleByLevelsMMOY($make, $model, $option, $year) { $vehicleFinder = new VF_Vehicle_Finder(new VF_Schema()); return $vehicleFinder->findOneByLevels(array('make' => $make, 'model' => $model, 'option' => $option, 'year' => $year)); }
/** * Create duplicate * * @return Mage_Catalog_Model_Product */ function duplicate() { $schema = new VF_Schema(); $vehicleFinder = new VF_Vehicle_Finder($schema); $leaf = $schema->getLeafLevel() . '_id'; $newProduct = parent::duplicate(); foreach ($this->getFits() as $fit) { // 2.x has a bug that it inserts blank fitments, which prevents duplicating products here. Simple workaround for 2.x if (!$fit->{$leaf}) { continue; } $levelIDs = array(); foreach ($schema->getLevels() as $level) { $levelIDs[$level . '_id'] = $fit->{$level . '_id'}; } $vehicle = $vehicleFinder->findOneByLevelIds($levelIDs); if (is_object($vehicle)) { $newProduct->insertMapping($vehicle); } } if ($this->isUniversal()) { $newProduct->setUniversal(true); } return $newProduct; }
/** * @param Elite_Vaf_Model_Abstract - if is an "aggregrate" of fits ( iterate and add it's children ) */ function doAddFit($entity) { $vehicleFinder = new VF_Vehicle_Finder(new VF_Schema()); $params = array($entity->getType() => $entity->getTitle()); $vehicles = $vehicleFinder->findByLevels($params); return $vehicles; }
function getFlexibleDefinition() { $this->storeFitInSession(); try { $level = $this->getLevel(); $vehicle = $this->vehicleSelection(); if (!$vehicle) { return false; } $levelObj = $vehicle->getLevel($level); if (!$level || !$levelObj || !$levelObj->getId()) { return false; } $vehicleFinder = new VF_Vehicle_Finder($this->schema()); $vehicle = $vehicleFinder->findOneByLevelIds($this->getRequestValues()); } catch (Elite_Vaf_Exception_DefinitionNotFound $e) { return false; } return $vehicle; }
function definition($vehicle_id) { $vehicleFinder = new VF_Vehicle_Finder(new VF_Schema()); return $vehicleFinder->findById($vehicle_id); }
/** * Create duplicate * * @return Mage_Catalog_Model_Product */ function duplicate() { $schema = new VF_Schema(); $vehicleFinder = new VF_Vehicle_Finder($schema); $leaf = $schema->getLeafLevel() . '_id'; $newProduct = parent::duplicate(); foreach ($this->getFits() as $fit) { $vehicle = $vehicleFinder->findByLeaf($fit->{$leaf}); $newProduct->insertMapping($vehicle); } if ($this->isUniversal()) { $newProduct->setUniversal(true); } return $newProduct; }