public function testCommand() { $application = new Application($this->getKernel()); $checkCommand = new SaleCheckActivationCommand(); $checkCommand->setContainer($this->getContainer()); $application->add($checkCommand); $command = $application->find("sale:check-activation"); $commandTester = new CommandTester($command); $commandTester->execute(["command" => $command->getName(), "--env" => "test"]); $deactivatedSale = SaleQuery::create()->findPk(self::$deactivated); $this->assertTrue($deactivatedSale->getActive(), "the sale must be actived now"); $activatedSale = SaleQuery::create()->findPk(self::$activated); $this->assertFalse($activatedSale->getActive(), "the sale must be deactived now"); }
/** * Performs an INSERT on the database, given a Sale or Criteria object. * * @param mixed $criteria Criteria or Sale 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(SaleTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Sale object } if ($criteria->containsKey(SaleTableMap::ID) && $criteria->keyContainsValue(SaleTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . SaleTableMap::ID . ')'); } // Set the correct dbName $query = SaleQuery::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; }
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\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(); //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(); }
/** * This method check the activation and deactivation dates of sales, and perform * the required action depending on the current date. * * @param SaleActiveStatusCheckEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher * @throws \Propel\Runtime\Exception\PropelException */ public function checkSaleActivation(SaleActiveStatusCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME); $con->beginTransaction(); try { $now = time(); // Disable expired sales if (null !== ($salesToDisable = SaleQuery::create()->filterByActive(true)->filterByEndDate($now, Criteria::LESS_THAN)->find())) { /** @var SaleModel $sale */ foreach ($salesToDisable as $sale) { $sale->setActive(false)->save(); // Update related products sale status $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale)); } } // Enable sales that should be enabled. if (null !== ($salesToEnable = SaleQuery::create()->filterByActive(false)->filterByStartDate($now, Criteria::LESS_EQUAL)->filterByEndDate($now, Criteria::GREATER_EQUAL)->find())) { /** @var SaleModel $sale */ foreach ($salesToEnable as $sale) { $sale->setActive(true)->save(); // Update related products sale status $dispatcher->dispatch(TheliaEvents::UPDATE_PRODUCT_SALE_STATUS, new ProductSaleStatusUpdateEvent($sale)); } } $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } }
public function testSearchById() { $sale = SaleQuery::create()->findOne(); $this->baseTestSearchById($sale->getId()); }
$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(); //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(); }
/** * @return \Thelia\Model\Sale */ protected function getRandomSale() { $sale = SaleQuery::create()->addAscendingOrderByColumn('RAND()')->findOne(); if (null === $sale) { $this->fail('use fixtures before launching test, there is no sale in database'); } return $sale; }
/** * Load an existing object from the database * * @return \Thelia\Model\Sale */ protected function getExistingObject() { $sale = SaleQuery::create()->findOneById($this->getRequest()->get('sale_id', 0)); if (null !== $sale) { $sale->setLocale($this->getCurrentEditionLocale()); } return $sale; }
public function buildModelCriteria() { $search = SaleQuery::create(); /* manage translations */ $this->configureI18nProcessing($search, array('TITLE', 'SALE_LABEL', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM')); $id = $this->getId(); if (!is_null($id)) { $search->filterById($id, Criteria::IN); } $active = $this->getActive(); if ($active !== BooleanOrBothType::ANY) { $search->filterByActive($active ? 1 : 0); } $exclude = $this->getExclude(); if (!is_null($exclude)) { $search->filterById($exclude, Criteria::NOT_IN); } $productIdList = $this->getProduct(); if (!is_null($productIdList)) { $search->useSaleProductQuery()->filterByProductId($productIdList, Criteria::IN)->groupByProductId()->endUse(); } $search->leftJoinSaleOffsetCurrency('SaleOffsetCurrency')->addJoinCondition('SaleOffsetCurrency', '`SaleOffsetCurrency`.`currency_id` = ?', $this->getCurrency(), null, \PDO::PARAM_INT); $search->withColumn('`SaleOffsetCurrency`.PRICE_OFFSET_VALUE', 'price_offset_value'); $orders = $this->getOrder(); foreach ($orders as $order) { switch ($order) { case 'id': $search->orderById(Criteria::ASC); break; case 'id-reverse': $search->orderById(Criteria::DESC); break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha-reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "label": $search->addAscendingOrderByColumn('i18n_SALE_LABEL'); break; case "label-reverse": $search->addDescendingOrderByColumn('i18n_SALE_LABEL'); break; case "active": $search->orderByActive(Criteria::ASC); break; case "active-reverse": $search->orderByActive(Criteria::DESC); break; case "start-date": $search->orderByStartDate(Criteria::ASC); break; case "start-date-reverse": $search->orderByStartDate(Criteria::DESC); break; case "end-date": $search->orderByEndDate(Criteria::ASC); break; case "end-date-reverse": $search->orderByEndDate(Criteria::DESC); break; case "created": $search->addAscendingOrderByColumn('created_at'); break; case "created-reverse": $search->addDescendingOrderByColumn('created_at'); break; case "updated": $search->addAscendingOrderByColumn('updated_at'); break; case "updated-reverse": $search->addDescendingOrderByColumn('updated_at'); break; } } return $search; }
/** * Get the associated ChildSale object * * @param ConnectionInterface $con Optional Connection object. * @return ChildSale The associated ChildSale object. * @throws PropelException */ public function getSale(ConnectionInterface $con = null) { if ($this->aSale === null && $this->id !== null) { $this->aSale = ChildSaleQuery::create()->findPk($this->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->aSale->addSaleI18ns($this); */ } return $this->aSale; }