Exemplo n.º 1
0
 public function buildModelCriteria()
 {
     $search = AttributeCombinationQuery::create();
     /* manage attribute translations */
     $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), AttributeTableMap::TABLE_NAME, 'ATTRIBUTE_ID');
     /* manage attributeAv translations */
     $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), AttributeAvTableMap::TABLE_NAME, 'ATTRIBUTE_AV_ID');
     $productSaleElements = $this->getProduct_sale_elements();
     $search->filterByProductSaleElementsId($productSaleElements, Criteria::EQUAL);
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn(AttributeTableMap::TABLE_NAME . '_i18n_TITLE');
                 break;
             case "alpha_reverse":
                 $search->addDescendingOrderByColumn(AttributeTableMap::TABLE_NAME . '_i18n_TITLE');
                 break;
         }
     }
     return $search;
 }
Exemplo n.º 2
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this ProductSaleElements is new, it will return
  * an empty collection; or if this ProductSaleElements has previously
  * been saved, it will retrieve related AttributeCombinations 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 ProductSaleElements.
  *
  * @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|ChildAttributeCombination[] List of ChildAttributeCombination objects
  */
 public function getAttributeCombinationsJoinAttributeAv($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildAttributeCombinationQuery::create(null, $criteria);
     $query->joinWith('AttributeAv', $joinBehavior);
     return $this->getAttributeCombinations($query, $con);
 }
Exemplo n.º 3
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see AttributeCombination::setDeleted()
  * @see AttributeCombination::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(AttributeCombinationTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAttributeCombinationQuery::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;
     }
 }
Exemplo n.º 4
0
    $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();
    Model\FolderQuery::create()->deleteAll();
Exemplo n.º 5
0
 /**
  * @covers Thelia\Action\ProductSaleElement::createClonePSE
  * @depends testCloneFile
  * @param ProductCloneEvent $event
  * @return ProductCloneEvent
  */
 public function testCreateClonePSE(ProductCloneEvent $event)
 {
     $originalProductPSE = ProductSaleElementsQuery::create()->filterByProductId($event->getOriginalProduct()->getId())->findOne();
     $currencyId = ProductPriceQuery::create()->filterByProductSaleElementsId($originalProductPSE->getId())->select('CURRENCY_ID')->findOne();
     // Call function to test
     $action = new ProductSaleElement();
     $clonedProductPSEId = $action->createClonePSE($event, $originalProductPSE, $currencyId);
     // Get created PSE
     $cloneProductPSE = ProductSaleElementsQuery::create()->findOneById($clonedProductPSEId);
     // Check clone PSE information
     $this->assertInstanceOf('Thelia\\Model\\ProductSaleElements', $cloneProductPSE, 'Instance of clone PSE must be Thelia\\Model\\ProductSaleElements');
     $this->assertEquals($event->getClonedProduct()->getId(), $cloneProductPSE->getProductId(), 'ProductID must be equal');
     $this->assertStringStartsWith($event->getClonedProduct()->getRef(), $cloneProductPSE->getRef(), 'PSE\'s ref must start with product\'s ref');
     $this->assertEquals($originalProductPSE->getWeight(), $cloneProductPSE->getWeight(), 'Weight must be equal');
     // Get attribute combination
     $originalAttributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($originalProductPSE->getId());
     $cloneAttributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($clonedProductPSEId);
     // Check clone PSE's attribute combination if exist
     if ($cloneAttributeCombination != null) {
         $this->assertInstanceOf('Thelia\\Model\\AttributeCombination', $cloneAttributeCombination, 'Instance of clone PSE\'s attribute combination must be Thelia\\Model\\AttributeCombination');
         $this->assertEquals($originalAttributeCombination->getAttributeId(), $cloneAttributeCombination->getAttributeId(), 'AttributeID must be equal');
         $this->assertEquals($originalAttributeCombination->getAttributeAvId(), $cloneAttributeCombination->getAttributeAvId(), 'AttributeAvID must be equal');
         $this->assertEquals($clonedProductPSEId, $cloneAttributeCombination->getProductSaleElementsId(), 'PSE ID must be equal');
     }
     return ['event' => $event, 'originalPSE' => $originalProductPSE, 'clonePSE' => $cloneProductPSE];
 }
