コード例 #1
0
ファイル: CouponCode.php プロジェクト: alex63530/thelia
 public function verifyExistingCode($value, ExecutionContextInterface $context)
 {
     $coupon = CouponQuery::create()->findOneByCode($value);
     if (null === $coupon) {
         $context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
     }
 }
コード例 #2
0
 /**
  * Get the associated ChildCoupon object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildCoupon The associated ChildCoupon object.
  * @throws PropelException
  */
 public function getCoupon(ConnectionInterface $con = null)
 {
     if ($this->aCoupon === null && $this->id !== null) {
         $this->aCoupon = ChildCouponQuery::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->aCoupon->addCouponVersions($this);
            */
     }
     return $this->aCoupon;
 }
コード例 #3
0
ファイル: Customer.php プロジェクト: shirone/thelia
 /**
  * Gets the number of ChildCoupon objects related by a many-to-many relationship
  * to the current object by way of the coupon_customer_count 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 ChildCoupon objects
  */
 public function countCoupons($criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     if (null === $this->collCoupons || null !== $criteria) {
         if ($this->isNew() && null === $this->collCoupons) {
             return 0;
         } else {
             $query = ChildCouponQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByCustomer($this)->count($con);
         }
     } else {
         return count($this->collCoupons);
     }
 }
コード例 #4
0
ファイル: faker.php プロジェクト: hadesain/thelia
 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();
 //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();
コード例 #5
0
ファイル: Coupon.php プロジェクト: alex63530/thelia
 /**
  * @param \Thelia\Core\Event\Order\OrderEvent $event
  *
  * @throws \Exception if something goes wrong.
  */
 public function afterOrder(OrderEvent $event)
 {
     $consumedCoupons = $this->request->getSession()->getConsumedCoupons();
     if (is_array($consumedCoupons)) {
         $con = Propel::getWriteConnection(OrderCouponTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             foreach ($consumedCoupons as $couponCode) {
                 $couponQuery = CouponQuery::create();
                 $couponModel = $couponQuery->findOneByCode($couponCode);
                 $couponModel->setLocale($this->request->getSession()->getLang()->getLocale());
                 /* decrease coupon quantity */
                 $this->couponManager->decrementQuantity($couponModel, $event->getOrder()->getCustomerId());
                 /* memorize coupon */
                 $orderCoupon = new OrderCoupon();
                 $orderCoupon->setOrder($event->getOrder())->setCode($couponModel->getCode())->setType($couponModel->getType())->setAmount($couponModel->getAmount())->setTitle($couponModel->getTitle())->setShortDescription($couponModel->getShortDescription())->setDescription($couponModel->getDescription())->setExpirationDate($couponModel->getExpirationDate())->setIsCumulative($couponModel->getIsCumulative())->setIsRemovingPostage($couponModel->getIsRemovingPostage())->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())->setSerializedConditions($couponModel->getSerializedConditions())->setPerCustomerUsageCount($couponModel->getPerCustomerUsageCount());
                 $orderCoupon->save();
                 // Copy order coupon free shipping data for countries and modules
                 $couponCountries = CouponCountryQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponCountry $couponCountry */
                 foreach ($couponCountries as $couponCountry) {
                     $occ = new OrderCouponCountry();
                     $occ->setCouponId($orderCoupon->getId())->setCountryId($couponCountry->getCountryId())->save();
                 }
                 $couponModules = CouponModuleQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponModule $couponModule */
                 foreach ($couponModules as $couponModule) {
                     $ocm = new OrderCouponModule();
                     $ocm->setCouponId($orderCoupon->getId())->setModuleId($couponModule->getModuleId())->save();
                 }
             }
             $con->commit();
         } catch (\Exception $ex) {
             $con->rollBack();
             throw $ex;
         }
     }
     // Clear all coupons.
     $event->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
 }
