/**
  * Add fields for attribute values selection in our own way (since the product on has its default PSE, it has
  * no attributes as far as Thelia is concerned, but we want it to have all of its template's attributes).
  *
  * @param TheliaFormEvent $event
  */
 public function cartFormAfterBuild(TheliaFormEvent $event)
 {
     $sessionLocale = null;
     $session = $this->request->getSession();
     if ($session !== null) {
         $sessionLang = $session->getLang();
         if ($sessionLang !== null) {
             $sessionLocale = $sessionLang->getLocale();
         }
     }
     $product = ProductQuery::create()->findPk($this->request->getProductId());
     if ($product === null || $product->getTemplate() === null) {
         return;
     }
     $productAttributes = AttributeQuery::create()->filterByTemplate($product->getTemplate())->find();
     /** @var Attribute $productAttribute */
     foreach ($productAttributes as $productAttribute) {
         $attributeValues = AttributeAvQuery::create()->findByAttributeId($productAttribute->getId());
         $choices = [];
         /** @var AttributeAv $attributeValue */
         foreach ($attributeValues as $attributeValue) {
             if ($sessionLocale !== null) {
                 $attributeValue->setLocale($sessionLocale);
             }
             $choices[$attributeValue->getId()] = $attributeValue->getTitle();
         }
         $event->getForm()->getFormBuilder()->add(static::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId(), 'choice', ['choices' => $choices, 'required' => true]);
     }
 }
Example #2
0
 public function preImport()
 {
     AttributeQuery::create()->deleteAll();
     AttributeAvQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->attr_corresp = new CorrespondanceTable(CorrespondanceTable::ATTRIBUTES, $this->t1db);
     $this->attr_corresp->reset();
     $this->attr_av_corresp = new CorrespondanceTable(CorrespondanceTable::ATTRIBUTES_AV, $this->t1db);
     $this->attr_av_corresp->reset();
 }
Example #3
0
 public function testCreate()
 {
     $attribute = AttributeQuery::create()->findOne();
     $event = new AttributeAvCreateEvent();
     $event->setAttributeId($attribute->getId())->setLocale('en_US')->setTitle('foo')->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $action = new AttributeAv();
     $action->create($event);
     $attributeAvCreated = $event->getAttributeAv();
     $this->assertInstanceOf('Thelia\\Model\\AttributeAv', $attributeAvCreated);
     $this->assertEquals('en_US', $attributeAvCreated->getLocale());
     $this->assertEquals('foo', $attributeAvCreated->getTitle());
     $this->assertNull($attributeAvCreated->getDescription());
     $this->assertNull($attributeAvCreated->getPostscriptum());
     $this->assertNull($attributeAvCreated->getChapo());
     $this->assertEquals($attribute, $attributeAvCreated->getAttribute());
     return $attributeAvCreated;
 }
