/**
  * @param Varien_Controller_Action
  * @param Mage_Catalog_Model_Product
  */
 protected function doAddBoltPatterns($controller, Elite_Vaf_Model_Catalog_Product $product)
 {
     $VFproduct = new VF_Product();
     $VFproduct->setId($product->getId());
     $wheelProduct = new VF_Wheel_Catalog_Product($VFproduct);
     $wheelProduct->removeBoltPatterns();
     /** @todo get under test */
     if (isset($_FILES['boltpatterncsv']) && $_FILES['boltpatterncsv']['tmp_name'] && $_FILES['boltpatterncsv']['error'] == 0) {
         $importer = new VF_Wheel_Catalog_Product_Import($_FILES['boltpatterncsv']['tmp_name']);
         $importer->import();
     } else {
         $patterns = $controller->getRequest()->getParam('wheel_side_pattern') ? $controller->getRequest()->getParam('wheel_side_pattern') : $controller->getRequest()->getParam('multipatterns');
         $patterns = explode("\n", $patterns);
         foreach ($patterns as $k => $pattern) {
             $pattern = str_replace("\r", '', $pattern);
             if (!trim($pattern)) {
                 return;
             }
             $boltPattern = VF_Wheel_BoltPattern::create($pattern);
             if (!is_array($boltPattern)) {
                 $boltPattern = array($boltPattern);
             }
             foreach ($boltPattern as $each) {
                 $wheelProduct->addBoltPattern($each);
             }
         }
     }
 }
 function testIsNotUniversal()
 {
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId(1);
     $product->setUniversal(false);
     $this->assertFalse($product->isUniversal());
 }
 function product($sku)
 {
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId($this->productId($sku));
     $product = new Elite_Vafdiagram_Model_Catalog_Product($product);
     return $product;
 }
 function superProduct()
 {
     $superProductId = $this->getData('parent_id');
     $superProduct = new Elite_Vaf_Model_Catalog_Product();
     $superProduct->setId($superProductId);
     return $superProduct;
 }
 function product()
 {
     $productId = $this->insertProduct('sku');
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId($productId);
     Mage::register('current_product', $product);
     return $product;
 }
 function testMappingIdProductDifferent()
 {
     $vehicle = $this->createMMY();
     $mapping_id = $this->insertMappingMMY($vehicle, 2);
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId(1);
     $this->assertEquals(null, $product->getMappingId($vehicle), 'should return null if a product has no mappings');
 }
 function setShowInRelated($value)
 {
     $select = $this->getReadAdapter()->select()->from($this->wrappedProduct->getSchema()->mappingsTable(), array('count(*)'))->where('entity_id = ' . $this->getId());
     if (0 == $select->query()->fetchColumn() && $value) {
         $this->query(sprintf("\n                    REPLACE INTO\n                    `" . $this->wrappedProduct->getSchema()->mappingsTable() . "`\n                    (\n                    `related`,\n                    `entity_id`\n                    )\n                    VALUES\n                    (\n                    %d,\n                    %d\n                    )\n                    ", 1, (int) $this->getId()));
     }
     $this->query('UPDATE ' . $this->wrappedProduct->getSchema()->mappingsTable() . ' set related = ' . (int) $value . ' where entity_id = ' . (int) $this->getId());
 }
 /**
  * @param Varien_Controller_Action
  * @param Mage_Catalog_Model_Product
  */
 function doBindWheelSide($controller, Elite_Vaf_Model_Catalog_Product $product)
 {
     $VFproduct = new VF_Product();
     $VFproduct->setId($product->getId());
     $wheeladapterProduct = new VF_Wheeladapter_Catalog_Product($VFproduct);
     $pattern = $controller->getRequest()->getParam('wheel_side_pattern');
     if (!$pattern) {
         return $wheeladapterProduct->unsetWheelSideBoltPattern();
     }
     $boltPattern = VF_Wheel_BoltPattern::create($pattern);
     $wheeladapterProduct->setWheelSideBoltPattern($boltPattern);
 }
 function getProductsThatFit($vehicle_object)
 {
     $select = new VF_Select($this->getReadAdapter());
     $select->from($this->getSchema()->mappingsTable())->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;
 }
 function testShouldMakeSafeOperations()
 {
     $this->createVehicle(array('year'=>2000, 'make'=>'Ford', 'model'=>'F-150', 'engine'=>'1.6L'));
     $this->createVehicle(array('year'=>2000, 'make'=>'Ford', 'model'=>'F-150', 'engine'=>'1.8L'));
     
     $this->createVehicle(array('year'=>2001, 'make'=>'Ford', 'model'=>'F-150', 'engine'=>'1.6L'));
     // there is no 2001/Ford/F-150 with a 1.8L in this example
     
     $this->mappingsImport('sku, make, model, year, engine' . "\n" .
                           'sku,Ford,F-150,"2000,2001,2002",{{all}}');
     
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId($this->product_id);
     $fits = $product->getFits();
     
     $this->assertEquals( 3, count($fits), 'should not a non-existant vehicle even it is implied' );
 }
 function testUnbindBoltFromProduct()
 {
     $this->setRequestParams(array('wheel_side_pattern' => '4x114.3'));
     $binder = new Elite_Vafwheeladapter_Observer_WheelSideBinder();
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId(1);
     $event = $this->event($product);
     $binder->bindWheelSide($event);
     $this->setRequestParams(array('wheel_side_pattern' => ''));
     $binder = new Elite_Vafwheeladapter_Observer_WheelSideBinder();
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId(1);
     $event = $this->event($product);
     $binder->bindWheelSide($event);
     $wheeladapterProduct = new Elite_Vafwheeladapter_Model_Catalog_Product($product);
     $this->assertFalse($wheeladapterProduct->getWheelSideBoltPattern(), 'should unbind bolt pattern from product');
 }
 function export($stream)
 {
     fwrite($stream, '"sku","section_width","aspect_ratio","diameter"');
     fwrite($stream, "\n");
     foreach ($this->getProductRows() as $productRow) {
         $product = new Elite_Vaf_Model_Catalog_Product();
         $product->setId($productRow['entity_id']);
         $product = new Elite_Vaftire_Model_Catalog_Product($product);
         if ($product->getTireSize()) {
             $tireSize = $product->getTireSize();
             fwrite($stream, '"' . $productRow['sku'] . '",');
             fwrite($stream, '"' . $tireSize->sectionWidth() . '",');
             fwrite($stream, '"' . $tireSize->aspectRatio() . '",');
             fwrite($stream, '"' . $tireSize->diameter() . '"');
             fwrite($stream, "\n");
         }
     }
 }
 function testAddsAndRemovesBoltPattern()
 {
     $this->setRequestParams(array('multipatterns' => "4x114.3\n5x114.3"));
     $binder = new Elite_Vafwheel_Observer_ProductBoltBinder();
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId(1);
     $event = $this->event($product);
     $binder->addBoltPatterns($event);
     $wheelProduct = new Elite_Vafwheel_Model_Catalog_Product($product);
     $this->assertEquals(2, count($wheelProduct->getBoltPatterns()));
     $this->setRequestParams(array('wheel_side_pattern' => "4x114.3"));
     $binder = new Elite_Vafwheel_Observer_ProductBoltBinder();
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId(1);
     $event = $this->event($product);
     $binder->addBoltPatterns($event);
     $wheelProduct = new Elite_Vafwheel_Model_Catalog_Product($product);
     $this->assertEquals(1, count($wheelProduct->getBoltPatterns()), 'removes previously added bolt patterns');
 }
    function testBlowoutMultipleColumn()
    {
        $this->importVehiclesList($this->vehiclesList);
        $this->mappingsImport('sku, make, model, year
sku, honda, {{all}}, {{all}}');
        
        $product = new Elite_Vaf_Model_Catalog_Product();
        $product->setId($this->product_id);
        $fits = $product->getFits();
        
        $this->assertEquals( 3, count($fits), 'should blow out options' );
        $this->assertEquals( 'civic', $fits[0]->model );
        
        $this->assertEquals( 'accord', $fits[1]->model );
        $this->assertEquals( '2000', $fits[1]->year );
        
        $this->assertEquals( 'accord', $fits[2]->model );
        $this->assertEquals( '2001', $fits[2]->year );
        
    }
 /**
  * @var integer product id
  * @var mixed boolean false for universal, or Elite_Vaf_Model_Vehicle to create a mapping for
  */
 function insertMapping($row, $vehicle)
 {
     $sku = $this->sku($row);
     $productId = $this->productId($sku);
     if (!$productId) {
         $this->skipped_mappings++;
         return;
     }
     if ($this->isUniversal($row)) {
         $product = new Elite_Vaf_Model_Catalog_Product();
         $product->setId($productId);
         $product->setUniversal(1);
         return;
     }
     if (false === $vehicle) {
         $this->invalid_vehicle_count++;
         $this->skipped_mappings++;
         return;
     }
     $mapping = new Elite_Vaf_Model_Mapping($productId, $vehicle);
     if ($this->hasMapping($productId, $vehicle)) {
         $this->already_existing_mappings++;
         $this->skipped_mappings++;
         return $mapping->save();
     }
     $mapping_id = $mapping->save();
     if (!$mapping_id) {
         $this->skipped_mappings++;
     } else {
         $this->added_mappings++;
     }
     return $mapping_id;
 }
 protected function getProduct($Id)
 {
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId($Id);
     return $product;
 }
 protected function snippet($product_id)
 {
     // begin fitment fitment notes
     $noteFinder = new VF_Note_Finder();
     $vehicle = VF_Singleton::getInstance()->vehicleSelection()->getFirstVehicle();
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId($product_id);
     if (null == $vehicle) {
         echo 'Select a vehicle to view fitment notes';
     } else {
         if ($product->isUniversal()) {
             echo 'Product is universal and has no fitment notes';
         } else {
             $mapping_id = $product->getMappingId($vehicle);
             $notes = $noteFinder->getNotes($mapping_id);
             foreach ($notes as $note) {
                 echo $note->message . ' <br />';
             }
             if (!count($notes)) {
                 echo 'There are no notes for your vehicle (' . $vehicle->__toString() . ')';
             }
         }
     }
     // end fitment fitment notes
 }
 function testSetDataShouldWorkWithNoID()
 {
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setData(array());
 }
 function applyName(Elite_Vaf_Model_Catalog_Product $product)
 {
     if ($this->shouldApplyName()) {
         $product->setCurrentlySelectedFit($this->getFit());
     }
 }
 function getProductForSku($sku)
 {
     $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();
     $product = new Elite_Vaf_Model_Catalog_Product();
     $product->setId($product_id);
     return $product;
 }
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
session_start();
if (file_exists('../config.php')) {
    require_once '../config.php';
} else {
    require_once '../config.default.php';
}
require_once getenv('PHP_MAGE_PATH') . '/app/code/local/Elite/Vaf/bootstrap-tests.php';
$schemaGenerator = new VF_Schema_Generator();
$schemaGenerator->dropExistingTables();
$schemaGenerator->execute(array('make', 'model', 'year'));
$schema = new VF_Schema();
$vehicle = VF_Vehicle::create($schema, array('make' => 'Honda_Unique' . uniqid(), 'model' => 'Civic', 'year' => '2002'));
$vehicle->save();
$magento_product = new Elite_Vaf_Model_Catalog_Product();
$magento_product->setId(1);
$magento_product->addVafFit($vehicle->toValueArray());
$values = $vehicle->toValueArray();
file_put_contents(sys_get_temp_dir() . '/vf-ajax-tests', '1');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <link rel="stylesheet" href="../qunit/qunit.css" type="text/css"/>
    <link rel="stylesheet" href="/skin/adminhtml/default/default/multiTree.css" type="text/css"/>
  </head>
  <body>
    <h1 id="qunit-header">VAF - Multi Tree</h1>
    <h2 id="qunit-banner"></h2>