Ejemplo n.º 1
0
 /**
  * @return \Thelia\Model\Feature
  */
 protected function getRandomFeature()
 {
     $feature = FeatureQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     if (null === $feature) {
         $this->fail('use fixtures before launching test, there is no feature in database');
     }
     return $feature;
 }
Ejemplo n.º 2
0
 public function preImport()
 {
     FeatureQuery::create()->deleteAll();
     FeatureAvQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->feat_corresp = new CorrespondanceTable(CorrespondanceTable::FEATURES, $this->t1db);
     $this->feat_corresp->reset();
     $this->feat_av_corresp = new CorrespondanceTable(CorrespondanceTable::FEATURES_AV, $this->t1db);
     $this->feat_av_corresp->reset();
 }
Ejemplo n.º 3
0
 public function buildModelCriteria()
 {
     $search = FeatureQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search);
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $exclude = $this->getExclude();
     if (null !== $exclude) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $visible = $this->getVisible();
     if ($visible != BooleanOrBothType::ANY) {
         $search->filterByVisible($visible);
     }
     $product = $this->getProduct();
     $template = $this->getTemplate();
     $exclude_template = $this->getExcludeTemplate();
     $this->useFeaturePosition = true;
     if (null !== $product) {
         // Find all template assigned to the products.
         $products = ProductQuery::create()->findById($product);
         // Ignore if the product cannot be found.
         if ($products !== null) {
             // Create template array
             if ($template == null) {
                 $template = array();
             }
             foreach ($products as $product) {
                 $tpl_id = $product->getTemplateId();
                 if (!is_null($tpl_id)) {
                     $template[] = $tpl_id;
                 }
             }
         }
         // franck@cqfdev.fr - 05/12/2013 : if the given product has no template
         // or if the product cannot be found, do not return anything.
         if (empty($template)) {
             return null;
         }
     }
     if (!empty($template)) {
         // Join with feature_template table to get position
         $search->withColumn(FeatureTemplateTableMap::POSITION, 'position')->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN);
         $this->useFeaturePosition = false;
     }
     if (null !== $exclude_template) {
         $exclude_features = FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find();
         $search->filterById($exclude_features, Criteria::NOT_IN);
     }
     $title = $this->getTitle();
     if (null !== $title) {
         //find all feature that match exactly this title and find with all locales.
         $features = FeatureI18nQuery::create()->filterByTitle($title, Criteria::LIKE)->select('id')->find();
         if ($features) {
             $search->filterById($features, Criteria::IN);
         }
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "id":
                 $search->orderById(Criteria::ASC);
                 break;
             case "id_reverse":
                 $search->orderById(Criteria::DESC);
                 break;
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha-reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual":
                 if ($this->useFeaturePosition) {
                     $search->orderByPosition(Criteria::ASC);
                 } else {
                     $search->addAscendingOrderByColumn(FeatureTemplateTableMap::POSITION);
                 }
                 break;
             case "manual_reverse":
                 if ($this->useFeaturePosition) {
                     $search->orderByPosition(Criteria::DESC);
                 } else {
                     $search->addDescendingOrderByColumn(FeatureTemplateTableMap::POSITION);
                 }
                 break;
         }
     }
     return $search;
 }
Ejemplo n.º 4
0
}
$con = \Propel\Runtime\Propel::getConnection(Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
$con->beginTransaction();
// Intialize URL management
$url = new Thelia\Tools\URL();
$currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne();
//\Thelia\Log\Tlog::getInstance()->setLevel(\Thelia\Log\Tlog::ERROR);
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();
Ejemplo n.º 5
0
 /**
  * Changes position, selecting absolute ou relative change.
  *
  * @param UpdatePositionEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $this->genericUpdatePosition(FeatureQuery::create(), $event, $dispatcher);
 }
Ejemplo n.º 6
0
 /**
  * Update product attributes and features
  */
 public function updateAttributesAndFeaturesAction($productId)
 {
     $product = ProductQuery::create()->findPk($productId);
     if ($product != null) {
         $featureTemplate = FeatureTemplateQuery::create()->filterByTemplateId($product->getTemplateId())->find();
         if ($featureTemplate !== null) {
             // Get all features for the template attached to this product
             $allFeatures = FeatureQuery::create()->filterByFeatureTemplate($featureTemplate)->find();
             $updatedFeatures = array();
             // Update all features values, starting with feature av. values
             $featureValues = $this->getRequest()->get('feature_value', array());
             foreach ($featureValues as $featureId => $featureValueList) {
                 // Delete all features av. for this feature.
                 $event = new FeatureProductDeleteEvent($productId, $featureId);
                 $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
                 // Add then all selected values
                 foreach ($featureValueList as $featureValue) {
                     $event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue);
                     $this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
                 }
                 $updatedFeatures[] = $featureId;
             }
             // Update then features text values
             $featureTextValues = $this->getRequest()->get('feature_text_value', array());
             foreach ($featureTextValues as $featureId => $featureValue) {
                 // Check if a FeatureProduct exists for this product and this feature (for another lang)
                 $freeTextFeatureProduct = FeatureProductQuery::create()->filterByProductId($productId)->filterByFreeTextValue(true)->findOneByFeatureId($featureId);
                 // If no corresponding FeatureProduct exists AND if the feature_text_value is empty, do nothing
                 if (is_null($freeTextFeatureProduct) && empty($featureValue)) {
                     continue;
                 }
                 $event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue, true);
                 $event->setLocale($this->getCurrentEditionLocale());
                 $this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
                 $updatedFeatures[] = $featureId;
             }
             // Delete features which don't have any values
             /** @var Feature $feature */
             foreach ($allFeatures as $feature) {
                 if (!in_array($feature->getId(), $updatedFeatures)) {
                     $event = new FeatureProductDeleteEvent($productId, $feature->getId());
                     $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
                 }
             }
         }
     }
     // If we have to stay on the same page, do not redirect to the successUrl,
     // just redirect to the edit page again.
     if ($this->getRequest()->get('save_mode') == 'stay') {
         return $this->redirectToEditionTemplate($this->getRequest());
     }
     // Redirect to the category/product list
     return $this->redirectToListTemplate();
 }
