/**
  * Save the attribute combinations for the order from our cart item attribute combinations.
  *
  * @param OrderEvent $event
  *
  * @throws PropelException
  */
 public function createOrderProductAttributeCombinations(OrderEvent $event)
 {
     $legacyCartItemAttributeCombinations = LegacyCartItemAttributeCombinationQuery::create()->findByCartItemId($event->getCartItemId());
     // works with Thelia 2.2
     if (method_exists($event, 'getId')) {
         $orderProductId = $event->getId();
     } else {
         // Thelia 2.1 however does not provides the order product id in the event
         // Since the order contains potentially identical (for Thelia) cart items that are only differentiated
         // by the cart item attribute combinations that we are storing ourselves, we cannot use information
         // such as PSE id to cross reference the cart item we are given to the order product that was created from
         // it (as far as I can tell).
         // So we will ASSUME that the order product with the higher id is the one created from this cart item.
         // This is PROBABLY TRUE on a basic Thelia install with no modules messing with the cart and orders in a way
         // that create additional order products, BUT NOT IN GENERAL !
         // This also assumes that ids are generated incrementally, which is NOT GUARANTEED (but true for MySQL
         // with default settings).
         // The creation date was previously used but is even less reliable.
         // FIXME: THIS IS NOT A SANE WAY TO DO THIS
         $orderProductId = OrderProductQuery::create()->orderById(Criteria::DESC)->findOne()->getId();
     }
     $lang = $this->request->getSession()->getLang();
     /** @var LegacyCartItemAttributeCombination $legacyCartItemAttributeCombination */
     foreach ($legacyCartItemAttributeCombinations as $legacyCartItemAttributeCombination) {
         /** @var Attribute $attribute */
         $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $legacyCartItemAttributeCombination->getAttributeId());
         /** @var AttributeAv $attributeAv */
         $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $legacyCartItemAttributeCombination->getAttributeAvId());
         (new OrderProductAttributeCombination())->setOrderProductId($orderProductId)->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save();
     }
 }
 public function buildModelCriteria()
 {
     $query = LegacyCartItemAttributeCombinationQuery::create();
     $this->configureI18nProcessing($query, ['TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'], AttributeTableMap::TABLE_NAME, 'ATTRIBUTE_ID');
     $this->configureI18nProcessing($query, ['TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'], AttributeAvTableMap::TABLE_NAME, 'ATTRIBUTE_AV_ID');
     $cartItemId = $this->getArgValue('cart_item');
     if ($cartItemId !== null) {
         $query->filterByCartItemId($cartItemId);
     }
     return $query;
 }
 /**
  * @inheritdoc
  *
  * Find a possible existing cart item by also filtering on our cart item attribute combinations.
  */
 protected function findItem($cartId, $productId, $productSaleElementsId)
 {
     // no legacy attributes, let the parent handle it
     if (empty($this->legacyProductAttributes)) {
         return parent::findItem($cartId, $productId, $productSaleElementsId);
     }
     $query = CartItemQuery::create();
     $query->filterByCartId($cartId)->filterByProductId($productId)->filterByProductSaleElementsId($productSaleElementsId);
     /** @var CartItem $cartItem */
     foreach ($query->find() as $cartItem) {
         $legacyCartItemAttributeCombinations = LegacyCartItemAttributeCombinationQuery::create()->findByCartItemId($cartItem->getId());
         $cartItemLegacyProductAttributes = [];
         /** @var LegacyCartItemAttributeCombination $legacyCartItemAttributeCombination */
         foreach ($legacyCartItemAttributeCombinations as $legacyCartItemAttributeCombination) {
             $cartItemLegacyProductAttributes[$legacyCartItemAttributeCombination->getAttributeId()] = $legacyCartItemAttributeCombination->getAttributeAvId();
         }
         if ($cartItemLegacyProductAttributes == $this->legacyProductAttributes) {
             return $cartItem;
         }
     }
     return null;
 }
 /**
  * Performs an INSERT on the database, given a LegacyCartItemAttributeCombination or Criteria object.
  *
  * @param mixed               $criteria Criteria or LegacyCartItemAttributeCombination 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(LegacyCartItemAttributeCombinationTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from LegacyCartItemAttributeCombination object
     }
     // Set the correct dbName
     $query = LegacyCartItemAttributeCombinationQuery::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;
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see LegacyCartItemAttributeCombination::setDeleted()
  * @see LegacyCartItemAttributeCombination::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(LegacyCartItemAttributeCombinationTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildLegacyCartItemAttributeCombinationQuery::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;
     }
 }