Exemplo n.º 6
0
 public function setProductTemplate(ProductSetTemplateEvent $event)
 {
     $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         $product = $event->getProduct();
         // Delete all product feature relations
         if (null !== ($featureProducts = FeatureProductQuery::create()->findByProductId($product->getId()))) {
             /** @var \Thelia\Model\FeatureProduct $featureProduct */
             foreach ($featureProducts as $featureProduct) {
                 $eventDelete = new FeatureProductDeleteEvent($product->getId(), $featureProduct->getFeatureId());
                 $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $eventDelete);
             }
         }
         // Delete all product attributes sale elements
         AttributeCombinationQuery::create()->filterByProductSaleElements($product->getProductSaleElementss())->delete($con);
         //Delete all productSaleElements except the default one (to keep price, weight, ean, etc...)
         ProductSaleElementsQuery::create()->filterByProduct($product)->filterByIsDefault(1, Criteria::NOT_EQUAL)->delete($con);
         // Update the product template
         $template_id = $event->getTemplateId();
         // Set it to null if it's zero.
         if ($template_id <= 0) {
             $template_id = null;
         }
         $product->setTemplateId($template_id)->save($con);
         //Be sure that the product has a default productSaleElements
         /** @var \Thelia\Model\ProductSaleElements $defaultPse */
         if (null == ($defaultPse = ProductSaleElementsQuery::create()->filterByProduct($product)->filterByIsDefault(1)->findOne())) {
             // Create a new default product sale element
             $product->createProductSaleElement($con, 0, 0, 0, $event->getCurrencyId(), true);
         }
         $product->clearProductSaleElementss();
         $event->setProduct($product);
         // Store all the stuff !
         $con->commit();
     } catch (\Exception $ex) {
         $con->rollback();
         throw $ex;
     }
 }
Exemplo n.º 7
0
 public function createClonePSE(ProductCloneEvent $event, ProductSaleElements $originalProductPSE, $currencyId)
 {
     $attributeCombinationList = AttributeCombinationQuery::create()->filterByProductSaleElementsId($originalProductPSE->getId())->select(['ATTRIBUTE_AV_ID'])->find();
     $clonedProductCreatePSEEvent = new ProductSaleElementCreateEvent($event->getClonedProduct(), $attributeCombinationList, $currencyId);
     $this->eventDispatcher->dispatch(TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT, $clonedProductCreatePSEEvent);
     return $clonedProductCreatePSEEvent->getProductSaleElement()->getId();
 }
 /**
  * Performs an INSERT on the database, given a AttributeCombination or Criteria object.
  *
  * @param mixed               $criteria Criteria or AttributeCombination 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(AttributeCombinationTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from AttributeCombination object
     }
     // Set the correct dbName
     $query = AttributeCombinationQuery::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;
 }
Exemplo n.º 9
0
 /**
  * @param AttributeCombinationQuery $search
  * @param string $order Criteria::ASC|Criteria::DESC
  * @return AttributeCombinationQuery
  */
 protected function orderByTemplateAttributePosition(AttributeCombinationQuery $search, $order)
 {
     $search->useProductSaleElementsQuery()->joinProduct()->endUse()->useAttributeQuery()->joinAttributeTemplate(AttributeTemplateTableMap::TABLE_NAME)->addJoinCondition(AttributeTemplateTableMap::TABLE_NAME, AttributeTemplateTableMap::TEMPLATE_ID . Criteria::EQUAL . ProductTableMap::TEMPLATE_ID)->endUse()->orderBy(AttributeTemplateTableMap::POSITION, $order);
     return $search;
 }