Ejemplo n.º 1
0
function createMaterials($con)
{
    echo "start creating materials feature\n";
    $feature = null;
    $features = array();
    if (($handle = fopen(THELIA_ROOT . '/setup/import/materials.csv', "r")) !== FALSE) {
        $row = 0;
        $feature = new \Thelia\Model\Feature();
        $feature->setPosition(1)->setLocale('fr_FR')->setTitle('Matière')->setLocale('en_US')->setTitle('Material');
        while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
            $row++;
            $featureAv = new \Thelia\Model\FeatureAv();
            $featureAv->setPosition($row)->setLocale('fr_FR')->setTitle($data[0])->setLocale('en_US')->setTitle($data[1]);
            //$featureAv->setFeature($feature);
            $feature->addFeatureAv($featureAv);
        }
        $feature->save($con);
        fclose($handle);
    }
    echo "materials feature created successfully\n";
    return $feature;
}
Ejemplo n.º 2
0
                 $pick = array_rand($attributeList, 1);
             } while (in_array($pick, $alreadyPicked));
             $alreadyPicked[] = $pick;
             $featureProduct->setAttributeId($pick)->setAttributeAvId($attributeList[$pick][array_rand($attributeList[$pick], 1)])->setProductSaleElements($stock)->save();
         }
     }
     //associate features to products
     $freeTextCreated = false;
     foreach ($featureList as $featureId => $featureAvId) {
         $featureProduct = new Thelia\Model\FeatureProduct();
         $featureProduct->setProductId($productId)->setFeatureId($featureId);
         if ($freeTextCreated === false && count($featureAvId) === 0) {
             //set one feature as free text
             $featureAv = new Thelia\Model\FeatureAv();
             $featureAv->setFeatureId($featureId);
             $featureAv->setPosition(1);
             setI18n($featureAv);
             $featureAv->save();
             $featureProduct->setFeatureAvId($featureAv->getId());
             $featureProduct->setFreeTextValue(true);
             $freeTextCreated = true;
         } elseif (count($featureAvId) > 0) {
             //got some av
             $featureProduct->setFeatureAvId($featureAvId[array_rand($featureAvId, 1)]);
         } else {
             //no av : no featureProduct
             continue;
         }
         $featureProduct->save();
     }
 }
Ejemplo n.º 3
0
 echo "Creating features\n";
 //features and features_av
 $featureList = array();
 for ($i = 0; $i < 4; $i++) {
     $feature = new Thelia\Model\Feature();
     $feature->setVisible(1);
     $feature->setPosition($i);
     setI18n($feature);
     $feature->save();
     $featureId = $feature->getId();
     $featureList[$featureId] = array();
     for ($j = 0; $j < rand(-2, 5); $j++) {
         //let a chance for no av
         $featureAv = new Thelia\Model\FeatureAv();
         $featureAv->setFeature($feature);
         $featureAv->setPosition($j);
         setI18n($featureAv);
         $featureAv->save();
         $featureList[$featureId][] = $featureAv->getId();
     }
 }
 echo "Creating attributes\n";
 //attributes and attributes_av
 $attributeList = array();
 for ($i = 0; $i < 4; $i++) {
     $attribute = new Thelia\Model\Attribute();
     $attribute->setPosition($i);
     setI18n($attribute);
     $attribute->save();
     $attributeId = $attribute->getId();
     $attributeList[$attributeId] = array();