function clearTables($con) { echo "Clearing tables\n"; $productAssociatedContent = Thelia\Model\ProductAssociatedContentQuery::create()->find($con); $productAssociatedContent->delete($con); $categoryAssociatedContent = Thelia\Model\CategoryAssociatedContentQuery::create()->find($con); $categoryAssociatedContent->delete($con); $featureProduct = Thelia\Model\FeatureProductQuery::create()->find($con); $featureProduct->delete($con); $attributeCombination = Thelia\Model\AttributeCombinationQuery::create()->find($con); $attributeCombination->delete($con); $feature = Thelia\Model\FeatureQuery::create()->find($con); $feature->delete($con); $feature = Thelia\Model\FeatureI18nQuery::create()->find($con); $feature->delete($con); $featureAv = Thelia\Model\FeatureAvQuery::create()->find($con); $featureAv->delete($con); $featureAv = Thelia\Model\FeatureAvI18nQuery::create()->find($con); $featureAv->delete($con); $attribute = Thelia\Model\AttributeQuery::create()->find($con); $attribute->delete($con); $attribute = Thelia\Model\AttributeI18nQuery::create()->find($con); $attribute->delete($con); $attributeAv = Thelia\Model\AttributeAvQuery::create()->find($con); $attributeAv->delete($con); $attributeAv = Thelia\Model\AttributeAvI18nQuery::create()->find($con); $attributeAv->delete($con); $brand = Thelia\Model\BrandQuery::create()->find($con); $brand->delete($con); $brand = Thelia\Model\BrandI18nQuery::create()->find($con); $brand->delete($con); $category = Thelia\Model\CategoryQuery::create()->find($con); $category->delete($con); $category = Thelia\Model\CategoryI18nQuery::create()->find($con); $category->delete($con); $product = Thelia\Model\ProductQuery::create()->find($con); $product->delete($con); $product = Thelia\Model\ProductI18nQuery::create()->find($con); $product->delete($con); $folder = Thelia\Model\FolderQuery::create()->find($con); $folder->delete($con); $folder = Thelia\Model\FolderI18nQuery::create()->find($con); $folder->delete($con); $content = Thelia\Model\ContentQuery::create()->find($con); $content->delete($con); $content = Thelia\Model\ContentI18nQuery::create()->find($con); $content->delete($con); $accessory = Thelia\Model\AccessoryQuery::create()->find($con); $accessory->delete($con); $stock = \Thelia\Model\ProductSaleElementsQuery::create()->find($con); $stock->delete($con); $productPrice = \Thelia\Model\ProductPriceQuery::create()->find($con); $productPrice->delete($con); \Thelia\Model\ProductImageQuery::create()->find($con)->delete($con); $customer = \Thelia\Model\CustomerQuery::create()->find($con); $customer->delete($con); $sale = \Thelia\Model\SaleQuery::create()->find($con); $sale->delete($con); $saleProduct = \Thelia\Model\SaleProductQuery::create()->find($con); $saleProduct->delete($con); echo "Tables cleared with success\n"; }
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(); //customer $customer = new Thelia\Model\Customer(); $customer->createOrUpdate(1, "thelia", "thelia", "5 rue rochon", "", "", "0102030405", "0601020304", "63000", "clermont-ferrand", 64, "*****@*****.**", "azerty"); for ($j = 0; $j <= 3; $j++) { $address = new Thelia\Model\Address(); $address->setLabel(getRealText(20))->setTitleId(rand(1, 3))->setFirstname($faker->firstname)->setLastname($faker->lastname)->setAddress1($faker->streetAddress)->setAddress2($faker->streetAddress)->setAddress3($faker->streetAddress)->setCellphone($faker->phoneNumber)->setPhone($faker->phoneNumber)->setZipcode($faker->postcode)->setCity($faker->city)->setCountryId(64)->setCustomer($customer)->save(); } for ($i = 0; $i < 3; $i++) {
/** * Process update sale * * @param SaleUpdateEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher * @throws PropelException */ public function update(SaleUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher) { if (null !== ($sale = SaleQuery::create()->findPk($event->getSaleId()))) { $sale->setDispatcher($dispatcher); $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME); $con->beginTransaction(); try { // Disable all promo flag on sale's currently selected products, // to reset promo status of the products that have been removed from the selection. $sale->setActive(false); $now = new \DateTime(); $startDate = $event->getStartDate(); $endDate = $event->getEndDate(); $update = $startDate <= $now && $now <= $endDate; if ($update) { $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale)); } $sale->setActive($event->getActive())->setStartDate($startDate)->setEndDate($endDate)->setPriceOffsetType($event->getPriceOffsetType())->setDisplayInitialPrice($event->getDisplayInitialPrice())->setLocale($event->getLocale())->setSaleLabel($event->getSaleLabel())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->save($con); $event->setSale($sale); // Update price offsets SaleOffsetCurrencyQuery::create()->filterBySaleId($sale->getId())->delete($con); foreach ($event->getPriceOffsets() as $currencyId => $priceOffset) { $saleOffset = new SaleOffsetCurrency(); $saleOffset->setCurrencyId($currencyId)->setSaleId($sale->getId())->setPriceOffsetValue($priceOffset)->save($con); } // Update products SaleProductQuery::create()->filterBySaleId($sale->getId())->delete($con); $productAttributesArray = $event->getProductAttributes(); foreach ($event->getProducts() as $productId) { if (isset($productAttributesArray[$productId])) { foreach ($productAttributesArray[$productId] as $attributeId) { $saleProduct = new SaleProduct(); $saleProduct->setSaleId($sale->getId())->setProductId($productId)->setAttributeAvId($attributeId)->save($con); } } else { $saleProduct = new SaleProduct(); $saleProduct->setSaleId($sale->getId())->setProductId($productId)->setAttributeAvId(null)->save($con); } } if ($update) { // Update related products sale status $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale)); } $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } } }
$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(); //customer $customer = new Thelia\Model\Customer(); $customer->createOrUpdate(1, "thelia", "thelia", "5 rue rochon", "", "", "0102030405", "0601020304", "63000", "clermont-ferrand", 64, "*****@*****.**", "azerty"); for ($j = 0; $j <= 3; $j++) { $address = new Thelia\Model\Address(); $address->setLabel(getRealText(20))->setTitleId(rand(1, 3))->setFirstname($faker->firstname)->setLastname($faker->lastname)->setAddress1($faker->streetAddress)->setAddress2($faker->streetAddress)->setAddress3($faker->streetAddress)->setCellphone($faker->phoneNumber)->setPhone($faker->phoneNumber)->setZipcode($faker->postcode)->setCity($faker->city)->setCountryId(64)->setCustomer($customer)->save(); } for ($i = 0; $i < 3; $i++) {
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Product is new, it will return * an empty collection; or if this Product has previously * been saved, it will retrieve related SaleProducts 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 Product. * * @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|ChildSaleProduct[] List of ChildSaleProduct objects */ public function getSaleProductsJoinAttributeAv($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildSaleProductQuery::create(null, $criteria); $query->joinWith('AttributeAv', $joinBehavior); return $this->getSaleProducts($query, $con); }
/** * Performs an INSERT on the database, given a SaleProduct or Criteria object. * * @param mixed $criteria Criteria or SaleProduct 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(SaleProductTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from SaleProduct object } if ($criteria->containsKey(SaleProductTableMap::ID) && $criteria->keyContainsValue(SaleProductTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . SaleProductTableMap::ID . ')'); } // Set the correct dbName $query = SaleProductQuery::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 SaleProduct::setDeleted() * @see SaleProduct::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(SaleProductTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildSaleProductQuery::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; } }