Example #4
0
 /**
  * Get the associated ChildAttribute object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildAttribute The associated ChildAttribute object.
  * @throws PropelException
  */
 public function getAttribute(ConnectionInterface $con = null)
 {
     if ($this->aAttribute === null && $this->id !== null) {
         $this->aAttribute = ChildAttributeQuery::create()->findPk($this->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->aAttribute->addAttributeI18ns($this);
            */
     }
     return $this->aAttribute;
 }
Example #5
0
$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();
    Model\ContentQuery::create()->deleteAll();
    Model\ContentI18nQuery::create()->deleteAll();
    Model\AccessoryQuery::create()->deleteAll();
    Model\ProductSaleElementsQuery::create()->deleteAll();
Example #6
0
 public function getAttributeValuesAction($productId, $attributeId)
 {
     $result = array();
     // Get attribute for this product
     $attribute = AttributeQuery::create()->findPk($attributeId);
     if ($attribute !== null) {
         $values = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->filterByAttribute($attribute)->find();
         if ($values !== null) {
             /** @var AttributeAv $value */
             foreach ($values as $value) {
                 $result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
             }
         }
     }
     return $this->jsonResponse(json_encode($result));
 }
Example #7
0
 protected function getExistingObject()
 {
     $attribute = AttributeQuery::create()->findOneById($this->getRequest()->get('attribute_id', 0));
     if (null !== $attribute) {
         $attribute->setLocale($this->getCurrentEditionLocale());
     }
     return $attribute;
 }
Example #8
0
 public function buildModelCriteria()
 {
     $search = AttributeQuery::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);
     }
     $product = $this->getProduct();
     $template = $this->getTemplate();
     $exclude_template = $this->getExcludeTemplate();
     $this->useAttributePosistion = 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(AttributeTemplateTableMap::POSITION, 'position')->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN);
         $this->useAttributePosistion = false;
     } elseif (null !== $exclude_template) {
         // Join with attribute_template table to get position
         $exclude_attributes = AttributeTemplateQuery::create()->filterByTemplateId($exclude_template)->select('attribute_id')->find();
         $search->joinAttributeTemplate(null, Criteria::LEFT_JOIN)->withColumn(AttributeTemplateTableMap::POSITION, 'position')->filterById($exclude_attributes, Criteria::NOT_IN);
         $this->useAttributePosistion = false;
     }
     $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->useAttributePosistion) {
                     $search->orderByPosition(Criteria::ASC);
                 } else {
                     $search->addAscendingOrderByColumn(AttributeTemplateTableMap::POSITION);
                 }
                 break;
             case "manual_reverse":
                 if ($this->useAttributePosistion) {
                     $search->orderByPosition(Criteria::DESC);
                 } else {
                     $search->addDescendingOrderByColumn(AttributeTemplateTableMap::POSITION);
                 }
                 break;
         }
     }
     return $search;
 }
Example #9
0
 /**
  * Gets the number of ChildAttribute objects related by a many-to-many relationship
  * to the current object by way of the attribute_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 ChildAttribute objects
  */
 public function countAttributes($criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     if (null === $this->collAttributes || null !== $criteria) {
         if ($this->isNew() && null === $this->collAttributes) {
             return 0;
         } else {
             $query = ChildAttributeQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByTemplate($this)->count($con);
         }
     } else {
         return count($this->collAttributes);
     }
 }
Example #10
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Attribute::setDeleted()
  * @see Attribute::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(AttributeTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAttributeQuery::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;
     }
 }
Example #11
0
 /**
  * Performs an INSERT on the database, given a Attribute or Criteria object.
  *
  * @param mixed               $criteria Criteria or Attribute 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(AttributeTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Attribute object
     }
     if ($criteria->containsKey(AttributeTableMap::ID) && $criteria->keyContainsValue(AttributeTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AttributeTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AttributeQuery::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;
 }
Example #12
0
 /**
  * Changes position, selecting absolute ou relative change.
  *
  * @param CategoryChangePositionEvent $event
  */
 public function updatePosition(UpdatePositionEvent $event)
 {
     $this->genericUpdatePosition(AttributeQuery::create(), $event);
 }
Example #13
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(AttributeQuery::create(), $event, $dispatcher);
 }
 public function addAttributeValueToCombinationAction($productId, $attributeAvId, $combination)
 {
     $result = array();
     // Get attribute for this product
     $attributeAv = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAvId);
     if ($attributeAv !== null) {
         $addIt = true;
         $attribute = AttributeQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAv->getAttributeId());
         // Check if this attribute is not already present
         $combinationArray = explode(',', $combination);
         foreach ($combinationArray as $id) {
             $attrAv = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($id);
             if ($attrAv !== null) {
                 if ($attrAv->getId() == $attributeAv->getId()) {
                     $result['error'] = $this->getTranslator()->trans('A value for attribute "%name" is already present in the combination', array('%name' => $attribute->getTitle() . " : " . $attributeAv->getTitle()));
                     $addIt = false;
                 }
                 $subAttribute = AttributeQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAv->getAttributeId());
                 $result[] = array('id' => $attrAv->getId(), 'title' => $subAttribute->getTitle() . " : " . $attrAv->getTitle());
             }
         }
         if ($addIt) {
             $result[] = array('id' => $attributeAv->getId(), 'title' => $attribute->getTitle() . " : " . $attributeAv->getTitle());
         }
     }
     return $this->jsonResponse(json_encode($result));
 }