public function testAssociatePSEImage()
 {
     /**
      * Get a product sale elements which has a related product image
      */
     $pse = ProductSaleElementsQuery::create()->useProductQuery()->joinProductImage()->endUse()->findOne();
     if (null === $pse) {
         $this->markTestSkipped("You must have at least one product_sale_elements which has a product_image related to it's product");
     }
     /**
      * Get this image and check if they are associated
      */
     $productImage = ProductImageQuery::create()->findOneByProductId($pse->getProductId());
     $association = ProductSaleElementsProductImageQuery::create()->filterByProductSaleElements($pse)->findOneByProductImageId($productImage->getId());
     $isAssociated = $association !== null;
     $this->controller->getAssociationResponseData($pse->getId(), "image", $productImage->getId());
     $newAssociation = ProductSaleElementsProductImageQuery::create()->filterByProductSaleElements($pse)->findOneByProductImageId($productImage->getId());
     $isNowAssociated = $newAssociation !== null;
     $this->assertFalse($isAssociated === $isNowAssociated);
 }
 /**
  * this method returns a Propel ModelCriteria
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildModelCriteria()
 {
     $query = ProductSaleElementsProductImageQuery::create();
     if (null !== ($id = $this->getId())) {
         $query->filterById($id);
     }
     if (null !== ($pseId = $this->getProductSaleElementsId())) {
         $query->filterByProductSaleElementsId($pseId);
     }
     if (null !== ($productImageId = $this->getProductImageId())) {
         $query->filterByProductImageId($id);
     }
     foreach ($this->getOrder() as $order) {
         switch ($order) {
             case "position":
                 $query->useProductImageQuery()->orderByPosition(Criteria::ASC)->endUse();
                 break;
             case "position-reverse":
                 $query->useProductImageQuery()->orderByPosition(Criteria::DESC)->endUse();
                 break;
         }
     }
     return $query;
 }
Example #3
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this ProductImage is new, it will return
  * an empty collection; or if this ProductImage has previously
  * been saved, it will retrieve related ProductSaleElementsProductImages 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 ProductImage.
  *
  * @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|ChildProductSaleElementsProductImage[] List of ChildProductSaleElementsProductImage objects
  */
 public function getProductSaleElementsProductImagesJoinProductSaleElements($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildProductSaleElementsProductImageQuery::create(null, $criteria);
     $query->joinWith('ProductSaleElements', $joinBehavior);
     return $this->getProductSaleElementsProductImages($query, $con);
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see ProductSaleElementsProductImage::setDeleted()
  * @see ProductSaleElementsProductImage::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(ProductSaleElementsProductImageTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildProductSaleElementsProductImageQuery::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 #5
0
 protected function getPSEImages(ProductSaleElementsModel $pse)
 {
     /**
      * Compute images with the associated loop
      */
     $imageLoop = new Image($this->container);
     $imageLoop->initializeArgs(["product" => $pse->getProductId(), "width" => 100, "height" => 75, "resize_mode" => "borders"]);
     $images = $imageLoop->exec($imagePagination);
     $imageAssoc = ProductSaleElementsProductImageQuery::create()->filterByProductSaleElementsId($pse->getId())->find()->toArray();
     $data = [];
     /** @var \Thelia\Core\Template\Element\LoopResultRow $image */
     for ($images->rewind(); $images->valid(); $images->next()) {
         $image = $images->current();
         $isAssociated = $this->arrayHasEntries($imageAssoc, ["ProductImageId" => $image->get("ID"), "ProductSaleElementsId" => $pse->getId()]);
         $data[] = ["id" => $image->get("ID"), "url" => $image->get("IMAGE_URL"), "title" => $image->get("TITLE"), "is_associated" => $isAssociated, "filename" => $image->model->getFile()];
     }
     return $data;
 }
Example #6
0
 /**
  * @covers \Thelia\Action\ProductSaleElement::clonePSEAssociatedFiles
  * @depends testUpdateClonePSE
  * @param array $params
  */
 public function testClonePSEAssociatedFiles(array $params)
 {
     $event = $params['event'];
     $cloneProductId = $params['cloneProductId'];
     $clonePSEId = $params['clonePSEId'];
     $originalPSE = $params['originalPSE'];
     foreach ($event->getTypes() as $type) {
         switch ($type) {
             case 'images':
                 $originalPSEFiles = ProductSaleElementsProductImageQuery::create()->findByProductSaleElementsId($originalPSE->getId());
                 // Call function to test
                 $action = new ProductSaleElement();
                 $action->clonePSEAssociatedFiles($cloneProductId, $clonePSEId, $originalPSEFiles, 'image');
                 $originalPSEImages = ProductSaleElementsProductImageQuery::create()->findByProductSaleElementsId($originalPSE->getId());
                 $clonePSEImages = ProductSaleElementsProductImageQuery::create()->findByProductSaleElementsId($clonePSEId);
                 $this->assertEquals(count($originalPSEImages), count($clonePSEImages), 'There must be the same quantity of PSE product image');
                 foreach ($clonePSEImages as $clonePSEImage) {
                     $cloneProductImage = ProductImageQuery::create()->findOneById($clonePSEImage->getProductImageId());
                     $this->assertNotNull($cloneProductImage, 'Image linked to PSE must not be null');
                     $this->assertInstanceOf('Thelia\\Model\\ProductImage', $cloneProductImage, 'Instance of clone PSE\'s product image must be Thelia\\Model\\ProductImage');
                     $this->assertEquals($clonePSEId, $clonePSEImage->getProductSaleElementsId(), 'PSE ID must be equal');
                 }
                 break;
             case 'documents':
                 $originalPSEFiles = ProductSaleElementsProductDocumentQuery::create()->findByProductSaleElementsId($originalPSE->getId());
                 // Call function to test
                 $action = new ProductSaleElement();
                 $action->clonePSEAssociatedFiles($cloneProductId, $clonePSEId, $originalPSEFiles, 'document');
                 $originalPSEDocuments = ProductSaleElementsProductDocumentQuery::create()->findByProductSaleElementsId($originalPSE->getId());
                 $clonePSEDocuments = ProductSaleElementsProductDocumentQuery::create()->findByProductSaleElementsId($clonePSEId);
                 $this->assertEquals(count($originalPSEDocuments), count($clonePSEDocuments), 'There must be the same quantity of PSE product document');
                 foreach ($clonePSEDocuments as $clonePSEDocument) {
                     $cloneProductDocument = ProductDocumentQuery::create()->findOneById($clonePSEDocument->getProductDocumentId());
                     $this->assertNotNull($cloneProductDocument, 'Document linked to PSE must not be null');
                     $this->assertInstanceOf('Thelia\\Model\\ProductDocument', $cloneProductDocument, 'Instance of clone PSE\'s product document must be Thelia\\Model\\ProductDocument');
                     $this->assertEquals($clonePSEId, $clonePSEDocument->getProductSaleElementsId(), 'PSE ID must be equal');
                 }
                 break;
         }
     }
 }
 /**
  * Clone product's PSEs and associated datas
  *
  * @param ProductCloneEvent $event
  */
 public function clonePSE(ProductCloneEvent $event)
 {
     $clonedProduct = $event->getClonedProduct();
     // Get original product's PSEs
     $originalProductPSEs = ProductSaleElementsQuery::create()->orderByIsDefault(Criteria::DESC)->findByProductId($event->getOriginalProduct()->getId());
     /**
      * Handle PSEs
      *
      * @var int  $key
      * @var ProductSaleElements $originalProductPSE
      */
     foreach ($originalProductPSEs as $key => $originalProductPSE) {
         $currencyId = ProductPriceQuery::create()->filterByProductSaleElementsId($originalProductPSE->getId())->select('CURRENCY_ID')->findOne();
         // The default PSE, created at the same time as the clone product, is overwritten
         $clonedProductPSEId = $this->createClonePSE($event, $originalProductPSE, $currencyId);
         $this->updateClonePSE($event, $clonedProductPSEId, $originalProductPSE, $key);
         // PSE associated images
         $originalProductPSEImages = ProductSaleElementsProductImageQuery::create()->findByProductSaleElementsId($originalProductPSE->getId());
         if (null !== $originalProductPSEImages) {
             $this->clonePSEAssociatedFiles($clonedProduct->getId(), $clonedProductPSEId, $originalProductPSEImages, $type = 'image');
         }
         // PSE associated documents
         $originalProductPSEDocuments = ProductSaleElementsProductDocumentQuery::create()->findByProductSaleElementsId($originalProductPSE->getId());
         if (null !== $originalProductPSEDocuments) {
             $this->clonePSEAssociatedFiles($clonedProduct->getId(), $clonedProductPSEId, $originalProductPSEDocuments, $type = 'document');
         }
     }
 }
 /**
  * Performs an INSERT on the database, given a ProductSaleElementsProductImage or Criteria object.
  *
  * @param mixed               $criteria Criteria or ProductSaleElementsProductImage 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(ProductSaleElementsProductImageTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from ProductSaleElementsProductImage object
     }
     if ($criteria->containsKey(ProductSaleElementsProductImageTableMap::ID) && $criteria->keyContainsValue(ProductSaleElementsProductImageTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductSaleElementsProductImageTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = ProductSaleElementsProductImageQuery::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;
 }