function testFindsMatchingProduct()
 {
     $bolt = Elite_Vafwheel_Model_BoltPattern::create('4x114.3');
     $product = $this->newWheelProduct(1);
     $product->addBoltPattern($bolt);
     $this->assertEquals(array(1), $this->wheelFinder()->getProductIds($bolt), 'should find products with this bolt pattern');
 }
 /**
  * @param Varien_Controller_Action
  * @param Mage_Catalog_Model_Product
  */
 protected function doAddBoltPatterns($controller, Elite_Vaf_Model_Catalog_Product $product)
 {
     $wheelProduct = new Elite_Vafwheel_Model_Catalog_Product($product);
     $wheelProduct->removeBoltPatterns();
     /** @todo get under test */
     if (isset($_FILES['boltpatterncsv']) && $_FILES['boltpatterncsv']['tmp_name'] && $_FILES['boltpatterncsv']['error'] == 0) {
         $importer = new Elite_Vafwheel_Model_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 = Elite_Vafwheel_Model_BoltPattern::create($pattern);
             if (!is_array($boltPattern)) {
                 $boltPattern = array($boltPattern);
             }
             foreach ($boltPattern as $each) {
                 $wheelProduct->addBoltPattern($each);
             }
         }
     }
 }
 function wheelSize($row)
 {
     $lugCount = $this->getFieldValue('lug_count', $row);
     $boltDistance = $this->getFieldValue('bolt_distance', $row);
     $offset = $this->getFieldValue('offset', $row);
     return Elite_Vafwheel_Model_BoltPattern::create($lugCount . 'x' . $boltDistance, $offset);
 }
 /**
  * @param array $row
  * @param VF_Vehicle|boolean the vehicle, false if none (for example, when setting a product as universal)
  */
 function doImportRow($row, $vehicle)
 {
     $boltPattern = $this->getFieldValue('bolt_pattern', $row);
     $offset = $this->getFieldValue('offset', $row);
     $boltPattern = Elite_Vafwheel_Model_BoltPattern::create($boltPattern, $offset);
     $wheelDefinition = new Elite_Vafwheel_Model_Vehicle($vehicle);
     $wheelDefinition->addBoltPattern($boltPattern);
 }
 /**
  * @param Varien_Controller_Action
  * @param Mage_Catalog_Model_Product
  */
 function doBindWheelSide($controller, Elite_Vaf_Model_Catalog_Product $product)
 {
     $wheeladapterProduct = new Elite_Vafwheeladapter_Model_Catalog_Product($product);
     $pattern = $controller->getRequest()->getParam('wheel_side_pattern');
     if (!$pattern) {
         return $wheeladapterProduct->unsetWheelSideBoltPattern();
     }
     $boltPattern = Elite_Vafwheel_Model_BoltPattern::create($pattern);
     $wheeladapterProduct->setWheelSideBoltPattern($boltPattern);
 }
	function testShouldDeleteBoltPatterns_WhenDeletingYear()
	{
		$vehicle = $this->createMMY('Honda','Civic','2000');
		$vehicle = new Elite_Vafwheel_Model_Vehicle($vehicle);
		$vehicle->addBoltPattern(Elite_Vafwheel_Model_BoltPattern::create('4x114.3'));
		
		$vehicle->getLevel('year')->delete();
		                                                                                                                
		$result = $this->query('select count(*) from elite_definition_wheel where leaf_id = '.$vehicle->getValue('year'));
		$this->assertEquals( 0, $result->fetchColumn(), 'should delete wheel record when deleting a year' );
	}
 function insertMappings(Elite_Vafwheel_Model_BoltPattern $boltPattern)
 {
     if ($boltPattern->getOffset()) {
         $q = sprintf("\n                SELECT DISTINCT(`leaf_id`) as leaf_id\n                FROM `elite_definition_wheel`\n                WHERE `bolt_distance` = %s\n                AND `lug_count` = %d\n                AND `offset` >= %s\n                AND `offset` <= %s\n                ", (double) $boltPattern->getDistance(), (double) $boltPattern->getLugCount(), (double) $boltPattern->offsetMin(), (double) $boltPattern->offsetMax());
     } else {
         $q = sprintf("\n                SELECT DISTINCT(`leaf_id`) as leaf_id\n                FROM `elite_definition_wheel`\n                WHERE `bolt_distance` = %s\n                AND `lug_count` = %d\n                ", (double) $boltPattern->getDistance(), (double) $boltPattern->getLugCount());
     }
     $result = $this->query($q);
     $years = array();
     $rows = $result->fetchAll(Zend_Db::FETCH_OBJ);
     foreach ($rows as $row) {
         $vehicle = $this->definition($row->leaf_id);
         $this->insertMapping($vehicle);
     }
 }
 /**
  * DUAL FORMAT
  * Total Lug Count x bolt distance A / bolt distance B
  * ex. 10 x 100/114.3  
  * dual bolt pattern, if string contains slash, lug nut count should be divided by 2 ( represents total count ). Slash seperates distance
  * So this would be either 5 lug 100mm or 5 lug 114.3 ( wheel fits both )
  */
 function __construct($formattedString)
 {
     $array = preg_split('#x#', $formattedString, 2);
     for ($i = 0; $i <= 1; $i++) {
         $array[$i] = trim($array[$i]);
     }
     $lug_count = $array[0];
     $bolt_distance = $array[1];
     if ($lug_count % 2 != 0) {
         throw new Exception('dual bolt pattern but odd # lug count');
     }
     $lug_count = $lug_count / 2;
     $bolt_distance = preg_split('#/#', $bolt_distance);
     $this->left = Elite_Vafwheel_Model_BoltPattern::createFromValues($lug_count, $bolt_distance[0]);
     $this->right = Elite_Vafwheel_Model_BoltPattern::createFromValues($lug_count, $bolt_distance[1]);
 }
 function testOffsetThresholdMaximum()
 {
     $bolt = Elite_Vafwheel_Model_BoltPattern::create('4x114.3', 20);
     $this->assertEquals(25, $bolt->offsetMax());
 }
 function setWheelSideBoltPattern(Elite_Vafwheel_Model_BoltPattern $boltPattern)
 {
     $sql = sprintf("REPLACE INTO `elite_product_wheeladapter` ( `entity_id`, `lug_count`, `bolt_distance` ) VALUES ( %d, %d, %s )", $this->getId(), (int) $boltPattern->getLugCount(), (double) $boltPattern->getDistance());
     $this->query($sql);
 }
 function boltPattern()
 {
     return Elite_Vafwheel_Model_BoltPattern::create($this->boltString());
 }
 function vehicleBolt()
 {
     $vehicleBoltString = $this->vehicleSideLugCount() . 'x' . $this->vehicleSideStudSpread();
     return Elite_Vafwheel_Model_BoltPattern::create($vehicleBoltString);
 }
 function boltPattern($boltPatternString, $offset = null)
 {
     return Elite_Vafwheel_Model_BoltPattern::create($boltPatternString, $offset);
 }