public function handleOrder(VirtualProductOrderHandleEvent $event) { $documentId = MetaDataQuery::getVal('virtual', MetaDataModel::PSE_KEY, $event->getPseId()); if (null !== $documentId) { $productDocument = ProductDocumentQuery::create()->findPk($documentId); if (null !== $productDocument) { $event->setPath($productDocument->getFile()); } } }
public function preImport() { // Delete table before proceeding ProductQuery::create()->deleteAll(); ProductImageQuery::create()->deleteAll(); ProductDocumentQuery::create()->deleteAll(); TaxRuleQuery::create()->deleteAll(); TaxQuery::create()->deleteAll(); ProductSaleElementsQuery::create()->deleteAll(); ProductPriceQuery::create()->deleteAll(); // Create T1 <-> T2 IDs correspondance tables $this->product_corresp->reset(); $this->tax_corresp->reset(); // Importer les taxes $this->importTaxes(); }
public function testAssociatePSEDocument() { /** * Get a product sale elements which has a related product image */ $pse = ProductSaleElementsQuery::create()->useProductQuery()->joinProductDocument()->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 */ $productDocument = ProductDocumentQuery::create()->findOneByProductId($pse->getProductId()); $association = ProductSaleElementsProductDocumentQuery::create()->filterByProductSaleElements($pse)->findOneByProductDocumentId($productDocument->getId()); $isAssociated = $association !== null; $this->controller->getAssociationResponseData($pse->getId(), "document", $productDocument->getId()); $newAssociation = ProductSaleElementsProductDocumentQuery::create()->filterByProductSaleElements($pse)->findOneByProductDocumentId($productDocument->getId()); $isNowAssociated = $newAssociation !== null; $this->assertFalse($isAssociated === $isNowAssociated); }
/** * Gets the number of ChildProductDocument objects related by a many-to-many relationship * to the current object by way of the product_sale_elements_product_document 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 ChildProductDocument objects */ public function countProductDocuments($criteria = null, $distinct = false, ConnectionInterface $con = null) { if (null === $this->collProductDocuments || null !== $criteria) { if ($this->isNew() && null === $this->collProductDocuments) { return 0; } else { $query = ChildProductDocumentQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByProductSaleElements($this)->count($con); } } else { return count($this->collProductDocuments); } }
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(); Model\ProductPriceQuery::create()->deleteAll(); Model\BrandQuery::create()->deleteAll(); Model\BrandI18nQuery::create()->deleteAll(); Model\ProductImageQuery::create()->deleteAll(); Model\CategoryImageQuery::create()->deleteAll(); Model\FolderImageQuery::create()->deleteAll(); Model\ContentImageQuery::create()->deleteAll(); Model\BrandImageQuery::create()->deleteAll(); Model\ProductDocumentQuery::create()->deleteAll(); Model\CategoryDocumentQuery::create()->deleteAll(); Model\FolderDocumentQuery::create()->deleteAll(); Model\ContentDocumentQuery::create()->deleteAll(); Model\BrandDocumentQuery::create()->deleteAll(); Model\CouponQuery::create()->deleteAll(); Model\OrderQuery::create()->deleteAll(); Model\SaleQuery::create()->deleteAll(); Model\SaleProductQuery::create()->deleteAll(); Model\MetaDataQuery::create()->deleteAll(); $stmt = $con->prepare("SET foreign_key_checks = 1"); $stmt->execute(); echo "Creating customers\n"; //API $api = new Thelia\Model\Api(); $api->setProfileId(null)->setApiKey('79E95BD784CADA0C9A578282E')->setLabel("test")->save();
public function testSearchByProductId() { $document = ProductDocumentQuery::create()->findOne(); $this->baseTestSearchById($document->getId(), array('source' => 'product')); }
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; }
protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, CurrencyModel $currency, LangModel $lang, CartModel $cart, CustomerModel $customer) { $con = \Propel\Runtime\Propel::getConnection(OrderTableMap::DATABASE_NAME); $con->beginTransaction(); $placedOrder = $sessionOrder->copy(); $placedOrder->setDispatcher($dispatcher); $deliveryAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenDeliveryAddress()); $taxCountry = $deliveryAddress->getCountry(); $invoiceAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenInvoiceAddress()); $cartItems = $cart->getCartItems(); /* fulfill order */ $placedOrder->setCustomerId($customer->getId()); $placedOrder->setCurrencyId($currency->getId()); $placedOrder->setCurrencyRate($currency->getRate()); $placedOrder->setLangId($lang->getId()); /* hard save the delivery and invoice addresses */ $deliveryOrderAddress = new OrderAddress(); $deliveryOrderAddress->setCustomerTitleId($deliveryAddress->getTitleId())->setCompany($deliveryAddress->getCompany())->setFirstname($deliveryAddress->getFirstname())->setLastname($deliveryAddress->getLastname())->setAddress1($deliveryAddress->getAddress1())->setAddress2($deliveryAddress->getAddress2())->setAddress3($deliveryAddress->getAddress3())->setZipcode($deliveryAddress->getZipcode())->setCity($deliveryAddress->getCity())->setPhone($deliveryAddress->getPhone())->setCountryId($deliveryAddress->getCountryId())->save($con); $invoiceOrderAddress = new OrderAddress(); $invoiceOrderAddress->setCustomerTitleId($invoiceAddress->getTitleId())->setCompany($invoiceAddress->getCompany())->setFirstname($invoiceAddress->getFirstname())->setLastname($invoiceAddress->getLastname())->setAddress1($invoiceAddress->getAddress1())->setAddress2($invoiceAddress->getAddress2())->setAddress3($invoiceAddress->getAddress3())->setZipcode($invoiceAddress->getZipcode())->setCity($invoiceAddress->getCity())->setPhone($invoiceAddress->getPhone())->setCountryId($invoiceAddress->getCountryId())->save($con); $placedOrder->setDeliveryOrderAddressId($deliveryOrderAddress->getId()); $placedOrder->setInvoiceOrderAddressId($invoiceOrderAddress->getId()); $placedOrder->setStatusId(OrderStatusQuery::getNotPaidStatus()->getId()); $placedOrder->setCart($cart); /* memorize discount */ $placedOrder->setDiscount($cart->getDiscount()); $placedOrder->save($con); /* fulfill order_products and decrease stock */ foreach ($cartItems as $cartItem) { $product = $cartItem->getProduct(); /* get translation */ $productI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'Product', $product->getId()); $pse = $cartItem->getProductSaleElements(); /* check still in stock */ if ($cartItem->getQuantity() > $pse->getQuantity() && true === ConfigQuery::checkAvailableStock() && 0 === $product->getVirtual()) { throw new TheliaProcessException("Not enough stock", TheliaProcessException::CART_ITEM_NOT_ENOUGH_STOCK, $cartItem); } if (0 === $product->getVirtual()) { /* decrease stock for non virtual product */ $allowNegativeStock = intval(ConfigQuery::read('allow_negative_stock', 0)); $newStock = $pse->getQuantity() - $cartItem->getQuantity(); //Forbid negative stock if ($newStock < 0 && 0 === $allowNegativeStock) { $newStock = 0; } $pse->setQuantity($newStock); $pse->save($con); } /* get tax */ $taxRuleI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'TaxRule', $product->getTaxRuleId()); $taxDetail = $product->getTaxRule()->getTaxDetail($product, $taxCountry, $cartItem->getPrice(), $cartItem->getPromoPrice(), $lang->getLocale()); // get the virtual document path $virtualDocumentPath = null; if ($product->getVirtual() === 1) { // try to find the associated document if (null !== ($documentId = MetaDataQuery::getVal('virtual', MetaDataModel::PSE_KEY, $pse->getId()))) { $productDocument = ProductDocumentQuery::create()->findPk($documentId); if (null !== $productDocument) { $virtualDocumentPath = $productDocument->getFile(); } } } $orderProduct = new OrderProduct(); $orderProduct->setOrderId($placedOrder->getId())->setProductRef($product->getRef())->setProductSaleElementsRef($pse->getRef())->setProductSaleElementsId($pse->getId())->setTitle($productI18n->getTitle())->setChapo($productI18n->getChapo())->setDescription($productI18n->getDescription())->setPostscriptum($productI18n->getPostscriptum())->setVirtual($product->getVirtual())->setVirtualDocument($virtualDocumentPath)->setQuantity($cartItem->getQuantity())->setPrice($cartItem->getPrice())->setPromoPrice($cartItem->getPromoPrice())->setWasNew($pse->getNewness())->setWasInPromo($cartItem->getPromo())->setWeight($pse->getWeight())->setTaxRuleTitle($taxRuleI18n->getTitle())->setTaxRuleDescription($taxRuleI18n->getDescription())->setEanCode($pse->getEanCode())->setCartIemId($cartItem->getId())->setDispatcher($dispatcher)->save($con); /* fulfill order_product_tax */ foreach ($taxDetail as $tax) { $tax->setOrderProductId($orderProduct->getId()); $tax->save($con); } /* fulfill order_attribute_combination and decrease stock */ foreach ($pse->getAttributeCombinations() as $attributeCombination) { $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $attributeCombination->getAttributeId()); $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId()); $orderAttributeCombination = new OrderProductAttributeCombination(); $orderAttributeCombination->setOrderProductId($orderProduct->getId())->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($con); } } $con->commit(); return $placedOrder; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see ProductDocument::setDeleted() * @see ProductDocument::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(ProductDocumentTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildProductDocumentQuery::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; } }
$accessory = Thelia\Model\AccessoryQuery::create()->find(); $accessory->delete(); $stock = \Thelia\Model\ProductSaleElementsQuery::create()->find(); $stock->delete(); $productPrice = \Thelia\Model\ProductPriceQuery::create()->find(); $productPrice->delete(); $brand = Thelia\Model\BrandQuery::create()->find(); $brand->delete(); $brand = Thelia\Model\BrandI18nQuery::create()->find(); $brand->delete(); \Thelia\Model\ProductImageQuery::create()->find()->delete(); \Thelia\Model\CategoryImageQuery::create()->find()->delete(); \Thelia\Model\FolderImageQuery::create()->find()->delete(); \Thelia\Model\ContentImageQuery::create()->find()->delete(); \Thelia\Model\BrandImageQuery::create()->find()->delete(); \Thelia\Model\ProductDocumentQuery::create()->find()->delete(); \Thelia\Model\CategoryDocumentQuery::create()->find()->delete(); \Thelia\Model\FolderDocumentQuery::create()->find()->delete(); \Thelia\Model\ContentDocumentQuery::create()->find()->delete(); \Thelia\Model\BrandDocumentQuery::create()->find()->delete(); \Thelia\Model\CouponQuery::create()->find()->delete(); \Thelia\Model\OrderQuery::create()->find()->delete(); \Thelia\Model\SaleQuery::create()->find()->delete(); \Thelia\Model\SaleProductQuery::create()->find()->delete(); \Thelia\Model\MetaDataQuery::create()->find()->delete(); $stmt = $con->prepare("SET foreign_key_checks = 1"); $stmt->execute(); echo "Creating customers\n"; //API $api = new Thelia\Model\Api(); $api->setProfileId(null)->setApiKey('79E95BD784CADA0C9A578282E')->setLabel("test")->save();
/** * @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; } } }
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(); } }
/** * Returns the number of related ProductDocument objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related ProductDocument objects. * @throws PropelException */ public function countProductDocuments(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collProductDocumentsPartial && !$this->isNew(); if (null === $this->collProductDocuments || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collProductDocuments) { return 0; } if ($partial && !$criteria) { return count($this->getProductDocuments()); } $query = ChildProductDocumentQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByProduct($this)->count($con); } return count($this->collProductDocuments); }
public function cloneFile(ProductCloneEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $originalProductId = $event->getOriginalProduct()->getId(); $clonedProduct = $event->getClonedProduct(); foreach ($event->getTypes() as $type) { $originalProductFiles = []; switch ($type) { case 'images': $originalProductFiles = ProductImageQuery::create()->findByProductId($originalProductId); break; case 'documents': $originalProductFiles = ProductDocumentQuery::create()->findByProductId($originalProductId); break; } // Set clone's files /** @var ProductDocument|ProductImage $originalProductFile */ foreach ($originalProductFiles as $originalProductFile) { $srcPath = $originalProductFile->getUploadDir() . DS . $originalProductFile->getFile(); if (file_exists($srcPath)) { $ext = pathinfo($srcPath, PATHINFO_EXTENSION); $clonedProductFile = []; switch ($type) { case 'images': $fileName = $clonedProduct->getRef() . '.' . $ext; $clonedProductFile = new ProductImage(); break; case 'documents': $fileName = pathinfo($originalProductFile->getFile(), PATHINFO_FILENAME) . '-' . $clonedProduct->getRef() . '.' . $ext; $clonedProductFile = new ProductDocument(); break; } // Copy a temporary file of the source file as it will be deleted by IMAGE_SAVE or DOCUMENT_SAVE event $srcTmp = $srcPath . '.tmp'; copy($srcPath, $srcTmp); // Get file mimeType $finfo = new \finfo(); $fileMimeType = $finfo->file($srcPath, FILEINFO_MIME_TYPE); // Get file event's parameters $clonedProductFile->setProductId($clonedProduct->getId())->setVisible($originalProductFile->getVisible())->setPosition($originalProductFile->getPosition())->setLocale($clonedProduct->getLocale())->setTitle($clonedProduct->getTitle()); $clonedProductCopiedFile = new UploadedFile($srcPath, $fileName, $fileMimeType, filesize($srcPath), null, true); // Create and dispatch event $clonedProductCreateFileEvent = new FileCreateOrUpdateEvent($clonedProduct->getId()); $clonedProductCreateFileEvent->setModel($clonedProductFile)->setUploadedFile($clonedProductCopiedFile)->setParentName($clonedProduct->getTitle()); $originalProductFileI18ns = []; switch ($type) { case 'images': $dispatcher->dispatch(TheliaEvents::IMAGE_SAVE, $clonedProductCreateFileEvent); // Get original product image I18n $originalProductFileI18ns = ProductImageI18nQuery::create()->findById($originalProductFile->getId()); break; case 'documents': $dispatcher->dispatch(TheliaEvents::DOCUMENT_SAVE, $clonedProductCreateFileEvent); // Get original product document I18n $originalProductFileI18ns = ProductDocumentI18nQuery::create()->findById($originalProductFile->getId()); break; } // Set temporary source file as original one rename($srcTmp, $srcPath); // Clone file's I18n $this->cloneFileI18n($originalProductFileI18ns, $clonedProductFile, $type, $event, $dispatcher); } else { Tlog::getInstance()->addWarning("Failed to find media file {$srcPath}"); } } } }
/** * Get the associated ChildProductDocument object * * @param ConnectionInterface $con Optional Connection object. * @return ChildProductDocument The associated ChildProductDocument object. * @throws PropelException */ public function getProductDocument(ConnectionInterface $con = null) { if ($this->aProductDocument === null && $this->product_document_id !== null) { $this->aProductDocument = ChildProductDocumentQuery::create()->findPk($this->product_document_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->aProductDocument->addProductSaleElementsProductDocuments($this); */ } return $this->aProductDocument; }
/** * Performs an INSERT on the database, given a ProductDocument or Criteria object. * * @param mixed $criteria Criteria or ProductDocument 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(ProductDocumentTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from ProductDocument object } if ($criteria->containsKey(ProductDocumentTableMap::ID) && $criteria->keyContainsValue(ProductDocumentTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductDocumentTableMap::ID . ')'); } // Set the correct dbName $query = ProductDocumentQuery::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; }
public function testCopyUploadedFileProductDocument() { $this->dotTestDocumentUpload(ProductDocumentQuery::create()->findOne(), 'product'); }
/** * Delete a product entry * * @param \Thelia\Core\Event\Product\ProductDeleteEvent $event */ public function delete(ProductDeleteEvent $event) { if (null !== ($product = ProductQuery::create()->findPk($event->getProductId()))) { $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME); $con->beginTransaction(); try { // Get product's files to delete after product deletion $fileList['images']['list'] = ProductImageQuery::create()->findByProductId($event->getProductId()); $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE; $fileList['documentList']['list'] = ProductDocumentQuery::create()->findByProductId($event->getProductId()); $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE; // Delete product $product->setDispatcher($event->getDispatcher())->delete($con); $event->setProduct($product); // Dispatch delete product's files event foreach ($fileList as $fileTypeList) { foreach ($fileTypeList['list'] as $fileToDelete) { $fileDeleteEvent = new FileDeleteEvent($fileToDelete); $event->getDispatcher()->dispatch($fileTypeList['type'], $fileDeleteEvent); } } $con->commit(); } catch (\Exception $e) { $con->rollback(); throw $e; } } }