Ejemplo n.º 7
0
 /**
  * Performs an INSERT on the database, given a Feature or Criteria object.
  *
  * @param mixed               $criteria Criteria or Feature 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(FeatureTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Feature object
     }
     if ($criteria->containsKey(FeatureTableMap::ID) && $criteria->keyContainsValue(FeatureTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . FeatureTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = FeatureQuery::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;
 }
Ejemplo n.º 8
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Feature::setDeleted()
  * @see Feature::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(FeatureTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildFeatureQuery::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;
     }
 }
Ejemplo n.º 9
0
 /**
  * Gets the number of ChildFeature objects related by a many-to-many relationship
  * to the current object by way of the feature_template cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      ConnectionInterface $con Optional connection object
  *
  * @return int the number of related ChildFeature objects
  */
 public function countFeatures($criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     if (null === $this->collFeatures || null !== $criteria) {
         if ($this->isNew() && null === $this->collFeatures) {
             return 0;
         } else {
             $query = ChildFeatureQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByTemplate($this)->count($con);
         }
     } else {
         return count($this->collFeatures);
     }
 }
Ejemplo n.º 10
0
 /**
  * Changes position, selecting absolute ou relative change.
  *
  * @param UpdatePositionEvent $event
  */
 public function updatePosition(UpdatePositionEvent $event)
 {
     $this->genericUpdatePosition(FeatureQuery::create(), $event);
 }
Ejemplo n.º 11
0
 protected function getExistingObject()
 {
     $feature = FeatureQuery::create()->findOneById($this->getRequest()->get('feature_id', 0));
     if (null !== $feature) {
         $feature->setLocale($this->getCurrentEditionLocale());
     }
     return $feature;
 }
Ejemplo n.º 12
0
 /**
  * Get the associated ChildFeature object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildFeature The associated ChildFeature object.
  * @throws PropelException
  */
 public function getFeature(ConnectionInterface $con = null)
 {
     if ($this->aFeature === null && $this->feature_id !== null) {
         $this->aFeature = ChildFeatureQuery::create()->findPk($this->feature_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aFeature->addFeatureTemplates($this);
            */
     }
     return $this->aFeature;
 }
Ejemplo n.º 13
0
$con->beginTransaction();
// Intialize URL management
try {
    $options = getopt('f::e::');
    $forceEcotaxFeatureId = $options['f'];
    if (null !== $forceEcotaxFeatureId && !filter_var($forceEcotaxFeatureId, FILTER_VALIDATE_INT)) {
        exit('[ERROR] bad value for f option\\n');
    }
    $forceEcotaxId = $options['e'];
    if (null !== $forceEcotaxId && !filter_var($forceEcotaxId, FILTER_VALIDATE_INT)) {
        exit('[ERROR] bad value for e option\\n');
    }
    echo "Adding Ecotax feature\n";
    $feature = null;
    if (null !== $forceEcotaxFeatureId) {
        $feature = \Thelia\Model\FeatureQuery::create()->findPk($forceEcotaxFeatureId);
        if (null === $feature) {
            echo "Feature `{$forceEcotaxFeatureId}` not found\n";
        }
    }
    if (null === $feature) {
        $feature = new \Thelia\Model\Feature();
        $feature->setVisible(1);
        $feature->save();
        echo sprintf("Ecotax feature added with ID \n", $feature->getId());
    }
    $fr = \Thelia\Model\Base\FeatureI18nQuery::create()->filterByLocale('fr_FR')->filterByFeature($feature)->findOne();
    if (null === $fr) {
        $fr = new \Thelia\Model\FeatureI18n();
        $fr->setLocale('fr_FR')->setFeature($feature);
    }