コード例 #1
0
ファイル: faker.php プロジェクト: hadesain/thelia
try {
    $stmt = $con->prepare("SET foreign_key_checks = 0");
    $stmt->execute();
    echo "Clearing tables\n";
    Model\ProductAssociatedContentQuery::create()->deleteAll();
    Model\CategoryAssociatedContentQuery::create()->deleteAll();
    Model\FeatureProductQuery::create()->deleteAll();
    Model\AttributeCombinationQuery::create()->deleteAll();
    Model\FeatureQuery::create()->deleteAll();
    Model\FeatureI18nQuery::create()->deleteAll();
    Model\FeatureAvQuery::create()->deleteAll();
    Model\FeatureAvI18nQuery::create()->deleteAll();
    Model\AttributeQuery::create()->deleteAll();
    Model\AttributeI18nQuery::create()->deleteAll();
    Model\AttributeAvQuery::create()->deleteAll();
    Model\AttributeAvI18nQuery::create()->deleteAll();
    Model\CategoryQuery::create()->deleteAll();
    Model\CategoryI18nQuery::create()->deleteAll();
    Model\ProductQuery::create()->deleteAll();
    Model\ProductI18nQuery::create()->deleteAll();
    Model\CustomerQuery::create()->deleteAll();
    Model\AdminQuery::create()->deleteAll();
    Model\FolderQuery::create()->deleteAll();
    Model\FolderI18nQuery::create()->deleteAll();
    Model\ContentQuery::create()->deleteAll();
    Model\ContentI18nQuery::create()->deleteAll();
    Model\AccessoryQuery::create()->deleteAll();
    Model\ProductSaleElementsQuery::create()->deleteAll();
    Model\ProductPriceQuery::create()->deleteAll();
    Model\BrandQuery::create()->deleteAll();
    Model\BrandI18nQuery::create()->deleteAll();
コード例 #2
0
ファイル: import.php プロジェクト: alex63530/thelia
function createProduct($faker, $categories, $brands, $contents, $template, $attribute, $feature, $con)
{
    echo "start creating products\n";
    $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
    if (($handle = fopen(THELIA_ROOT . '/setup/import/products.csv', "r")) !== FALSE) {
        $row = 0;
        while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) {
            $row++;
            if ($row == 1) {
                continue;
            }
            $product = new \Thelia\Model\Product();
            $product->setRef($data[0])->setVisible(1)->setTaxRuleId(1)->setTemplate($template);
            $productCategories = explode(';', $data[15]);
            foreach ($productCategories as $productCategory) {
                $productCategory = trim($productCategory);
                if (array_key_exists($productCategory, $categories)) {
                    $product->addCategory($categories[$productCategory]);
                }
            }
            $brand = $data[11];
            if (array_key_exists($brand, $brands)) {
                $product->setBrand($brands[$brand]);
            }
            $product->setLocale('en_US')->setTitle($data[1])->setChapo($data[2])->setDescription($data[4])->setPostscriptum($data[6])->setLocale('fr_Fr')->setTitle($data[1])->setChapo($data[3])->setDescription($data[5])->setPostscriptum($data[7])->save($con);
            $productCategories = $product->getProductCategories()->getFirst();
            $productCategories->setDefaultCategory(true)->save($con);
            // Set the position
            $product->setPosition($product->getNextPosition())->save($con);
            $images = explode(';', $data[10]);
            foreach ($images as $image) {
                $image = trim($image);
                if (empty($image)) {
                    continue;
                }
                $productImage = new \Thelia\Model\ProductImage();
                $productImage->setProduct($product)->setFile($image)->save($con);
                $fileSystem->copy(THELIA_ROOT . 'setup/import/images/' . $image, THELIA_ROOT . 'local/media/images/product/' . $image, true);
            }
            $pses = explode(";", $data[12]);
            foreach ($pses as $pse) {
                if (empty($pse)) {
                    continue;
                }
                $stock = new \Thelia\Model\ProductSaleElements();
                $stock->setProduct($product);
                $stock->setRef($product->getId() . '_' . uniqid('', true));
                $stock->setQuantity($faker->numberBetween(1, 50));
                if (!empty($data[9])) {
                    $stock->setPromo(1);
                } else {
                    $stock->setPromo(0);
                }
                $stock->setNewness($faker->numberBetween(0, 1));
                $stock->setWeight($faker->randomFloat(2, 1, 30));
                $stock->save($con);
                $productPrice = new \Thelia\Model\ProductPrice();
                $productPrice->setProductSaleElements($stock);
                $productPrice->setCurrencyId(1);
                $productPrice->setPrice($data[8]);
                $productPrice->setPromoPrice($data[9]);
                $productPrice->save($con);
                $attributeAv = \Thelia\Model\AttributeAvI18nQuery::create()->filterByLocale('en_US')->filterByTitle($pse)->findOne($con);
                $attributeCombination = new \Thelia\Model\AttributeCombination();
                $attributeCombination->setAttributeId($attribute->getId())->setAttributeAvId($attributeAv->getId())->setProductSaleElements($stock)->save($con);
            }
            $productSaleElements = $product->getProductSaleElementss()->getFirst();
            $productSaleElements->setIsDefault(1)->save($con);
            // associated content
            $associatedContents = explode(";", $data[14]);
            foreach ($associatedContents as $associatedContent) {
                $content = new ProductAssociatedContent();
                if (!array_key_exists($associatedContent, $contents)) {
                    continue;
                }
                $content->setProduct($product)->setContent($contents[$associatedContent])->save($con);
            }
            // feature
            $features = explode(";", $data[13]);
            foreach ($features as $aFeature) {
                $featurAv = \Thelia\Model\FeatureAvI18nQuery::create()->filterByLocale('en_US')->filterByTitle($aFeature)->findOne($con);
                $featureProduct = new Thelia\Model\FeatureProduct();
                $featureProduct->setProduct($product)->setFeatureId($feature->getId())->setFeatureAvId($featurAv->getId())->save($con);
            }
        }
    }
    echo "end creating products\n";
}
コード例 #3
0
 /**
  * Performs an INSERT on the database, given a AttributeAvI18n or Criteria object.
  *
  * @param mixed               $criteria Criteria or AttributeAvI18n object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(AttributeAvI18nTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from AttributeAvI18n object
     }
     // Set the correct dbName
     $query = AttributeAvI18nQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
コード例 #4
0
ファイル: AttributeAv.php プロジェクト: margery/thelia
 /**
  * Remove the translation for a given locale
  *
  * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
  * @param     ConnectionInterface $con an optional connection object
  *
  * @return    ChildAttributeAv The current object (for fluent API support)
  */
 public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null)
 {
     if (!$this->isNew()) {
         ChildAttributeAvI18nQuery::create()->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))->delete($con);
     }
     if (isset($this->currentTranslations[$locale])) {
         unset($this->currentTranslations[$locale]);
     }
     foreach ($this->collAttributeAvI18ns as $key => $translation) {
         if ($translation->getLocale() == $locale) {
             unset($this->collAttributeAvI18ns[$key]);
             break;
         }
     }
     return $this;
 }
コード例 #5
0
ファイル: AttributeAvI18n.php プロジェクト: margery/thelia
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see AttributeAvI18n::setDeleted()
  * @see AttributeAvI18n::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(AttributeAvI18nTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAttributeAvI18nQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }