Exemplo n.º 1
0
 /**
  * @param    ProductDocument $productDocument The productDocument object to add.
  */
 protected function doAddProductDocument($productDocument)
 {
     $productSaleElementsProductDocument = new ChildProductSaleElementsProductDocument();
     $productSaleElementsProductDocument->setProductDocument($productDocument);
     $this->addProductSaleElementsProductDocument($productSaleElementsProductDocument);
     // set the back reference to this object directly as using provided method either results
     // in endless loop or in multiple relations
     if (!$productDocument->getProductSaleElementss()->contains($this)) {
         $foreignCollection = $productDocument->getProductSaleElementss();
         $foreignCollection[] = $this;
     }
 }
Exemplo n.º 2
0
 public function getAssociationResponseData($pseId, $type, $typeId)
 {
     $responseData = [];
     if (null !== ($msg = $this->checkFileType($type))) {
         throw new \Exception($msg);
     }
     $responseData["product_sale_elements_id"] = $pseId;
     $pse = ProductSaleElementsQuery::create()->findPk($pseId);
     if (null === $pse) {
         throw new \Exception($this->getTranslator()->trans("The product sale elements id %id doesn't exists", ["%id" => $pseId]));
     }
     $assoc = null;
     if ($type === "image") {
         $image = ProductImageQuery::create()->findPk($typeId);
         if (null === $image) {
             throw new \Exception($this->getTranslator()->trans("The product image id %id doesn't exists", ["%id" => $typeId]));
         }
         $assoc = ProductSaleElementsProductImageQuery::create()->filterByProductSaleElementsId($pseId)->findOneByProductImageId($typeId);
         if (null === $assoc) {
             $assoc = new ProductSaleElementsProductImage();
             $assoc->setProductSaleElementsId($pseId)->setProductImageId($typeId)->save();
         } else {
             $assoc->delete();
         }
         $responseData["product_image_id"] = $typeId;
         $responseData["is-associated"] = (int) (!$assoc->isDeleted());
     } elseif ($type === "document") {
         $image = ProductDocumentQuery::create()->findPk($typeId);
         if (null === $image) {
             throw new \Exception($this->getTranslator()->trans("The product document id %id doesn't exists", ["%id" => $pseId]));
         }
         $assoc = ProductSaleElementsProductDocumentQuery::create()->filterByProductSaleElementsId($pseId)->findOneByProductDocumentId($typeId);
         if (null === $assoc) {
             $assoc = new ProductSaleElementsProductDocument();
             $assoc->setProductSaleElementsId($pseId)->setProductDocumentId($typeId)->save();
         } else {
             $assoc->delete();
         }
         $responseData["product_document_id"] = $typeId;
         $responseData["is-associated"] = (int) (!$assoc->isDeleted());
     } elseif ($type === "virtual") {
         $image = ProductDocumentQuery::create()->findPk($typeId);
         if (null === $image) {
             throw new \Exception($this->getTranslator()->trans("The product document id %id doesn't exists", ["%id" => $pseId]));
         }
         $documentId = intval(MetaDataQuery::getVal('virtual', MetaData::PSE_KEY, $pseId));
         if ($documentId === intval($typeId)) {
             $assocEvent = new MetaDataDeleteEvent('virtual', MetaData::PSE_KEY, $pseId);
             $this->dispatch(TheliaEvents::META_DATA_DELETE, $assocEvent);
             $responseData["is-associated"] = 0;
         } else {
             $assocEvent = new MetaDataCreateOrUpdateEvent('virtual', MetaData::PSE_KEY, $pseId, $typeId);
             $this->dispatch(TheliaEvents::META_DATA_UPDATE, $assocEvent);
             $responseData["is-associated"] = 1;
         }
         $responseData["product_document_id"] = $typeId;
     }
     return $responseData;
 }
Exemplo n.º 3
0
 /**
  * Filter the query by a related \Thelia\Model\ProductSaleElementsProductDocument object
  *
  * @param \Thelia\Model\ProductSaleElementsProductDocument|ObjectCollection $productSaleElementsProductDocument  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildProductDocumentQuery The current query, for fluid interface
  */
 public function filterByProductSaleElementsProductDocument($productSaleElementsProductDocument, $comparison = null)
 {
     if ($productSaleElementsProductDocument instanceof \Thelia\Model\ProductSaleElementsProductDocument) {
         return $this->addUsingAlias(ProductDocumentTableMap::ID, $productSaleElementsProductDocument->getProductDocumentId(), $comparison);
     } elseif ($productSaleElementsProductDocument instanceof ObjectCollection) {
         return $this->useProductSaleElementsProductDocumentQuery()->filterByPrimaryKeys($productSaleElementsProductDocument->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByProductSaleElementsProductDocument() only accepts arguments of type \\Thelia\\Model\\ProductSaleElementsProductDocument or Collection');
     }
 }
Exemplo n.º 4
0
 public function clonePSEAssociatedFiles($clonedProductId, $clonedProductPSEId, $originalProductPSEFiles, $type)
 {
     /** @var ProductSaleElementsDocument|ProductSaleElementsImage $originalProductPSEFile */
     foreach ($originalProductPSEFiles as $originalProductPSEFile) {
         $originalProductFilePositionQuery = [];
         $originalProductPSEFileId = null;
         // Get file's original position
         switch ($type) {
             case 'image':
                 $originalProductFilePositionQuery = ProductImageQuery::create();
                 $originalProductPSEFileId = $originalProductPSEFile->getProductImageId();
                 break;
             case 'document':
                 $originalProductFilePositionQuery = ProductDocumentQuery::create();
                 $originalProductPSEFileId = $originalProductPSEFile->getProductDocumentId();
                 break;
         }
         $originalProductFilePosition = $originalProductFilePositionQuery->select(['POSITION'])->findPk($originalProductPSEFileId);
         // Get cloned file ID to link to the cloned PSE
         switch ($type) {
             case 'image':
                 $clonedProductFileIdToLinkToPSEQuery = ProductImageQuery::create();
                 break;
             case 'document':
                 $clonedProductFileIdToLinkToPSEQuery = ProductDocumentQuery::create();
                 break;
         }
         $clonedProductFileIdToLinkToPSE = $clonedProductFileIdToLinkToPSEQuery->filterByProductId($clonedProductId)->filterByPosition($originalProductFilePosition)->select(['ID'])->findOne();
         // Save association
         switch ($type) {
             case 'image':
                 $assoc = new ProductSaleElementsProductImage();
                 $assoc->setProductImageId($clonedProductFileIdToLinkToPSE);
                 break;
             case 'document':
                 $assoc = new ProductSaleElementsProductDocument();
                 $assoc->setProductDocumentId($clonedProductFileIdToLinkToPSE);
                 break;
         }
         $assoc->setProductSaleElementsId($clonedProductPSEId)->save();
     }
 }
 /**
  * Exclude object from result
  *
  * @param   ChildProductSaleElementsProductDocument $productSaleElementsProductDocument Object to remove from the list of results
  *
  * @return ChildProductSaleElementsProductDocumentQuery The current query, for fluid interface
  */
 public function prune($productSaleElementsProductDocument = null)
 {
     if ($productSaleElementsProductDocument) {
         $this->addUsingAlias(ProductSaleElementsProductDocumentTableMap::ID, $productSaleElementsProductDocument->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }