public function parseResults(LoopResult $loopResult)
 {
     foreach ($loopResult->getResultDataCollection() as $featureAv) {
         $isFreeText = FeatureProductQuery::create()->filterByFeatureId($featureAv->getFeatureId())->filterByFeatureAvId($featureAv->getId())->findOneByFreeTextValue(true);
         if ($isFreeText === null) {
             $loopResultRow = new LoopResultRow($featureAv);
             $loopResultRow->set("ID", $featureAv->getId())->set("IS_TRANSLATED", $featureAv->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("FEATURE_ID", $featureAv->getFeatureId())->set("TITLE", $featureAv->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $featureAv->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $featureAv->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $featureAv->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("POSITION", $featureAv->getPosition());
             $this->addOutputFields($loopResultRow, $featureAv);
             $loopResult->addRow($loopResultRow);
         }
     }
     return $loopResult;
 }
 public function fixAmountRetriever(Product $product)
 {
     $taxAmount = 0;
     $featureId = $this->getRequirement("feature");
     $query = FeatureProductQuery::create()->filterByProduct($product)->filterByFeatureId($featureId)->findOne();
     if (null !== $query) {
         $taxAmount = $query->getFreeTextValue();
         $testInt = new FloatType();
         if (!$testInt->isValid($taxAmount)) {
             throw new TaxEngineException(Translator::getInstance()->trans('Feature value does not match FLOAT format'), TaxEngineException::FEATURE_BAD_EXPECTED_VALUE);
         }
     }
     return $taxAmount;
 }
示例#3
0
 public function buildModelCriteria()
 {
     $search = FeatureProductQuery::create();
     // manage featureAv translations
     $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), FeatureAvTableMap::TABLE_NAME, 'FEATURE_AV_ID', true);
     $search->useFeatureAvQuery('feature_av')->withColumn(FeatureAvTableMap::POSITION, 'feature_av_position')->endUse();
     $feature = $this->getFeature();
     $search->filterByFeatureId($feature, Criteria::EQUAL);
     if (null !== ($product = $this->getProduct())) {
         $search->filterByProductId($product, Criteria::EQUAL);
     }
     if (null !== ($featureAvailability = $this->getFeature_availability())) {
         $search->filterByFeatureAvId($featureAvailability, Criteria::IN);
     }
     if (null !== ($freeText = $this->getFreeText())) {
         $search->filterByFreeTextValue($featureAvailability, Criteria::IN);
     }
     if (true === ($excludeFeatureAvailability = $this->getExclude_feature_availability())) {
         $search->filterByFeatureAvId(null, Criteria::ISNULL);
     }
     if (true === ($excludeFreeText = $this->getExcludeFreeText())) {
         $search->filterByFreeTextValue(null, Criteria::ISNULL);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_TITLE');
                 break;
             case "alpha_reverse":
                 $search->addDescendingOrderByColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_TITLE');
                 break;
             case "manual":
                 $search->orderBy('feature_av_position', Criteria::ASC);
                 break;
             case "manual_reverse":
                 $search->orderBy('feature_av_position', Criteria::DESC);
                 break;
         }
     }
     return $search;
 }
示例#4
0
文件: faker.php 项目: hadesain/thelia
foreach ($localeList as $locale) {
    $localizedFaker[$locale] = Faker\Factory::create($locale);
}
$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();
示例#5
0
 /**
  * Performs an INSERT on the database, given a FeatureProduct or Criteria object.
  *
  * @param mixed               $criteria Criteria or FeatureProduct 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(FeatureProductTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from FeatureProduct object
     }
     if ($criteria->containsKey(FeatureProductTableMap::ID) && $criteria->keyContainsValue(FeatureProductTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . FeatureProductTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = FeatureProductQuery::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;
 }
示例#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();
 }
示例#7
0
 /**
  * @depends testUpdateClone
  * @param ProductCloneEvent $event
  * @return ProductCloneEvent
  */
 public function testCloneFeatureCombination(ProductCloneEvent $event)
 {
     // Call function to test
     $action = new Product();
     $action->cloneFeatureCombination($event);
     // Get products' features
     $originalProductFeatures = FeatureProductQuery::create()->findByProductId($event->getOriginalProduct()->getId());
     $cloneProductFeatures = FeatureProductQuery::create()->filterByProductId($event->getClonedProduct()->getId())->count();
     $this->assertEquals(count($originalProductFeatures), $cloneProductFeatures, 'There must be the same quantity of features');
     // Check clone product's features
     foreach ($originalProductFeatures as $originalProductFeature) {
         $cloneProductFeatureQuery = FeatureProductQuery::create()->filterByProductId($event->getClonedProduct()->getId())->filterByFeatureId($originalProductFeature->getFeatureId());
         if ($originalProductFeature->getFreeTextValue() != 1) {
             $cloneProductFeatureQuery->filterByFeatureAvId($originalProductFeature->getFeatureAvId());
         }
         $cloneProductFeature = $cloneProductFeatureQuery->findOne();
         $this->assertInstanceOf('Thelia\\Model\\FeatureProduct', $cloneProductFeature, 'Instance of clone product feature must be Thelia\\Model\\FeatureProduct');
         $this->assertEquals($event->getClonedProduct()->getId(), $cloneProductFeature->getProductId(), 'ProductID must be equal');
         $this->assertEquals($originalProductFeature->getFeatureId(), $cloneProductFeature->getFeatureId(), 'FeatureID must be equal');
         if ($originalProductFeature->getFreeTextValue() == 1) {
             $this->assertNotEquals($originalProductFeature->getFeatureAvId(), $cloneProductFeature->getFeatureAvId(), 'FeatureAvID can\'t be equal');
         } else {
             $this->assertEquals($originalProductFeature->getFeatureAvId(), $cloneProductFeature->getFeatureAvId(), 'FeatureAvID must be equal');
         }
         $this->assertEquals($originalProductFeature->getFreeTextValue(), $cloneProductFeature->getFreeTextValue(), 'Free text value must be equal');
         $this->assertEquals($originalProductFeature->getPosition(), $cloneProductFeature->getPosition(), 'Position must be equal');
     }
     return $event;
 }
示例#8
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Feature is new, it will return
  * an empty collection; or if this Feature has previously
  * been saved, it will retrieve related FeatureProducts from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Feature.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return Collection|ChildFeatureProduct[] List of ChildFeatureProduct objects
  */
 public function getFeatureProductsJoinFeatureAv($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildFeatureProductQuery::create(null, $criteria);
     $query->joinWith('FeatureAv', $joinBehavior);
     return $this->getFeatureProducts($query, $con);
 }
示例#9
0
 /**
  * Delete a product feature value
  *
  * @param FeatureProductDeleteEvent $event
  */
 public function deleteFeatureProductValue(FeatureProductDeleteEvent $event)
 {
     FeatureProductQuery::create()->filterByProductId($event->getProductId())->filterByFeatureId($event->getFeatureId())->delete();
 }
示例#10
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see FeatureProduct::setDeleted()
  * @see FeatureProduct::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(FeatureProductTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildFeatureProductQuery::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;
     }
 }