コード例 #6
0
 /**
  * Performs an INSERT on the database, given a Coupon or Criteria object.
  *
  * @param mixed               $criteria Criteria or Coupon 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(CouponTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Coupon object
     }
     if ($criteria->containsKey(CouponTableMap::ID) && $criteria->keyContainsValue(CouponTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . CouponTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = CouponQuery::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;
 }
コード例 #7
0
ファイル: BaseFacade.php プロジェクト: margery/thelia
 /**
  * Find one Coupon in the database from its code
  *
  * @param string $code Coupon code
  *
  * @return Coupon
  */
 public function findOneCouponByCode($code)
 {
     $couponQuery = CouponQuery::create();
     return $couponQuery->findOneByCode($code);
 }
コード例 #8
0
ファイル: faker.php プロジェクト: NicolasMugnier/thelia
 $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();
 //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();
コード例 #9
0
 public function checkCouponCodeChangedAndDoesntExists($value, ExecutionContextInterface $context)
 {
     $changed = isset($this->data["code"]) && $this->data["code"] !== $value;
     $exists = CouponQuery::create()->filterByCode($value)->count() > 0;
     if ($changed && $exists) {
         $context->addViolation(Translator::getInstance()->trans("The coupon code '%code' already exist. Please choose another coupon code", ['%code' => $value]));
     }
 }
コード例 #10
0
ファイル: Coupon.php プロジェクト: margery/thelia
 public function buildModelCriteria()
 {
     $search = CouponQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION', 'SHORT_DESCRIPTION'));
     $id = $this->getId();
     $isEnabled = $this->getIsEnabled();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     if (isset($isEnabled)) {
         $search->filterByIsEnabled($isEnabled ? true : false);
     }
     $inUse = $this->getInUse();
     if ($inUse !== null) {
         // Get the code of coupons currently in use
         $consumedCoupons = $this->request->getSession()->getConsumedCoupons();
         // Get only matching coupons.
         $criteria = $inUse ? Criteria::IN : Criteria::NOT_IN;
         $search->filterByCode($consumedCoupons, $criteria);
     }
     $search->addAsColumn('days_left', 'DATEDIFF(' . CouponTableMap::EXPIRATION_DATE . ', CURDATE()) - 1');
     $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 'code':
                 $search->orderByCode(Criteria::ASC);
                 break;
             case 'code-reverse':
                 $search->orderByCode(Criteria::DESC);
                 break;
             case 'title':
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case 'title-reverse':
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case 'enabled':
                 $search->orderByIsEnabled(Criteria::ASC);
                 break;
             case 'enabled-reverse':
                 $search->orderByIsEnabled(Criteria::DESC);
                 break;
             case 'expiration-date':
                 $search->orderByExpirationDate(Criteria::ASC);
                 break;
             case 'expiration-date-reverse':
                 $search->orderByExpirationDate(Criteria::DESC);
                 break;
             case 'usages-left':
                 $search->orderByMaxUsage(Criteria::ASC);
                 break;
             case 'usages-left-reverse':
                 $search->orderByMaxUsage(Criteria::DESC);
                 break;
             case 'days-left':
                 $search->addAscendingOrderByColumn('days_left');
                 break;
             case 'days-left-reverse':
                 $search->addDescendingOrderByColumn('days_left');
                 break;
         }
     }
     return $search;
 }
