/**
  * @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 testFindsMatchingProduct()
 {
     $bolt = VF_Wheel_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');
 }
 function wheelSize($row)
 {
     $lugCount = $this->getFieldValue('lug_count', $row);
     $boltDistance = $this->getFieldValue('bolt_distance', $row);
     $offset = $this->getFieldValue('offset', $row);
     return VF_Wheel_BoltPattern::create($lugCount . 'x' . $boltDistance, $offset);
 }
Beispiel #4
0
 /**
  * @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 = VF_Wheel_BoltPattern::create($boltPattern, $offset);
     $wheelDefinition = new VF_Wheel_Vehicle($vehicle);
     $wheelDefinition->addBoltPattern($boltPattern);
 }
 /**
  * @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 insertMappings(VF_Wheel_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);
     }
 }
Beispiel #7
0
 /**
  * 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 = VF_Wheel_BoltPattern::createFromValues($lug_count, $bolt_distance[0]);
     $this->right = VF_Wheel_BoltPattern::createFromValues($lug_count, $bolt_distance[1]);
 }
 function vehicleBolt()
 {
     $vehicleBoltString = $this->vehicleSideLugCount() . 'x' . $this->vehicleSideStudSpread();
     return VF_Wheel_BoltPattern::create($vehicleBoltString);
 }
Beispiel #9
0
 function boltPattern()
 {
     return VF_Wheel_BoltPattern::create($this->boltString());
 }
 function setWheelSideBoltPattern(VF_Wheel_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($boltPatternString, $offset = null)
 {
     return VF_Wheel_BoltPattern::create($boltPatternString, $offset);
 }
 function testOffsetThresholdMaximum()
 {
     $bolt = VF_Wheel_BoltPattern::create('4x114.3', 20);
     $this->assertEquals(25, $bolt->offsetMax());
 }