protected function rowResult()
    {
	$this->getReadAdapter()->getConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
	$select = $this->getReadAdapter()->select()
			->from($this->schema()->mappingsTable(), array('id', 'universal'));
	foreach ($this->schema->getLevels() as $level)
	{
	    $levelTable = $this->schema()->levelTable($level);
	    $condition = sprintf('%s.id = '.$this->schema()->mappingsTable().'.%s_id', $levelTable, $level);
	    $select->joinLeft($levelTable, $condition, array($level => 'title'));
	}
	$select->joinLeft(array('p' => $this->getProductTable()), 'p.entity_id = '.$this->schema()->mappingsTable().'.entity_id', array('sku'));
	return $this->query($select);
    }
 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 )
         {
         }
     }
 }
 function testShouldGetSchemaById()
 {
     $schema = VF_Schema::create('foo,bar');
     $schemaID = $schema->id();
     $new_schema = new VF_Schema($schemaID);
     $this->assertEquals(array('foo', 'bar'), $new_schema->getLevels(), 'should look up schema specified by ID passed to constructor');
 }
 function execute( VF_Schema $schema, $alphaNumeric=false )
 {
     $this->alphaNumeric = $alphaNumeric;
     $this->schema = $schema;
     
     $levels = $schema->getLevels();
     $c = count( $levels );
     
     $levelFinder = new VF_Level_Finder();
     if( isset( $_GET['front'] ) )
     {
         $product = isset($_GET['product']) ? $_GET['product'] : null;
         if($alphaNumeric)
         {
             $children = $levelFinder->listInUseByTitle( 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 run()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_level_' . str_replace(' ', '_', $level) . '` ADD INDEX ( `title` )   ');
     }
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_mapping` ADD INDEX ( `entity_id` ) ;');
     }
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = VF_Singleton::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_product_wheel` ADD `offset` FLOAT NOT NULL ');
         $db->query('ALTER TABLE `elite_definition_wheel` ADD `offset` FLOAT NOT NULL ');
     }
 }
Esempio n. 8
0
 function testShouldAddSecondSchema()
 {
     $command = __DIR__ . '/vf schema --force --levels="year,make,model"';
     exec($command);
     $command = __DIR__ . '/vf schema --add --levels="foo,bar"';
     exec($command);
     $schema = new VF_Schema(2);
     $this->assertEquals(array('foo', 'bar'), $schema->getLevels(), 'should create second schema');
 }
 function setSortingLevels()
 {
     $schema = new VF_Schema();
     foreach ($schema->getLevels() as $level) {
         if (isset($_GET[$level . 'Sorting'])) {
             $this->generator()->setSorting($level, $_GET[$level . 'Sorting']);
         }
     }
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $old = 'elite_' . $level;
         $new = 'elite_level_' . $level;
         $db->query(sprintf("RENAME TABLE %s TO %s", $old, $new));
     }
 }
 function testShouldSetSchema()
 {
     $schemaGenerator = new VF_Schema_Generator();
     $schemaGenerator->dropExistingTables();
     VF_Schema::$levels = null;
     $command = __DIR__ . '/vfmagento schema --force --levels="year,make,model"';
     exec($command);
     $schema = new VF_Schema();
     $this->assertEquals(array('year', 'make', 'model'), $schema->getLevels(), 'should create default schema of MMY');
 }
 function testOneQueryAcrossInstances()
 {
     $this->getReadAdapter()->getProfiler()->clear();
     $this->getReadAdapter()->getProfiler()->setEnabled(true);
     $schema = new VF_Schema();
     $schema->getLevels();
     $schema = new VF_Schema();
     $schema->getLevels();
     $queries = $this->getReadAdapter()->getProfiler()->getQueryProfiles();
     $this->assertEquals(1, count($queries));
 }
 function addUniqueOnDefinitions()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     $levels = array();
     foreach ($schema->getLevels() as $level) {
         $levels[] = sprintf('`%s_id`', $level);
     }
     $levels = implode(',', $levels);
     $query = "ALTER TABLE `elite_definition` ADD UNIQUE ( %s );";
     $db->query(sprintf($query, $levels));
 }
 function levels()
 {
     $params = $this->getRequest()->getParam('vehicle');
     $params = explode("-", $params);
     $schema = new VF_Schema();
     $levels = array();
     foreach ($schema->getLevels() as $level) {
         $levels[$level] = current($params);
         next($params);
     }
     return $levels;
 }
    function save()
    {
        if (!(int) $this->product_id)
        {
            throw new Exception('Trying to insert a mapping with no product ID');
        }
        $schema = new VF_Schema;
        $schema->setConfig($this->getConfig());
        $levels = $schema->getLevels();

        $select = $this->getReadAdapter()->select()
                        ->from($schema->mappingsTable(), array('id'));
        foreach ($this->vehicle->toValueArray() as $level => $id)
        {
            $select->where($this->inflect($level) . '_id = ?', $id);
        }
        $select->where('entity_id = ?', $this->product_id);

        $id = (int) $select->query()->fetchColumn();
        if (0 !== $id)
        {
            return $id;
        }

        $columns = '';
        $values = '';
        foreach ($levels as $level)
        {
            $columns .= '`' . $this->inflect($level) . '_id`,';
            $values .= $this->inflect($this->vehicle->getLevel($level)->getId());
            $values .= ',';
        }
        $query = sprintf(
                        '
            INSERT INTO
                `'.$schema->mappingsTable().'`
            (
                ' . $columns . '
                `entity_id`
            )
            VALUES
            (
                ' . $values . '
                %d
            )
            ',
            (int) $this->product_id
        );
        $r = $this->query($query);
        return $this->getReadAdapter()->lastInsertId();
    }
Esempio n. 16
0
 public function indexAction()
 {
     try {
         $schema = new \VF_Schema();
         $levels = $schema->getLevels();
     } catch (\Zend_Db_Statement_Exception $e) {
         $levels = array();
     }
     if ($this->getRequest()->isPost()) {
         $schemaGenerator = new \VF_Schema_Generator();
         $schemaGenerator->dropExistingTables();
         $schemaGenerator->execute(explode(",", $_POST['schema']));
         $this->flashMessenger()->setNamespace('success')->addMessage('Saved Schema');
     }
     return array('schema' => $levels);
 }
Esempio n. 17
0
 function productmanageAction()
 {
     $schema = new \VF_Schema();
     $product = new \VF_Product();
     $product->setId($this->params()->fromRoute('id'));
     if ($this->getRequest()->isPost()) {
         $this->removeFitments($product);
         $this->updateUniversal($product);
         //$this->updateRelated($product);
         $this->addNewFitments($product);
         $this->flashMessenger()->addSuccessMessage('Produt\'s fitments saved');
     }
     $view = new ViewModel(array('fitments' => $product->getFits(), 'product' => $product, 'schema' => $schema->getLevels()));
     $view->setTemplate('fitments/index/multitree.phtml');
     return $view;
 }
Esempio n. 18
0
 protected function switchSchema($levels, $force = false)
 {
     if (!$force) {
         try {
             $schema = new VF_Schema();
             if ($levels == implode(',', $schema->getLevels())) {
                 $this->startTransaction();
                 return;
             }
         } catch (Zend_Db_Statement_Mysqli_Exception $e) {
         } catch (Zend_Db_Statement_Exception $e) {
         }
     }
     $schemaGenerator = new VF_Schema_Generator();
     $schemaGenerator->dropExistingTables();
     $schemaGenerator->execute(explode(',', $levels));
     VF_Schema::reset();
     $this->startTransaction();
 }
 function selectionPart()
 {
     $vehicleSelection = Elite_Vaf_Helper_Data::getInstance()->vehicleSelection();
     if ($vehicleSelection->isEmpty()) {
         return false;
     }
     if ($this->getConfig()->logo->level) {
         $level = $this->getConfig()->logo->level;
         return $vehicleSelection->getLevel($level)->__toString();
     }
     $schema = new VF_Schema();
     if (in_array('make', $schema->getLevels())) {
         $make = $vehicleSelection->getLevel('make');
         if (!$make) {
             return false;
         }
         return $make->__toString();
     }
     $rootLevel = $schema->getRootLevel();
     return $vehicleSelection->getLevel($rootLevel)->__toString();
 }
Esempio n. 20
0
 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);
 }
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Vehicle Fits to newer
 * versions in the future. If you wish to customize Vehicle Fits for your
 * needs please refer to http://www.vehiclefits.com for more information.
 * @copyright  Copyright (c) 2013 Vehicle Fits, llc
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
$query = "CREATE TABLE `elite_schema` (\n`key` VARCHAR( 25 ) NOT NULL ,\n`value` VARCHAR( 255 ) NOT NULL\n) ENGINE = InnoDB;";
$db->query($query);
$schema = new VF_Schema();
$levels = $schema->getLevels();
if (!count($levels)) {
    $levels = array('make', 'model', 'year');
}
foreach ($levels as $level) {
    if (!trim($level)) {
        $levels = array('make', 'model', 'year');
    }
}
$db->insert('elite_schema', array('key' => 'levels', 'value' => implode(',', $levels)));
Esempio n. 22
0
 protected function getLevels()
 {
     return $this->schema->getLevels();
 }
Esempio n. 23
0
 function getLevels()
 {
     $schema = new VF_Schema();
     $schema->setConfig($this->getConfig());
     return $schema->getLevels();
 }
Esempio n. 24
0
 /**
  * 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;
 }
 function testLevels()
 {
     $schema = new VF_Schema();
     $this->assertEquals( array('make','model type','year'), $schema->getLevels(), 'should allow spaces in level name' );
 }
 /** @todo move to importer model */
 protected function formatMessages()
 {
     $schema = new VF_Schema();
     $this->formatMessage('<strong>Vehicles List Import Results</strong>');
     $this->formatMessage(number_format($this->importer->getCountAddedVehicles()) . ' Vehicles Added');
     foreach ($schema->getLevels() as $level) {
         $this->formatMessage(number_format($this->importer->getCountAddedByLevel($level)) . ' ' . $level . 's Added');
     }
     //        if( $this->importer->getCountSkippedDefinitions() > 0 )
     //        {
     //            $this->formatMessage( number_format( $this->importer->getCountSkippedDefinitions() ) . ' vehicles skipped because they already existed, your csv contained overlapping ranges or duplicate vehicles.' );
     //        }
     $this->doFormatMessages();
 }
 function testLevels()
 {
     $schema = new VF_Schema();
     $this->assertEquals(array('make', 'model', 'version'), $schema->getLevels(), 'should get levels');
 }
Esempio n. 28
0
 public static function getJoins()
 {
     $joins = '';
     $schema = new VF_Schema();
     $levels = $schema->getLevels();
     $c = count($levels);
     for ($i = 0; $i <= $c - 1; $i++) {
         $joins .= sprintf('
             LEFT JOIN
                 `elite_%1$s`
             ON
                 `elite_%1$s`.`id` = `".$this->getSchema()->mappingsTable()."`.`%1$s_id`
             ', $levels[$i]);
     }
     return $joins;
 }
 function testLevelsMMOY()
 {
     $schema = new VF_Schema();
     $this->assertEquals(array('make', 'model', 'option', 'year'), $schema->getLevels(), 'should get levels MMOY');
 }
 function testLevelsFB()
 {
     $schema = new VF_Schema();
     $this->assertEquals(array('foo', 'bar'), $schema->getLevels(), 'should get levels FB');
 }