/** * Filter the query by a related \Thelia\Model\SaleOffsetCurrency object * * @param \Thelia\Model\SaleOffsetCurrency|ObjectCollection $saleOffsetCurrency the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCurrencyQuery The current query, for fluid interface */ public function filterBySaleOffsetCurrency($saleOffsetCurrency, $comparison = null) { if ($saleOffsetCurrency instanceof \Thelia\Model\SaleOffsetCurrency) { return $this->addUsingAlias(CurrencyTableMap::ID, $saleOffsetCurrency->getCurrencyId(), $comparison); } elseif ($saleOffsetCurrency instanceof ObjectCollection) { return $this->useSaleOffsetCurrencyQuery()->filterByPrimaryKeys($saleOffsetCurrency->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterBySaleOffsetCurrency() only accepts arguments of type \\Thelia\\Model\\SaleOffsetCurrency or Collection'); } }
/** * Exclude object from result * * @param ChildSaleOffsetCurrency $saleOffsetCurrency Object to remove from the list of results * * @return ChildSaleOffsetCurrencyQuery The current query, for fluid interface */ public function prune($saleOffsetCurrency = null) { if ($saleOffsetCurrency) { $this->addCond('pruneCond0', $this->getAliasedColName(SaleOffsetCurrencyTableMap::SALE_ID), $saleOffsetCurrency->getSaleId(), Criteria::NOT_EQUAL); $this->addCond('pruneCond1', $this->getAliasedColName(SaleOffsetCurrencyTableMap::CURRENCY_ID), $saleOffsetCurrency->getCurrencyId(), Criteria::NOT_EQUAL); $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); } return $this; }
/** * 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; } } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by find*() * and findPk*() calls. * * @param \Thelia\Model\SaleOffsetCurrency $obj A \Thelia\Model\SaleOffsetCurrency object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if (null === $key) { $key = serialize(array((string) $obj->getSaleId(), (string) $obj->getCurrencyId())); } // if key === null self::$instances[$key] = $obj; } }