コード例 #11
0
ファイル: Coupon.php プロジェクト: thelia/core
 /**
  * Cancels order coupons usage when order is canceled or refunded,
  * or use canceled coupons again if the order is no longer canceled or refunded
  *
  * @param OrderEvent $event
  * @param string $eventName
  * @param EventDispatcherInterface $dispatcher
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function orderStatusChange(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     // The order has been canceled or refunded ?
     if ($event->getOrder()->isCancelled() || $event->getOrder()->isRefunded()) {
         // Cancel usage of all coupons for this order
         $usedCoupons = OrderCouponQuery::create()->filterByUsageCanceled(false)->findByOrderId($event->getOrder()->getId());
         $customerId = $event->getOrder()->getCustomerId();
         /** @var OrderCoupon $usedCoupon */
         foreach ($usedCoupons as $usedCoupon) {
             if (null !== ($couponModel = CouponQuery::create()->findOneByCode($usedCoupon->getCode()))) {
                 // If the coupon still exists, restore one usage to the usage count.
                 $this->couponManager->incrementQuantity($couponModel, $customerId);
             }
             // Mark coupon usage as canceled in the OrderCoupon table
             $usedCoupon->setUsageCanceled(true)->save();
         }
     } else {
         // Mark canceled coupons for this order as used again
         $usedCoupons = OrderCouponQuery::create()->filterByUsageCanceled(true)->findByOrderId($event->getOrder()->getId());
         $customerId = $event->getOrder()->getCustomerId();
         /** @var OrderCoupon $usedCoupon */
         foreach ($usedCoupons as $usedCoupon) {
             if (null !== ($couponModel = CouponQuery::create()->findOneByCode($usedCoupon->getCode()))) {
                 // If the coupon still exists, mark the coupon as used
                 $this->couponManager->decrementQuantity($couponModel, $customerId);
             }
             // The coupon is no longer canceled
             $usedCoupon->setUsageCanceled(false)->save();
         }
     }
 }
コード例 #12
0
 public function deleteAction()
 {
     // Check current user authorization
     if (null !== ($response = $this->checkAuth(AdminResources::COUPON, [], AccessManager::DELETE))) {
         return $response;
     }
     try {
         // Check token
         $this->getTokenProvider()->checkToken($this->getRequest()->query->get("_token"));
         // Retrieve coupon
         $coupon = CouponQuery::create()->findPk($couponId = $this->getRequest()->request->get("coupon_id"));
         $deleteEvent = new CouponDeleteEvent($couponId, $coupon);
         $this->dispatch(TheliaEvents::COUPON_DELETE, $deleteEvent);
         if (null !== ($deletedObject = $deleteEvent->getCoupon())) {
             $this->adminLogAppend(AdminResources::COUPON, AccessManager::DELETE, sprintf("Coupon %s (ID %s) deleted", $deletedObject->getCode(), $deletedObject->getId()), $deletedObject->getId());
         }
         return $response = RedirectResponse::create(URL::getInstance()->absoluteUrl($this->getRoute('admin.coupon.list')));
     } catch (\Exception $e) {
         $this->getParserContext()->setGeneralError($e->getMessage());
         return $this->browseAction();
     }
 }
コード例 #13
0
ファイル: Coupon.php プロジェクト: zorn-v/thelia
 /**
  * Checks whether the current state must be recorded as a version
  *
  * @return  boolean
  */
 public function isVersioningNecessary($con = null)
 {
     if ($this->alreadyInSave) {
         return false;
     }
     if ($this->enforceVersion) {
         return true;
     }
     if (ChildCouponQuery::isVersioningEnabled() && ($this->isNew() || $this->isModified()) || $this->isDeleted()) {
         return true;
     }
     return false;
 }
コード例 #14
0
ファイル: CouponController.php プロジェクト: alex63530/thelia
 /**
  * Draw the input displayed in the BackOffice
  * allowing Admin to set its Coupon effect
  *
  * @param int $couponId Coupon id
  *
  * @return ResponseRest
  */
 public function getBackOfficeConditionSummariesAjaxAction($couponId)
 {
     if (null !== ($response = $this->checkAuth(AdminResources::COUPON, [], AccessManager::VIEW))) {
         return $response;
     }
     $this->checkXmlHttpRequest();
     /** @var Coupon $coupon */
     $coupon = CouponQuery::create()->findPk($couponId);
     if (null === $coupon) {
         return $this->pageNotFound();
     }
     /** @var CouponFactory $couponFactory */
     $couponFactory = $this->container->get('thelia.coupon.factory');
     $couponManager = $couponFactory->buildCouponFromModel($coupon);
     if (!$couponManager instanceof CouponInterface) {
         return $this->pageNotFound();
     }
     $args = [];
     $args['conditions'] = $this->cleanConditionForTemplate($couponManager->getConditions());
     return $this->render('coupon/conditions', $args);
 }